Ошибка вызова службы WS-Security с использованием конечной точки camel cxf - имя пользователя недоступно
Я пытаюсь вызвать сторонний веб-сервис.net с помощью ws-security и получаю следующее исключение, несмотря на настройку всех необходимых параметров в 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] at org.apache.cxf.ws.security.wss4j.PolicyBasedWSS4JOutInterceptor$PolicyBasedWSS4JOutInterceptorInternal.handleMessageInternal(PolicyBasedWSS4JOutInterceptor.java:195)[cxf-3.0-w-w-2-w-w.2-w.w.2.w.2 ] at org.apache.cxf.ws.security.wss4j.PolicyBasedWSS4JOutInterceptor $ PolicyBasedWSS4JOutInterceptorInternal.handleMessage (PolicyBasedWSS4JOutInterceptor.java:114) [cxf-rt-ws-security-3.0.j.jp-3.0-at-3.0.j.jp-3.0-at.cxf.ws.security.wss4j.PolicyBasedWSS4JOutInterceptor$PolicyBasedWSS4JOutInterceptorInternal.handleMessage(PolicyBasedWSS4JOutInterceptor.java:101)[cxf-rt-ws-security-3.0.2.doIntercept(PhaseInterceptorChain.java:307)[cxf-core-3.0.2.jar:3.0.2] в 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.processor.SendProcessor.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(CamelInternalProternal.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] at 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&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>
(ниже фрагмент ws-политики из wsdl)
<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>
2 ответа
Поскольку формат данных CXF PAYLOAD не обрабатывает заголовок мыла, вам может потребоваться изменить формат данных на CXF_MESSAGE или POJO, чтобы заставить перехватчик CXF обрабатывать эти заголовки мыла.
Если я правильно понял, вы пытаетесь создать клиент SOAP для веб-служб, который включает <wsp:Policy>
определение.
Это означает, что вы не должны включать перехватчик CXF (например, как WSS4JOutInterceptor
). Вам просто нужно правильно настроить клиент jaws: для автоматического обнаружения <wsp:Policy>
в WSDL и включите его внутренний перехватчик политики безопасности WS. Если вы определите дополнительные (как вы сделали), то это не будет работать вообще.
Проверьте эти примеры:
а также
Примером может быть:
<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>