我正在使用Spring Integration,我想知道是否可以通过MarshallingWebServiceOutboundGateway以任何方式保护输入/输出。
我的结构:
请求频道 - >网关 - >响应渠道
更新III
现在,我简化了我的逻辑。我试图以其他方式配置Wss4jSecurityInterceptor。从Spring WS文档中,我看到了这个例子:
<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"/>
<property name="validationActions" value="Signature"/>
<property name="validationSignatureCrypto">
<bean class="org.springframework.ws.soap.security.wss4j.support.CryptoFactoryBean">
<property name="keyStorePassword" value="123456"/>
<property name="keyStoreLocation" value="classpath:/keystore.jks"/>
</bean>
</property>
</bean>
适应我的Java配置:
@Bean
public Wss4jSecurityInterceptor wss4jSecurityInterceptor() throws IOException, Exception{
Wss4jSecurityInterceptor interceptor = new Wss4jSecurityInterceptor();
interceptor.setSecurementActions("UsernameToken Encrypt");
interceptor.setSecurementUsername("https user");
interceptor.setSecurementPassword("https password");
interceptor.setValidationActions("Signature");
interceptor.setValidationSignatureCrypto( signature().getObject() );
return interceptor;
}
public CryptoFactoryBean signature() throws IOException{
CryptoFactoryBean trustStore = new CryptoFactoryBean();
trustStore.setKeyStoreLocation( new ClassPathResource("security/keystore.jks") );
trustStore.setKeyStorePassword( "keystore_password" );
return trustStore;
}
这非常令人沮丧,但我收到了一个新错误:
Caused by: java.lang.IllegalArgumentException: validationSignatureCrypto is required
at org.springframework.util.Assert.notNull(Assert.java:112)
at org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor.afterPropertiesSet(Wss4jSecurityInterceptor.java:515)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1625)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1562)
... 58 more
更新II
在我的第二种方法中,我将配置更改为@Bean方法。此时,我刚刚配置用户/密码但没有成功,但我需要使用我的.cert文件连接到服务器。
@Bean
public CallbackHandler passwordCallbackHandler(){
SimplePasswordValidationCallbackHandler handler = new SimplePasswordValidationCallbackHandler();
Properties users = new Properties();
users.setProperty("user1", "pass1");
users.setProperty("user2", "pass2");
handler.setUsers(users);
return handler;
}
@Bean
public ClientInterceptor wsSecurityInterceptor(){
XwsSecurityInterceptor xws = new XwsSecurityInterceptor();
xws.setPolicyConfiguration(new ClassPathResource("securityPolicy.xml"));
xws.setCallbackHandlers(new CallbackHandler[]{
passwordCallbackHandler()
});
return xws;
}
我的securityPolicy.xml:
<xwss:SecurityConfiguration xmlns:xwss="http://java.sun.com/xml/ns/xwss/config">
<xwss:RequireUsernameToken passwordDigestRequired="false" nonceRequired="false"/>
</xwss:SecurityConfiguration>
收到以下错误:
Caused by: java.lang.ClassNotFoundException: com.sun.xml.wss.XWSSecurityException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
... 72 more
更新我
我整合了:
弹簧的WS-Security
@Configuration
@EnableWs
@EnableIntegration
public class ConfigWS {
@Bean
public MessageHandler wsOutboundGateway() throws Exception {
MarshallingWebServiceOutboundGateway gw =new MarshallingWebServiceOutboundGateway(myprovider,
jaxb2Marshaller(),
jaxb2Marshaller());
gw.setOutputChannelName("responseChannel");
SimplePasswordValidationCallbackHandler spvch = new SimplePasswordValidationCallbackHandler();
Properties users = new Properties();
users.setProperty("user", "pass");
spvch.setUsers( users );
XwsSecurityInterceptor xws = new XwsSecurityInterceptor();
xws.setSecureRequest(true);
xws.setSecureResponse(true);
xws.setPolicyConfiguration( new ClassPathResource("securityPolicy.xml"));
xws.setCallbackHandler( spvch );
gw.setInterceptors( xws );
gw.afterPropertiesSet();
return gw;
}
....
}
我得到了:
Caused by: java.lang.ClassNotFoundException: com.sun.xml.wss.impl.callback.PasswordValidationCallback$PasswordValidator
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
... 50 more
答案 0 :(得分:1)
Spring Integration WebServices模块完全基于Spring WS。因此,只需遵循其giudeline,如何在client side上配置WSS。
只需将XwsSecurityInterceptor
或Wss4jSecurityInterceptor
注入<int-ws:outbound-gateway>
。