SOAP API 请求的 WS-Security 配置

问题描述 投票:0回答:1

我正在尝试从需要 Keystore 中的数字证书 (JKS) 的服务器获取数据以授权 soap 请求,除此之外,它还需要 WSS 传出配置的基本授权。这些图像显示了我在 SoapUI 上成功测试 Web 服务所遵循的步骤。

下面的图像 1 和图像 2 显示了 WS-Security 配置(传出的 WS-Security 配置)。图 1 添加了时间戳条目和图 2 签名配置,添加了密钥库 (keystore.jks)、密码和一些其他配置以及正文和时间戳的额外部分。

图 3 集成了早期传出请求步骤中的 WS-Security 配置。

Soap UI 请求按照上述步骤成功。现在的要求是以编程方式实现这一点。不幸的是我的尝试没有成功。

任何人都可以指导我完成 spring web 服务中的这些步骤,或者推荐我任何其他库(java 或 php 或任何其他语言)连接到具有类似安全性的 SOAP 服务器。

以下是我尝试将 Spring WS 与 Wss4j 结合使用的代码片段。

@Configuration
public class SoapClientConfig extends WsConfigurerAdapter {

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

    securityInterceptor.setSecurementActions("Signature Timestamp");


    securityInterceptor.setSecurementTimeToLive(300000);
    securityInterceptor.setTimestampPrecisionInMilliseconds(true);

    securityInterceptor.setSecurementUsername("key-alias");
    securityInterceptor.setSecurementPassword("password");
    securityInterceptor.setSecurementSignatureCrypto(getCryptoFactoryBean().getObject());

   
    securityInterceptor.setSecurementSignatureKeyIdentifier("DirectReference");
    securityInterceptor.setSecurementSignatureAlgorithm("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256");
    securityInterceptor.setSecurementSignatureDigestAlgorithm("http://www.w3.org/2001/04/xmlenc#sha256");
    
    securityInterceptor.setSecurementMustUnderstand(true);
    securityInterceptor.setSecurementSignatureParts("{Content}{http://schemas.xmlsoap.org/soap/envelope/}Body;{Content}{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd}Timestamp");


    return securityInterceptor;
}

@Bean
public CryptoFactoryBean getCryptoFactoryBean() throws IOException {

    CryptoFactoryBean cryptoFactoryBean = new CryptoFactoryBean();
    cryptoFactoryBean.setKeyStorePassword("password");
    cryptoFactoryBean.setKeyStoreLocation(new ClassPathResource("keystore.jks"));

    return cryptoFactoryBean;

}
java soap soapui ws-security wss4j
1个回答
0
投票

wsdl 有策略部分吗?如果有,则不能使用拦截器。根据我的经验,“Policy Rejected”并不总是来自服务器的验证,它可以来自客户端。

拦截器可能包括策略检查后的安全性(客户端)。

© www.soinside.com 2019 - 2024. All rights reserved.