我正在尝试向我的ws客户端添加UsernameToken wss标头。 客户端实现了javax.xml.ws.Service并且是通过WSDL2Java CFX 3.1.4
生成的由于wsdl包含
<wsp:Policy xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy" wsu:Id="UsernameTokenPolicy">
<sp:UsernameToken>
<wsp:Policy>
<sp:WssUsernameToken10/>
<sp:HashPassword/>
</wsp:Policy>
</sp:UsernameToken>
</wsp:Policy>
必须添加Usernametoken标头。搜索了一下我发现这很简单
((BindingProvider)soapClient).getRequestContext().put("ws-security.username", usr);
((BindingProvider)soapClient).getRequestContext().put("ws-security.password", psw);
当我尝试执行调用时,我收到以下错误:
These policy alternatives can not be satisfied:
{http://schemas.xmlsoap.org/ws/2005/07/securitypolicy}UsernameToken: Password hashing policy not enforced
有什么建议吗? 谢谢。
P.S。我已经检查了堆栈溢出中的类似帖子,但如果我尝试像建议here那样的不同方法,我会遇到不同的错误:
Interceptor for XXXX has thrown exception, unwinding now
org.apache.cxf.ws.policy.PolicyException: No username available
答案 0 :(得分:1)
从Apache CXF 3.1.0,WS-SecurityPolicy和XML Security CXF中的(JAX-RS)组件共享一组通用的配置标记。
所以你不应该使用ws-security.username
和ws-security.password
但security.username
和security.password
还要确保 cxf-rt-ws-policy 和 cxf-rt-ws-security 模块在类路径上可用,因此将自动启用ws-policy,从而处理哈希密码,即计算正确的密码摘要。