我正在通过WSS4JSecurityInterceptor使用Spring集成+ Spring WS Security。
我有一个WS客户端使用下一个安全方案在服务器上使用Web服务:
有了这两个条件,我对Spring文档提供的有关客户端/服务器配置的示例感到有些困惑。我无法在服务器端更改任何配置。我只有:用户,密码和.cert文件。
我有下一个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( NEED TO BE DEFINED );
return interceptor;
}
此方案的解决方案:
首先,将.cer文件导入到您自己的密钥库中:
keytool -importcert -v -trustcacerts-文件“ path \ to \ file.cer” -alias myAlias -keystore“ myNewKeyStore.jks” -storepass myPass
将文件放在您的类路径下
如果使用的是maven,请将其配置为包括.jks文件,并且不对此类资源进行过滤。这对于在编译时维护证书很重要。
使此配置适应您的WS场景:
@Bean
public Wss4jSecurityInterceptor wss4jSecurityInterceptor() throws Exception{
Wss4jSecurityInterceptor interceptor = new Wss4jSecurityInterceptor();
interceptor.setSecurementActions("UsernameToken");
interceptor.setSecurementUsername("user http");
interceptor.setSecurementPassword("pass http");
interceptor.setValidationActions("Signature");
interceptor.setValidationSignatureCrypto( myCrypto() );
interceptor.afterPropertiesSet();
return interceptor;
}
@Bean
public Crypto myCrypto() throws Exception{
CryptoFactoryBean factory = new CryptoFactoryBean();
factory.setTrustStorePassword( "myPass" );
factory.setKeyStorePassword( "myPass" );
factory.setKeyStoreLocation( new ClassPathResource("myNewKeyStore.jks") );
factory.afterPropertiesSet();
return factory.getObject();
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句