2010-03-31 65 views
0

我想知道是否可以使用WS-SecurityPolicy而不是WS-Security來構建cxf-bc。 WS-SecurityPolicy似乎是一個更優雅的解決方案,因爲所有東西都在WSDL中。例子歡迎。 :)cxf-bc中的WS-securitypolicy部署在servicemix中

那麼與大衛的幫助我得到了CXF-BC在ESB上安裝和運行,但我似乎無法測試它。它讓回來用:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
<soap:Body> 
    <soap:Fault> 
    <faultcode>soap:Server</faultcode> 
    <faultstring>These policy alternatives can not be satisfied: 
     {http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}UsernameToken</faultstring> 
    </soap:Fault> 
</soap:Body> 
</soap:Envelope> 

我味精:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://nwec.faa.gov/wxrec/UserAccount/types"> 
    <soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"> 
    <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/ws-securitypolicy-1.2.xsd"> 
    <wsse:UsernameToken wsu:Id="UsernameToken-25" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 
     <wsse:Username>bob</wsse:Username> 
     <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">bobspassword</wsse:Password> 
    </wsse:UsernameToken> 
    </wsse:Security> 
    <wsa:Action>http://nwec.faa.gov/wxrec/UserAccount/UserAccountPortType/ApproveDenyAccountRequest</wsa:Action> 
</soapenv:Header> 
<soapenv:Body> 
    ... 
</soapenv:Body> 

這裏的WSDL中的策略:

<wsp:Policy wsu:Id="UserAccountBindingPolicy" xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702"> 
    <wsp:ExactlyOne> 
    <wsp:All> 
     <wsaw:UsingAddressing xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" wsp:Optional="true" /> 
     <wsp:Policy > 
      <sp:UsernameToken sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/Always"> 
      <wsp:Policy> 
       <sp:WssUsernameToken10 /> 
      </wsp:Policy> 
      </sp:UsernameToken> 
     </wsp:Policy> 
     </wsp:All> 
    </wsp:ExactlyOne> 
</wsp:Policy> 

回答

0

隨着大衛和弗里曼在servicemix用戶郵件列表。我終於可以獲得正確的配置來實施WS-Security Policy。

下面是我對我的BC

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:cxfbc="http://servicemix.apache.org/cxfbc/1.0" xmlns:util="http://www.springframework.org/schema/util" 
xmlns:httpj="http://cxf.apache.org/transports/http-jetty/configuration" 
xmlns:http="http://cxf.apache.org/transports/http/configuration" xmlns:sec="http://cxf.apache.org/configuration/security" 
xmlns:person="http://www.mycompany.com/ws-sec-proto" 
xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd 
    http://www.springframework.org/schema/util 
    http://www.springframework.org/schema/util/spring-util.xsd 
    http://servicemix.apache.org/cxfbc/1.0 
    http://repo2.maven.org/maven2/org/apache/servicemix/servicemix-cxf-bc/2010.01/servicemix-cxf-bc-2010.01.xsd 
    http://cxf.apache.org/transports/http-jetty/configuration 
    http://cxf.apache.org/schemas/configuration/http-jetty.xsd 
    http://cxf.apache.oarg/transports/http/configuration 
    http://cxf.apache.org/schemas/configuration/http-conf.xsd"> 

<import resource="classpath:META-INF/cxf/cxf.xml" /> 
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> 
<import resource="classpath:META-INF/cxf/cxf-extension-http.xml" /> 
<import resource="classpath:META-INF/cxf/osgi/cxf-extension-osgi.xml" /> 
<import resource="classpath:META-INF/cxf/cxf-extension-policy.xml" /> 
<import resource="classpath:META-INF/cxf/cxf-extension-ws-security.xml" /> 

<bean id="myPasswordCallback" class="com.mycompany.ServerPasswordCallback" /> 

<cxfbc:consumer wsdl="classpath:wsdl/person.wsdl" 
    targetService="person:PersonService" targetInterface="person:Person" 
    properties="#properties" delegateToJaas="false" > 
<!-- not important for ws-security 
<cxfbc:inInterceptors> 
    <bean class="com.mycompany.SaveSubjectInterceptor" /> 
    <bean class="org.apache.cxf.interceptor.LoggingInInterceptor" /> 
