【问题标题】:How to invoke a REST service from BPEL in Oracle SOA, with Basic Authentication?如何使用基本身份验证从 Oracle SOA 中的 BPEL 调用 REST 服务?
【发布时间】:2017-06-15 12:01:13
【问题描述】:

我正在使用 Oracle Fusion Middleware 12.1.3,并且我正在开发一个 BPEL 流程,该流程必须调用需要基本身份验证的远程 REST 服务。

我为 Rest Service 创建了一个外部引用,在我的composite.xml 中,它看起来像这样:

....
<component name="MyCompositeBASProcess" version="2.0">
    <implementation.bpel src="BPEL/MyCompositeBASProcess.bpel"/>
    <componentType>
        <service name="mycompositebasprocess_client" ui:wsdlLocation="WSDLs/MyCompositeBASProcess.wsdl">
            <interface.wsdl interface="http://xmlns.oracle.com/myPartitionSOA/MyCompositeBAS/MyCompositeBASProcess#wsdl.interface(MyCompositeBASProcess)"
                    callbackInterface="http://xmlns.oracle.com/myPartitionSOA/MyCompositeBAS/MyCompositeBASProcess#wsdl.interface(MyCompositeBASProcessCallback)"/>
        </service>
        <reference name="CMProxyRS" ui:wsdlLocation="WSDLs/CMProxyRS.wsdl">
            <interface.wsdl interface="http://xmlns.oracle.com/myPartitionSOA/MyCompositeBAS/CMProxyRS#wsdl.interface(CMProxyRS_ptt)"/>
        </reference>
    </componentType>
    <property name="bpel.config.oneWayDeliveryPolicy" type="xs:string" many="false">async.persist</property>
</component>

<reference name="CMProxyRS" ui:wsdlLocation="WSDLs/CMProxyRS.wsdl">
    <interface.wsdl interface="http://xmlns.oracle.com/myPartitionSOA/MyCompositeBAS/CMProxyRS#wsdl.interface(CMProxyRS_ptt)"/>
    <binding.rest config="Adapters/CMProxyRS.wadl" location="http://server_WITHOUT_basic-auth/cmproxy/resources/v2/" />
</reference>
....

使用这段代码,我调用了一个不受 BASIC_Auth 保护的 REST 服务,它工作正常。

现在,当我切换到需要基本身份验证的远程环境时,我没有成功。

我找到了一些使用基本身份验证调用 SOAP 服务的示例,但对于 REST 服务来说没有什么真正有趣的。但是,在 Oracle Fusion 堆栈 12.1.3 中,REST 服务在使用之前“适应”了 SOAP 服务,所以我认为我可以使用我找到的示例。

所以,我更新了我的composite.xml 以添加用户/密码和策略:

....
<reference name="CMProxyRS" ui:wsdlLocation="WSDLs/CMProxyRS.wsdl">
    <interface.wsdl interface="http://xmlns.oracle.com/myPartitionSOA/MyCompositeBAS/CMProxyRS#wsdl.interface(CMProxyRS_ptt)"/>
    <binding.rest config="Adapters/CMProxyRS.wadl" location="http://server_WITH_basic-auth/cmproxy/resources/v2/">
        <wsp:PolicyReference URI="oracle/wss_username_token_client_policy" orawsp:category="security" orawsp:status="enabled"/>
        <!-- <property name="oracle.webservices.auth.username">weblogic</property>                       -->
        <!-- <property name="oracle.webservices.auth.password">password</property>  -->
        <property name="oracle.webservices.preemptiveBasicAuth">true</property> 
        <property  name="javax.xml.ws.security.auth.username"  many="false"  override="may">weblogic</property>
        <property  name="javax.xml.ws.security.auth.password"  many="false"  override="may">password</property>
    </binding.rest>    
</reference>
....

如您所见,我尝试使用 javax.xml.ws.security.auth. 属性和 oracle.webservices.auth. 属性。但两者都失败了:在远程,我没有在请求中获得任何基本身份验证。

我还更新了我的CMProxyRS.wadl,在HTTP Header 中添加了Authorization 键。例如:

<resources>
  <resource path="/documents">
     <method name="GET" soa:wsdlOperation="searchDocument">
        <request>
           <param name="Authorization" style="header" soa:expression="$msg.request/tns:Authorization" default="" type="xsd:string"/>
           <param name="queryText" style="query" soa:expression="$msg.request/tns:queryText" default="" type="xsd:string"/>
           <param name="fields" style="query" soa:expression="$msg.request/tns:fields" default="id,name,originalName,originalFormat,originalExtension,alternateFormat,alternateExtension,revision" type="xsd:string"/>
           <param name="waitForIndexing" style="query" soa:expression="$msg.request/tns:waitForIndexing" default="false" type="xsd:boolean"/>
        </request>
        <response status="200">
....

而这个Authorization 在WSDL 中被“复制”了。CMProxyRS.wsdl

<element name="searchDocument_params">
    <complexType>
        <sequence>
            <element name="Authorization" type="string"/>
            <element name="queryText" type="string"/>
            <element name="fields" type="string"/>
            <element name="waitForIndexing" type="boolean"/>
        </sequence>
    </complexType>
</element>

这没有帮助。事实上,我真的不确定我在composite.xml 中添加的内容(属性用户名、密码、preemptiveBasicAuth)是否被 SOA 引擎用于构建 REST 请求。

(我想说明这不是用户/密码问题:当我使用来自 Postman 的相同用户/密码测试此 REST 查询时,它工作正常。)

如何从 soa-composite 调用具有基本身份验证的 REST 服务?

【问题讨论】:

    标签: basic-authentication bpel oracle-fusion-middleware oracle-soa


    【解决方案1】:

    您可以在 BPEL 中发送自定义 HTTP 标头。

    看看这个post。您需要在参考服务上添加 oracle.webservices.http.headers,然后您可以填充变量并将它们发送到 BPEL 中的 REST 调用活动。

    【讨论】:

      【解决方案2】:

      您可以尝试 OWSM oracle/http_jwt_token_client_policy 在请求中传递所需的标头。

      【讨论】:

        【解决方案3】:

        我最初尝试从 Oracle SOA 12c 调用 WADL 时遇到了同样的问题。

        它在应用以下 OWSM 安全策略后开始工作:

        oracle/http_jwt_token_client_policy
        

        【讨论】:

        • 请在您的回答中提供更多详细信息。正如目前所写的那样,很难理解您的解决方案。
        • 这并不能真正回答问题。如果您有其他问题,可以点击 进行提问。要在此问题有新答案时收到通知,您可以follow this question。一旦你有足够的reputation,你也可以add a bounty 来引起对这个问题的更多关注。 - From Review
        • @INDRAJITH:虽然这将受益于额外的解释和清晰,但它肯定会提供问题的答案。如果由于解释有限而没有用,或者您认为它是错误的,则应否决。它不应该被删除。
        猜你喜欢
        • 1970-01-01
        • 2019-06-20
        • 1970-01-01
        • 1970-01-01
        • 2016-05-04
        • 2016-05-31
        • 2020-03-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多