【发布时间】:2014-12-12 09:53:20
【问题描述】:
我正在使用 Spring Integration,我想知道是否可以以任何方式保护通过 MarshallingWebServiceOutboundGateway 生成的输入/输出。
我的结构:
请求通道 --> 网关 --> 响应通道
更新 III
- 安全性是 HTTPS 用户/密码
- 使用证书进行验证
现在,我简化了我的逻辑。我正在尝试以其他方式配置 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
-
spring-ws-安全
@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
- 如何配置安全 securityPolicy.xml 以便 根据服务器证书进行身份验证。
- 是 SimplePasswordValidationCallbackHandler 所需的解决方案 使用服务器证书?也许我必须使用其他处理程序。
- 我的证书提供商给了我一个 .cert 文件。因此,我生成了 .keystore 与 Oracle 的 keytool 但我不知道如何 在我的配置中包含此证书。
【问题讨论】:
标签: web-services certificate spring-integration keystore ws-security