在 Spring WS 中实现 WS-I 基本配置文件



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

最近,Web 服务发布者通知我们实现 WS-I 基本配置文件 1.1,以便能够获得响应。

以下是收到的示例,该示例应该在请求的 SOAP 标头上发送。

<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 安全性?

任何指示将不胜感激。

设法

自己找到了。

这是方法。

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

同样重要的是,将securementActions设置为"用户名令牌"(这是我所需要的,只需在WS-I基本配置文件标头中发送用户名和密码)

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

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

  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>

就我而言,使用 SOAP12 和用证书加密的密码,我做了 cxf 拦截器实现,因为 spring 的配置不起作用。

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

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

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

最新更新