I'm using Spring + wss4j with annotations config. The Wss4jSecurityInterceptor
interceptor has this configuration:
@Bean
public Wss4jSecurityInterceptor sessionInterceptorNb() throws Exception {
Wss4jSecurityInterceptor securityInterceptor = new Wss4jSecurityInterceptor();
// set security actions
securityInterceptor.setSecurementActions("UsernameToken Signature Encrypt");
// sign the request
securityInterceptor.setSecurementUsername("anyuser");
securityInterceptor.setSecurementPassword("anypassword");
securityInterceptor.setSecurementSignatureUser("privatecertuser");
securityInterceptor.setSecurementSignatureCrypto(getCryptoFactoryBeanNb().getObject());
securityInterceptor.setSecurementSignatureParts("{Content}{http://schemas.xmlsoap.org/soap/envelope/}Body");
return securityInterceptor;
}
That's all.
I want to set anyuser and anypassword to the request element UsernameToken
and use the privatecertuser to sign the request, but I'm geeting this error:
Original Exception was java.security.UnrecoverableKeyException: Cannot recover key
Caused by: org.apache.wss4j.common.ext.WSSecurityException: Error during Signature:
at org.apache.wss4j.dom.action.SignatureAction.execute(SignatureAction.java:163)
at org.apache.wss4j.dom.handler.WSHandler.doSenderAction(WSHandler.java:238)
at org.springframework.ws.soap.security.wss4j2.Wss4jHandler.doSenderAction(Wss4jHandler.java:63)
at org.springframework.ws.soap.security.wss4j2.Wss4jSecurityInterceptor.secureMessage(Wss4jSecurityInterceptor.java:574)
... 45 common frames omitted
Caused by: org.apache.wss4j.common.ext.WSSecurityException: The private key for the supplied alias does not exist in the keystore
at org.apache.wss4j.dom.message.WSSecSignature.computeSignature(WSSecSignature.java:595)
at org.apache.wss4j.dom.action.SignatureAction.execute(SignatureAction.java:155)
... 48 common frames omitted
I'm using the command keytool -list -v -keystore
to see the content of the keystore and I can see the private entry for the "privatecertuser".
If I delete the method call to
securityInterceptor.setSecurementSignatureUser("privatecertuser");
and set this value in the method setSecurementUsername
works fine.
What can be wrong in the condiguration?