I am trying to fetch data from a server that needs a digital certificate (JKS) in Keystore to authorize the soap request and in addition to this, it requires basic authorization with the WSS outgoing configuration. The images show the steps that I followed on SoapUI to test the web service successfully.
Image 1 and Image 2 below shows the WS-Security Configurations (an outgoing WS-Security Configuration). Image 1 adds Timestamp entry and Image 2 Signature configuration adding Keystore (keystore.jks), password, and few other configuration along with extra parts for Body and timestamp.
Image 3 integrates the WS-Security configuration from earlier steps for outgoing requests.
Soap UI requests suceeded following above steps. Now the requirement is to implement this programmatically. Unfortunately my attempts hasn't succeeded.
Could anybody guide me through these steps in spring web services or recommend me any other library(in java or php or any other language) to connect to a SOAP server with similar security.
Following is my code snippet that I tried using Spring WS with 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;
}