在Spring WS中实现WS-I Basic Profile

时间:2016-01-27 09:03:31

标签: spring web-services soap spring-security spring-ws

My Project使用Spring WS来使用SOAP Web服务。 Webservice调用通过webServiceTemplate.marshalSendAndReceive(..)发送 到目前为止一切正常。

最近,Webservice发布商已通知我们实施WS-I Basic Profile 1.1以便能够获得响应。

以下是收到的样本,该样本应该在请求的SOAP Header上发送。

<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
    <wsse:UsernameToken>
        <wsse:Username> </wsse:Username>
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"> </wsse:Password>
    </wsse:UsernameToken>
</wsse:Security>

是否有配置此示例?在这种情况下如何继续使用Spring-WS Security?

任何指针都会受到赞赏。

2 个答案:

答案 0 :(得分:1)

管理自己找出来。

这是方法。

  1. 为Wss4jSecurityInterceptor声明bean(这在spring-ws-security jar中基本可用) 通过bean的securementUsername,securementPassword属性提供凭证。
  2. 同样重要的是将securementActions设置为'UsernameToken'(这是我需要的,只需要在WS-I Basic Profile Header中发送用户名和密码)

    还有许多其他SecurementAction可用于securementActions。 (请参阅http://docs.spring.io/spring-ws/site/reference/html/security.html

    1. 在WebserviceTemplate的拦截器属性中包含Wss4jSecurityInterceptor bean。

    2. Voila!

    3. 示例配置

      <bean id="wsSecurityInterceptor"
          class="org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor">
          <property name="securementActions" value="UsernameToken" />
          <property name="securementUsername" value="${security.username}" />
          <property name="securementPasswordType" value="PasswordText" />
          <property name="securementPassword" value="${security.password}" />
          <property name="securementMustUnderstand" value="false" />
      </bean>
      
      <bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate"
          p:defaultUri="${service.endpt}" p:marshaller-ref="myServiceMarshaller"
          p:unmarshaller-ref="myServiceMarshaller">
          <property name="interceptors">
              <list>
                  <ref local="wsSecurityInterceptor" />
                  ..
              </list>
          </property>
      </bean>
      

答案 1 :(得分:0)

在我的情况下,使用SOAP12和使用证书加密的密码,我执行了cxf拦截器实现,因为spring的配置不起作用。

http://cxf.apache.org/docs/ws-security.html

我创建了webservices的bean JaxWsProxyFactoryBean,并添加了拦截器。

org.apache.cxf.endpoint.Client client = ClientProxy.getClient(YOUR_BEAN);
org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();
cxfEndpoint.getOutInterceptors().add(new WSS4JOutInterceptor(outProps));
cxfEndpoint.getInInterceptors().add( new WSS4JInInterceptor(inProps));
相关问题