【问题标题】:WSS4J with Spring WS (user/password authentication + .cert)带有 Spring WS 的 WSS4J(用户/密码认证 + .cert)
【发布时间】:2015-02-16 16:50:39
【问题描述】:

我正在通过 WSS4JSecurityInterceptor 使用 Spring 集成 + Spring WS Security。

我有一个 WS 客户端使用服务器上的 Web 服务,并具有下一个安全方案:

  • Https抢先认证(用户和密码)
  • 服务器端给了我一个 .cert 文件来签名,但我不知道如何签名 转换为 .jks(密钥库文件)

有了这两个必要条件,我对 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;
}

【问题讨论】:

    标签: security encryption certificate spring-ws wss4j


    【解决方案1】:

    此场景的解决方案:

    1. 首先,将 .cer 文件导入到您自己的密钥库中:

      keytool -importcert -v -trustcacerts -file "path\to\file.cer" -alias myAlias -keystore "myNewKeyStore.jks" -storepass myPass

    2. 将文件放在你的类路径下

    3. 如果您使用的是 maven,请将其配置为包含 .jks 文件,并且对此类资源不进行过滤。这对于在编译时维护证书非常重要。

    4. 根据您的 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();
      }
      

    【讨论】:

    • 是否可以为一个端点设置一个拦截器,为另一个设置另一个拦截器?
    猜你喜欢
    • 1970-01-01
    • 2011-11-21
    • 2016-05-10
    • 2012-02-08
    • 1970-01-01
    • 1970-01-01
    • 2013-01-05
    • 2018-11-10
    • 2013-11-03
    相关资源
    最近更新 更多