cxf-bc中的WS-securitypolicy部署在servicemix中

时间:2010-03-31 16:04:11

标签: cxf ws-security apache-servicemix usernametoken

我想知道是否可以使用WS-SecurityPolicy而不仅仅是WS-Security构建cxf-bc。 WS-SecurityPolicy似乎是一个更优雅的解决方案,因为一切都在WSDL中。欢迎举例。 :)

在David的帮助下,我得到了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>

2 个答案:

答案 0 :(得分: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. 加密令牌(在签名之前,如果您也签名)
  5. 使用TLS代替或补充上述建议

答案 1 :(得分:0)

在servicemix-user邮件列表中使用david和Freeman。我终于得到了正确的配置来实现WS-Security Policy。

这是我BC的最终beans.xml

<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的完整示例,但过了一段时间后可能不存在。