2013-11-01 59 views

回答

3

有關所需令牌的信息可以使用WS-Policies在WSDL中發佈。對於用戶名令牌我用了以下政策:

<wsp:Policy wsu:Id="UP_policy" xmlns:wsp="http://www.w3.org/ns/ws-policy" 
    xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 
    <sp:SupportingTokens 
     xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702"> 
     <wsp:Policy> 
      <sp:UsernameToken 
       sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient"> 
       <wsp:Policy> 
        <sp:WssUsernameToken11 /> 
       </wsp:Policy> 
      </sp:UsernameToken> 
     </wsp:Policy> 
    </sp:SupportingTokens> 
</wsp:Policy> 

它需要UT只爲請求消息(AlwaysToRecipient)。要在生成的WSDL中包含這樣的策略:

  • 將它保存到classpath中可用的文件中,例如, ut.policy.xml
  • 添加@Policies({ @Policy(uri = "ut.policy.xml") })註解服務類或接口

我修改例如CXF項目。它顯示瞭如何做到這一點。你可以找到它here

因此,您的WSDL將WS-安全的相應的實例連接,告訴客戶的是Username令牌預計:

<wsdl:definitions ...> 
    ... 
    <wsdl:service name="GreeterService"> 
     <wsdl:port binding="tns:GreeterServiceSoapBinding" name="GreeterPort"> 
      <soap:address location="http://localhost:9000/SoapContext/GreeterPort"/> 
     </wsdl:port> 
     <wsp:PolicyReference URI="#UP_policy"/> 
    </wsdl:service> 
    <wsp:Policy xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" wsu:Id="UP_policy"> 
     <sp:SupportingTokens xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702"> 
      <wsp:Policy> 
       <sp:UsernameToken sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient"> 
        <wsp:Policy> 
         <sp:WssUsernameToken11/> 
        </wsp:Policy> 
       </sp:UsernameToken> 
      </wsp:Policy> 
     </sp:SupportingTokens> 
    </wsp:Policy> 
</wsdl:definitions> 

中有更多關於CXF配置WS-安全策略,可以發現here,以及如何處理任何WS-Policy here

+0

嗨@ dawid-pytel感謝您的幫助,終於搞定了,對於遲到的回覆感到抱歉。 – user2944021

+0

比從未更好的遲到。高興地幫助:D –

相關問題