</cxfbc:inInterceptors> 
--> 
</cxfbc:consumer> 

<util:map id="properties"> 
    <entry> 
    <key> 
    <util:constant 
     static-field="org.apache.cxf.ws.security.SecurityConstants.CALLBACK_HANDLER" /> 
    </key> 
    <ref bean="myPasswordCallback" /> 
    </entry> 
</util:map> 

<httpj:engine-factory bus="cxf"> 
    <httpj:engine port="9001"> 
    <httpj:tlsServerParameters> 
    <sec:keyManagers keyPassword="password"> 
     <sec:keyStore type="JKS" password="password" resource="certs/cherry.jks" /> 
    </sec:keyManagers> 
    <sec:cipherSuitesFilter> 
     <sec:include>.*_WITH_3DES_.*</sec:include> 
     <sec:include>.*_WITH_DES_.*</sec:include> 
     <sec:exclude>.*_WITH_NULL_.*</sec:exclude> 
     <sec:exclude>.*_DH_anon_.*</sec:exclude> 
    </sec:cipherSuitesFilter> 
    <sec:clientAuthentication want="false" 
     required="false" /> 
    </httpj:tlsServerParameters> 
</httpj:engine> 
</httpj:engine-factory> 

<bean id="cxf" class="org.apache.cxf.bus.CXFBusImpl" /> 

<bean class="org.apache.servicemix.common.osgi.EndpointExporter" /> 

</beans> 

完整的示例,可以發現here最終beans.xml文件,但一段時間後,它可能不存在。

0

由於https://issues.apache.org/activemq/browse/SMXCOMP-711https://issues.apache.org/activemq/browse/SMXCOMP-712決議( servicemix-cxf-bc-2010.01),它應該是可能的,而且容易做到。

查看http://fisheye6.atlassian.com/browse/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/ws/security/CxfBcSecurityJAASTest.java?r=HEAD爲例。具體來說就是testJAASPolicy方法。

至於與聲明UsernameToken聲明有關的錯誤,您可能想嘗試將UsernameToken聲明放入SupportingTokenbinding assertion的內部,具體取決於您想對令牌執行的操作。看起來你只是想在消息中傳遞一個用戶名和密碼而沒有任何其他安全性,比如令牌與消息或加密的加密綁定,因此支持令牌很可能符合你的需求。

我也勸你使用的UsernameToken時需要考慮以下附加措施:

  1. 密碼學的令牌綁定到使用簽名的消息。
  2. 使用隨機數和創建時間戳和緩存令牌在服務器上,以防止重放
  3. 考慮加密令牌使用XML ENC
  4. 使用TLS(簽約,如果你還簽收前)無論是在代替或補充以上建議
+0

好的,在看了JAASTest之後,我仍然沒有絲毫知道如何實現它。此外,它似乎並沒有JAASTest甚至使用wsdl與其中定義的ws-security策略,除非我遺漏了一些東西,而且似乎並沒有apache發佈servicemix-cxf-bc-2010.01.xsd ,所以我不能使用它。 – Vinh 2010-04-06 18:24:57

+0

帶外部策略附件的CXF總線示例: http://fisheye6.atlassian.com/browse/servicemix/components/bindings/servicemix-cxf-bc/tags/servicemix-cxf-bc-2010.01/src/test/ resources/org/apache/servicemix/cxfbc/ws/security/xbean-jaas-policy-bus-context.xml?r = HEAD 請參閱http://cxf.apache.org/docs/ws-securitypolicy。HTML的其他方式來附加政策。 配置您的CXF-BC消費者: http://fisheye6.atlassian.com/browse/servicemix/components/bindings/servicemix-cxf-bc/tags/servicemix-cxf-bc-2010.01/src/test/resources/ org/apache/servicemix/cxfbc/ws/security/xbean-jaas.xml?r = HEAD – DavidValeri 2010-04-07 12:14:36

+0

你需要的一切應該在這裏http://repo2.maven.org/maven2/org/apache/servicemix/servicemix-cxf- bc/2010.01/ – DavidValeri 2010-04-07 12:15:45