2016-06-28 74 views
1

我正在嘗試向我的ws客戶端添加UsernameToken wss標頭。 的客戶端實現javax.xml.ws.Service和由於WSDL包含必須添加CXF UsernameToken問題

<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的報頭已經通過WSDL2Java的CFX 3.1.4

生成。搜索了一下,我發現,這是簡單的

((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.我已經檢查了類似的帖子在堆棧溢出,但如果我嘗試像一個differente方法建議here我得到一個不同的錯誤:

Interceptor for XXXX has thrown exception, unwinding now 
org.apache.cxf.ws.policy.PolicyException: No username available 

回答

1

由於cxf-documentation美國

From Apache CXF 3.1.0, the WS-SecurityPolicy and the XML Security (JAX-RS) components in CXF share a common set of configuration tags.

所以你不宜用ws-security.usernamews-security.passwordsecurity.usernamesecurity.password

另外要確保CXF-RT-WS-波利奇這樣的WS-Policy會自動啓用,從而利用散列密碼的照顧,即計算出正確的密碼摘要ŸCXF-RT-WS-Security的模塊都可以在類路徑中。