【问题标题】:WS-securitypolicy in cxf-bc deploy in servicemixcxf-bc 中的 WS-securitypolicy 部署在 servicemix 中
【发布时间】:2010-03-31 16:04:10
【问题描述】:

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

在 David 的帮助下,我在 ESB 上安装并运行了 CXF-BC,但我似乎无法对其进行测试。它不断返回:

<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>

【问题讨论】:

    标签: cxf ws-security apache-servicemix usernametoken


    【解决方案1】:

    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 代替或补充上述建议

    【讨论】:

    【解决方案2】:

    大卫和弗里曼在 servicemix-user 邮件列表中。我终于能够获得正确的配置来实施 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 找到完整的示例,但它可能会在一段时间后不存在。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-13
      • 2017-10-02
      • 1970-01-01
      • 2015-07-06
      • 1970-01-01
      相关资源
      最近更新 更多