【问题标题】:Implementing WS-I Basic Profile in Spring WS在 Spring WS 中实现 WS-I Basic Profile
【发布时间】:2016-01-27 09:03:30
【问题描述】:

我的项目使用 Spring WS 来使用 SOAP Web 服务。 Web 服务调用通过 webServiceTemplate.marshalSendAndReceive(..) 到目前为止一切正常。

最近,Web 服务发布者通知我们实施 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 安全性?

任何指针将不胜感激。

【问题讨论】:

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


    【解决方案1】:

    自己找到了。

    这是方法。

    1. 为 Wss4jSecurityInterceptor 声明 bean(这基本上在 spring-ws-security jar 中可用) 通过 bean 的 securementUsername、securementPassword 属性提供凭据。

    同样重要的是,将 securementActions 设置为“UsernameToken”(这是我需要的,只是要在 WS-I Basic Profile Header 中发送的用户名和密码)

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

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

    2. 瞧!

    示例配置

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

    【讨论】:

      【解决方案2】:

      在我的例子中,使用证书加密的 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));
      

      【讨论】:

        猜你喜欢
        • 2011-08-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多