0

我正在尝试使用 ws-security 调用第三方 .net Web 服务,尽管在 WSS4JOutInterceptor 中配置了所有必需的参数,但我得到了以下异常。

org.apache.cxf.interceptor.Fault:在 org.apache.cxf.ws.security.wss4j.policyhandlers.TransportBindingHandler.handleBinding(TransportBindingHandler.java:177)[cxf-rt-ws-security-3.0.2 中没有可用的用户名.jar:3.0.2] 在 org.apache.cxf.ws.security.wss4j.PolicyBasedWSS4JOutInterceptor$PolicyBasedWSS4JOutInterceptorInternal.handleMessageInternal(PolicyBasedWSS4JOutInterceptor.java:195)[cxf-rt-ws-security-3.0.2.jar:3.0.2 ] 在 org.apache.cxf.ws.security.wss4j.PolicyBasedWSS4JOutInterceptor$PolicyBasedWSS4JOutInterceptorInternal.handleMessage(PolicyBasedWSS4JOutInterceptor.java:114)[cxf-rt-ws-security-3.0.2.jar:3.0.2] 在 org.apache.cxf .ws.security.wss4j.PolicyBasedWSS4JOutInterceptor$PolicyBasedWSS4JOutInterceptorInternal.handleMessage(PolicyBasedWSS4JOutInterceptor.java:101)[cxf-rt-ws-security-3.0.2.jar:3.0.2] at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept (PhaseInterceptorChain.java:307)[cxf-core-3.0.2.jar:3.0.2] at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:514)[cxf-core-3.0.2. jar:3.0.2] 在 org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:416)[cxf-core-3.0.2.jar:3.0.2] 在 org.apache.camel.component.cxf .CxfProducer.process(CxfProducer.java:112)[camel-cxf-2.14.1.jar:2.14.1] 在 org.apache.camel.management.InstrumentationProcessor.process(SendProcessor.java:120)[camel-core-2.14.1.jar:2.14.1] 在 org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor .java:72)[camel-core-2.14.1.jar:2.14.1] 在 org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:416)[camel-core-2.14.1.jar: 2.14.1] 在 org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[camel-core-2.14.1.jar:2.14.1] 在 org.apache.camel.processor.Pipeline.process (Pipeline.java:118)[camel-core-2.14.1.jar:2.14.1] 在 org.apache.camel.processor.Pipeline.process(Pipeline.java:80)[camel-core-2.14.1. jar:2.14.1] 在 org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[camel-core-2.14.1.jar:2.14.1] 在 org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:166)[camel-core-2.14.1.jar:2.14.1] 在 org.apache.camel.component.timer.TimerConsumer $1.run(TimerConsumer.java:74)[camel-core-2.14.1.jar:2.14.1] 在 java.util.TimerThread.mainLoop(Timer.java:555)[:1.8.0_25] 在 java.util .TimerThread.run(Timer.java:505)[:1.8.0_25]

下面是我的 cxf 端点配置

<cxf:cxfEndpoint id="telapoint" 
  address="https://mycompany.com/APIv2/MyService"   wsdlURL="https://mycompany.com/APIv2/MyServices.svc?wsdl">
            <cxf:inInterceptors>
                    <ref bean="loggingInInterceptor" />
            </cxf:inInterceptors>
            <cxf:outInterceptors>
                    <ref bean="loggingOutInterceptor" />
                    <ref bean="wss4jOutInterceptor" />
            </cxf:outInterceptors>
            <cxf:properties>
                    <entry key="dataFormat" value="PAYLOAD" />
            </cxf:properties>
    </cxf:cxfEndpoint</b>> 

<bean id="wss4jOutInterceptor" class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor">
            <constructor-arg>
                    <map>
                            <entry key="action" value="UsernameToken Timestamp" />
                            <entry key="passwordType" value="PasswordText" />
                            <entry key="user" value="xxxxxx" />
                            <entry key="passwordCallbackClass" 
                                    value="com.mycompany.t.UTPasswordCallback" />
                            <entry key="addUsernameTokenNonce" value="true" />
                            <entry key="addUsernameTokenCreated" value="true" />
                    </map>
            </constructor-arg>
</bean>

下面是骆驼路线

<camelContext xmlns="http://camel.apache.org/schema/spring"
trace="false">
<route id="telaPoint_Camel_Route_with_CXF">
    <from uri="timer://foo?fixedRate=true&amp;period=10m" />
    <setBody>
        <constant>
            <![CDATA[
                   <v2:OrdersGetByStatus   xmlns:v2="http://mycompany.com/TelaFuel/v2">
                         <v2:status>Delivered</v2:status>
                   </v2:OrdersGetByStatus>
            ]]>
        </constant>
    </setBody>
    <setHeader headerName="operationName">
        <constant>OrdersGetByStatus</constant>
    </setHeader>
    <setHeader headerName="operationNamespace">
        <constant>http://mycompany.com/TelaFuel/v2</constant>
    </setHeader>
    <to uri="telapoint" />
</route>
</camelContext>

