if (log.isDebugEnabled()) {
log.debug(ex.getMessage(), ex);
}
}
SAMLIssuer saml = loadSamlIssuer(handler, reqData);
AssertionWrapper assertion = saml.newAssertion();
if (assertion == null) {
throw new WSSecurityException("WSHandler: Signed SAML: no SAML token received");
}
WSSecSignatureSAML wsSign = new WSSecSignatureSAML(reqData.getWssConfig());
CallbackHandler callbackHandler =
handler.getPasswordCallbackHandler(reqData);
WSPasswordCallback passwordCallback =
handler.getPasswordCB(reqData.getUsername(), actionToDo, callbackHandler, reqData);
wsSign.setUserInfo(reqData.getUsername(), passwordCallback.getPassword());
if (reqData.getSigKeyId() != 0) {
wsSign.setKeyIdentifierType(reqData.getSigKeyId());
}
if (reqData.getSigAlgorithm() != null) {
wsSign.setSignatureAlgorithm(reqData.getSigAlgorithm());
}
if (reqData.getSigDigestAlgorithm() != null) {
wsSign.setDigestAlgo(reqData.getSigDigestAlgorithm());
}
if (reqData.getSignatureC14nAlgorithm() != null) {
wsSign.setSigCanonicalization(reqData.getSignatureC14nAlgorithm());
}
/*
* required to add support for the
* signatureParts parameter.
* If not set WSSecSignatureSAML
* defaults to only sign the body.
*/
if (reqData.getSignatureParts().size() > 0) {
wsSign.setParts(reqData.getSignatureParts());
}
try {
wsSign.build(
doc,
crypto,
assertion,
saml.getIssuerCrypto(),
saml.getIssuerKeyName(),
saml.getIssuerKeyPassword(),
reqData.getSecHeader());
reqData.getSignatureValues().add(wsSign.getSignatureValue());
} catch (WSSecurityException e) {
throw new WSSecurityException("Error when signing the SAML token: ", e);
}