我有一个 Web 应用程序,它充当使用 Spring WS 实现的 Jax-WS Web 服务的客户端。 Spring WS 配置为需要 SOAP header 中的用户名 token 。在 Web 应用程序中,我计划使用 Spring Web 服务模板,但似乎找不到任何示例来说明如何将 UsernameToken 添加到传出请求。
有人可以指出我正确的方向吗?
谢谢。
最佳答案
您必须使用 Interceptors .见 Chapter 7. Securing your Web services with Spring-WS .
配置将是这样的
<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
<property name="marshaller" ref="marshaller" />
<property name="unmarshaller" ref="marshaller" />
<property name="defaultUri"
value="http://localhost:8080/ws-demo/myws" />
<property name="interceptors">
<list>
<ref bean="wsSecurityInterceptor" />
</list>
</property>
</bean>
<bean id="wsSecurityInterceptor" class="org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor">
<property name="securementActions" value="UsernameToken"/>
<property name="securementUsername" value="Ernie"/>
<property name="securementPassword" value="Bert"/>
</bean>
关于web-services - Spring Web 服务模板 : Add username token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9284024/