以下是我的 POM 依赖项

    <properties>
            <camel-version>2.14.1</camel-version>
            <log4j-version>1.2.17</log4j-version>
            <jaxb-api-version>2.2.12</jaxb-api-version>
            <jaxb-impl-version>2.2.11</jaxb-impl-version>
            <cxf-version>3.0.2</cxf-version>
            <log4j-version>1.2.17</log4j-version>
    </properties>


    <dependencies>
            <dependency>
                    <groupId>org.apache.camel</groupId>
                    <artifactId>camel-core</artifactId>
                    <version>${camel-version}</version>
            </dependency>
            <dependency>
                    <groupId>org.apache.camel</groupId>
                    <artifactId>camel-spring</artifactId>
                    <version>${camel-version}</version>
            </dependency>
            <dependency>
                    <groupId>org.apache.camel</groupId>
                    <artifactId>camel-cxf</artifactId>
                    <version>${camel-version}</version>
            </dependency>
            <dependency>
                    <groupId>org.apache.camel</groupId>
                    <artifactId>camel-http</artifactId>
                    <version>${camel-version}</version>
            </dependency>

            <dependency>
                    <groupId>org.apache.cxf</groupId>
                    <artifactId>cxf-rt-frontend-jaxws</artifactId>
                    <version>${cxf-version}</version>
            </dependency>


            <dependency>
                    <groupId>org.apache.cxf</groupId>
                    <artifactId>cxf-rt-transports-http</artifactId>
                    <version>${cxf-version}</version>
            </dependency>


            <dependency>
                    <groupId>org.apache.cxf</groupId>
                    <artifactId>cxf-rt-ws-security</artifactId>
                    <version>${cxf-version}</version>
            </dependency>

            <dependency>
                    <groupId>log4j</groupId>
                    <artifactId>log4j</artifactId>
                    <version>${log4j-version}</version>
            </dependency>
            <dependency>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                    <version>1.7.5</version>
            </dependency>


            <dependency>
                    <groupId>org.apache.cxf</groupId>
                    <artifactId>cxf-rt-transports-http-jetty</artifactId>
                    <version>${cxf-version}</version>
            </dependency>

            <dependency>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                    <version>3.8.1</version>
                    <scope>test</scope>
            </dependency>

            <dependency>
                    <groupId>org.apache.cxf</groupId>
                    <artifactId>cxf-rt-frontend-jaxrs</artifactId>
                    <version>${cxf-version}</version>
            </dependency>

    </dependencies>

(以下是来自 wsdl 的 ws-policy 的片段)

<wsp:ExactlyOne>
<wsp:All>
<sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:TransportToken>
<wsp:Policy>
<sp:HttpToken/>
</wsp:Policy>
</sp:TransportToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic256/>
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Strict/>
</wsp:Policy>
</sp:Layout>
<sp:IncludeTimestamp/>
</wsp:Policy>
</sp:TransportBinding>
<sp:SignedSupportingTokens xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:UsernameToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
<wsp:Policy>
<sp:WssUsernameToken10/>
</wsp:Policy>
</sp:UsernameToken>
</wsp:Policy>
</sp:SignedSupportingTokens>
<sp:Wss11 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy/>
</sp:Wss11>
<sp:Trust10 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:MustSupportIssuedTokens/>
<sp:RequireClientEntropy/>
<sp:RequireServerEntropy/>
</wsp:Policy>
</sp:Trust10>
</wsp:All>
</wsp:ExactlyOne>
4

2 回答 2

0

由于 CXF PAYLOAD 数据格式不处理肥皂头,您可能需要将数据格式更改为 CXF_MESSAGE 或 POJO 以强制 CXF 拦截器处理这些肥皂头。

于 2014-12-26T01:58:46.280 回答
0

<wsp:Policy>如果我理解正确,您正在尝试为包含定义的 Web 服务创建 SOAP 客户端。

这意味着您不应包含任何 CXF 拦截器(例如 like WSS4JOutInterceptor)。您应该只适当地配置一个jaws:client 以便自动检测<wsp:Policy>WSDL 中的并启用其内部的WS 安全策略拦截器。如果您定义额外的(如您所做的那样),那么它将根本不起作用。

看看这些例子:

https://access.redhat.com/documentation/en-US/Red_Hat_JBoss_Fuse/6.0/html/Web_Services_Security_Guide/files/STS-Demo-Client.html

https://access.redhat.com/documentation/en-US/Red_Hat_JBoss_Fuse/6.0/html/Web_Services_Security_Guide/files/STS-Demo-Server.html

一个例子可能是:

    <jaxws:client
    xmlns:tns="http://www.mynamespace.com/test"
    id="testSecureSoapClient" 
    wsdlLocation="wsdl/should_include_policy__definition.wsdl"
    address="http://localhost:8192/test"
    endpointName="tns:testServicePort" 
    serviceName="tns:testServiceService"
    serviceClass="com.test.TestServicePortType">
    <jaxws:properties>
        <entry key="ws-security.callback-handler">
            <ref component-id="myTestPasswordCallback"/>
        </entry>       
        ...
    </jaxws:properties>
    <jaxws:inInterceptors>
        <bean class="org.apache.cxf.interceptor.LoggingInInterceptor" />
    </jaxws:inInterceptors>
    <jaxws:outInterceptors>
        <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor" />
    </jaxws:outInterceptors>
</jaxws:client>
于 2017-02-22T13:38:04.697 回答