// fifth step: compute the signature
//
// after "prepare" the Signature XML element is ready and may prepend
// this to the security header.
SignatureActionToken signatureToken = null;
if (actionToken instanceof SignatureActionToken) {
signatureToken = (SignatureActionToken)actionToken;
}
if (signatureToken == null) {
signatureToken = reqData.getSignatureToken();
}
WSSecSignature sign = new WSSecSignature(reqData.getWssConfig());
sign.setCustomTokenValueType(WSConstants.USERNAMETOKEN_NS + "#UsernameToken");
sign.setCustomTokenId(builder.getId());
sign.setSecretKey(builder.getDerivedKey());
sign.setKeyIdentifierType(WSConstants.CUSTOM_SYMM_SIGNING);
if (signatureToken.getDigestAlgorithm() != null) {
sign.setDigestAlgo(signatureToken.getDigestAlgorithm());
}
if (signatureToken.getSignatureAlgorithm() != null) {
sign.setSignatureAlgorithm(signatureToken.getSignatureAlgorithm());
} else {
sign.setSignatureAlgorithm(WSConstants.HMAC_SHA1);
}
sign.prepare(doc, null, reqData.getSecHeader());
// prepend in this order: first the Signature Element and then the
// UsernameToken Element. This way the server gets the UsernameToken
// first, can check it and are prepared to compute the Signature key.
// sign.prependToHeader(reqData.getSecHeader());
// builder.prependToHeader(reqData.getSecHeader());
List<WSEncryptionPart> parts = null;
if (signatureToken.getParts().size() > 0) {
parts = signatureToken.getParts();
} else {
SOAPConstants soapConstants = reqData.getSoapConstants();
if (soapConstants == null) {
soapConstants = WSSecurityUtil.getSOAPConstants(doc.getDocumentElement());
}