}
String issuerKeyName = null;
String issuerKeyPW = null;
Crypto issuerCrypto = null;
WSSecSignatureSAML wsSign = new WSSecSignatureSAML();
wsSign.setWsConfig(reqData.getWssConfig());
String password = null;
if (saml.isSenderVouches()) {
issuerKeyName = saml.getIssuerKeyName();
issuerKeyPW = saml.getIssuerKeyPassword();
issuerCrypto = saml.getIssuerCrypto();
} else {
password =
handler.getPassword(reqData.getUsername(),
actionToDo,
WSHandlerConstants.PW_CALLBACK_CLASS,
WSHandlerConstants.PW_CALLBACK_REF, reqData)
.getPassword();
wsSign.setUserInfo(reqData.getUsername(), password);
}
if (reqData.getSigKeyId() != 0) {
wsSign.setKeyIdentifierType(reqData.getSigKeyId());
}
if (reqData.getSigAlgorithm() != null) {
wsSign.setSignatureAlgorithm(reqData.getSigAlgorithm());
}
if (reqData.getSigDigestAlgorithm() != null) {
wsSign.setDigestAlgo(reqData.getSigDigestAlgorithm());
}
/*
* 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,
issuerCrypto,
issuerKeyName,
issuerKeyPW,
reqData.getSecHeader());
reqData.getSignatureValues().add(wsSign.getSignatureValue());
} catch (WSSecurityException e) {
throw new WSSecurityException("Error when signing the SAML token: ", e);
}
}