错误:用户名令牌已创建策略未强制执行

时间:2016-04-20 19:04:13

标签: java web-services security cxf cxf-client

我正在研究基于CXF的服务和客户。 并使用wsdl中定义的策略文件在服务器端实现了用户名密码安全性。这是配置:

<wsp:Policy wsu:Id="policy.Security" xmlns:wsp="http://www.w3.org/ns/ws-policy">
  <wsp:ExactlyOne>
    <wsp:All>
        <sp:SupportingTokens>
            <wsp:Policy>
                <sp:UsernameToken
                        sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient"
                    wsp:Optional="false" wsp:Ignorable="false">
                    <wsp:Policy>
                        <sp:WssUsernameToken10 />
                        <sp13:Created />
                        <sp13:Nonce />
                    </wsp:Policy>
                </sp:UsernameToken>
            </wsp:Policy>
        </sp:SupportingTokens>
    </wsp:All>
  </wsp:ExactlyOne>
</wsp:Policy>

客户端配置:

<jaxws:client
    xmlns:tns="http://ws.soa.com/service/offer/XYZ/"
    name="XYZPort" address="${xyz.endPoint}"
    serviceClass="com.soa.ws.service.offer.XYZ.XYZPortType"
    wsdlLocation="${xyz.wsdlLocation}" serviceName="tns:xyzService" >
    <jaxws:properties>
        <entry key="ws-security.username" value="${xyz.auth.username}" />
        <entry key="ws-security.callback-handler" value-ref="xyzPasswordCallback" />
    </jaxws:properties>
    <jaxws:inInterceptors>
    <ref bean="logInBound" />
    </jaxws:inInterceptors>
    <jaxws:outInterceptors>
    <ref bean="logOutBound" />      
    </jaxws:outInterceptors>
</jaxws:client>

尝试点击服务时收到以下错误:

引起:javax.xml.ws.soap.SOAPFaultException:无法满足这些策略备选方案: {http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702} UsernameToken:用户名令牌未强制创建的策略     在org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:157)

有人可以指示如何解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

您可能正在使用旧版的CXF。这在以下是固定的:

https://issues.apache.org/jira/browse/CXF-6051