Spring XWSS Message Signing

最后都变了- 提交于 2021-02-11 12:41:06

问题


I am currently working on a client interface which connects to a third party web service.

This 3rd party web service requires that all messages sent to them are signed with the client's private key.

I am attempting to implement this using Spring's XWSS support as documented here:

http://docs.spring.io/spring-ws/site/reference/html/security.html

The issue I'm facing is that the messages I send out are not being signed despite what as far as I can tell is a correct configuration.

My applicationContext.xml is as follows:

<beans 
   xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xmlns:p="http://www.springframework.org/schema/p"
   xmlns:util="http://www.springframework.org/schema/util" 
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:tx="http://www.springframework.org/schema/tx" 
   xmlns:aop="http://www.springframework.org/schema/aop"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
                       http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                       http://www.springframework.org/schema/util
                       http://www.springframework.org/schema/util/spring-util-3.1.xsd
                       http://www.springframework.org/schema/context
                       http://www.springframework.org/schema/context/spring-context-3.1.xsd
                       http://www.springframework.org/schema/tx
                       http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
                       http://www.springframework.org/schema/aop
                       http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">

    ^
    |
    |
    B
    E
    A
    N
    S
    |
    |
    V

    <bean id="wsSecurityInterceptor"
         class="org.springframework.ws.soap.security.xwss.XwsSecurityInterceptor">
         <property name="policyConfiguration" value="classpath:securityPolicy.xml"/>
         <property name="callbackHandlers">
            <list>
               <ref bean="keyStoreHandler"/>
            </list>
         </property>
    </bean>

    <bean id="keyStoreHandler"
         class="org.springframework.ws.soap.security.xwss.callback.KeyStoreCallbackHandler">
         <property name="keyStore" ref="keyStore"/>
         <property name="privateKeyPassword" value="ckpass"/>
    </bean>

    <bean id="keyStore"
        class="org.springframework.ws.soap.security.support.KeyStoreFactoryBean">
        <property name="location" value="file:///C:/path/to/security/clientKeystore.jks"/>
        <property name="password" value="cspass"/>
    </bean>
</beans> 

My securityPolicy.xml consists of the following:

<xwss:SecurityConfiguration dumpMessages="true" xmlns:xwss="http://java.sun.com/xml/ns/xwss/config">
    <xwss:Sign>
   </xwss:Sign>
</xwss:SecurityConfiguration>

However there are no messages being dumped to standard output when I send messages out and the messages I send out do not contain the signature elements I would expect.

I suspect I am missing something quite trivial here however I cannot tell what that is for the life of me!


回答1:


In your configuration you only configure the interceptor. Currently it takes up only memory just hanging around and doing nothing. You should hook this interceptor up to your WebServiceTemplate (or class that extends WebServiceGatewaySupport.

Assuming you have one of those you should have something like this.

<bean id="yourClient" class="YourClientClass">
    <property name="interceptors" ref="wsSecurityInterceptor"/>
    // Your other properties here
</bean>

This wired your interceptor to the WebServiceTemplate used, without it the interceptor is basically not used.



来源:https://stackoverflow.com/questions/21526767/spring-xwss-message-signing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!