【问题标题】:using wss4jsecurityinterceptor for spring security- Configuring securement for signature and encryption with two keys使用 wss4jsecurityinterceptor 进行 spring security- 使用两个密钥配置签名和加密的安全性
【发布时间】:2018-08-17 06:49:32
【问题描述】:

我正在尝试通过阅读https://memorynotfound.com/spring-ws-certificate-authentication-wss4j/ 上的本教程来添加拦截器以保护 spring-ws

我需要在一个密钥库(server.jks-文件)中使用两个单独的公私钥(一个用于签名,第二个用于加密)。但我无法配置安全拦截器。

如果使用单个密钥库,它可以正常工作,但是当使用单独的密钥进行签名和加密时我应该如何设置以下内容

@Bean
public KeyStoreCallbackHandler securityCallbackHandler(){
    KeyStoreCallbackHandler callbackHandler = new KeyStoreCallbackHandler();
    callbackHandler.setPrivateKeyPassword("changeit");
    return callbackHandler;
}

@Bean
public Wss4jSecurityInterceptor securityInterceptor() throws Exception {
    Wss4jSecurityInterceptor securityInterceptor = new Wss4jSecurityInterceptor();

    // validate incoming request
    securityInterceptor.setValidationActions("Timestamp Signature Encrypt");
    securityInterceptor.setValidationSignatureCrypto(getCryptoFactoryBean().getObject());
    securityInterceptor.setValidationDecryptionCrypto(getCryptoFactoryBean().getObject());
    securityInterceptor.setValidationCallbackHandler(securityCallbackHandler());

    // encrypt the response
    securityInterceptor.setSecurementEncryptionUser("client-public");
    securityInterceptor.setSecurementEncryptionParts("{Content}{https://memorynotfound.com/beer}getBeerResponse");
    securityInterceptor.setSecurementEncryptionCrypto(getCryptoFactoryBean().getObject());

    // sign the response
    securityInterceptor.setSecurementActions("Signature Encrypt");
    securityInterceptor.setSecurementUsername("server");
    securityInterceptor.setSecurementPassword("changeit");
    securityInterceptor.setSecurementSignatureCrypto(getCryptoFactoryBean().getObject());

    return securityInterceptor;
}

@Bean
public CryptoFactoryBean getCryptoFactoryBean() throws IOException {
    CryptoFactoryBean cryptoFactoryBean = new CryptoFactoryBean();
    cryptoFactoryBean.setKeyStorePassword("changeit");
    cryptoFactoryBean.setKeyStoreLocation(new ClassPathResource("server.jks"));
    return cryptoFactoryBean;
}

对于加密,我们有方法 setSecurementEncryptionUser,但是我们如何配置 setValidationDecryptionCrypto 和 setValidationSignatureCrypto 以及别名来解密/验证

【问题讨论】:

    标签: spring-ws wss4j


    【解决方案1】:

    您可以尝试使用 2 个 securityInterceptor 和 2 个密钥库吗?一个用于签名,一个用于加密。然后将两个拦截器都添加到拦截器列表中。

    @Override
    public void addInterceptors(List<EndpointInterceptor> interceptors) {
        try {
            interceptors.add(signatureSecurityInterceptor());
            interceptors.add(encryptionSecurityInterceptor());
        } catch (Exception e) {
            throw new RuntimeException("could not initialize security interceptor");
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-10
      • 2011-06-29
      • 2015-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多