use of org.forgerock.openam.sts.tokengeneration.saml2.xmlsig.SAML2CryptoProvider in project OpenAM by OpenRock.
the class SAML2TokenGenerationImpl method signAssertion.
private void signAssertion(Assertion assertion, STSInstanceState instanceState) throws TokenCreationException {
final SAML2CryptoProvider saml2CryptoProvider = instanceState.getSAML2CryptoProvider();
final SAML2Config saml2Config = instanceState.getConfig().getSaml2Config();
String signatureKeyPassword;
try {
signatureKeyPassword = new String(saml2Config.getSignatureKeyPassword(), AMSTSConstants.UTF_8_CHARSET_ID);
} catch (UnsupportedEncodingException e) {
throw new TokenCreationException(ResourceException.INTERNAL_ERROR, "Could not obtain string representation of signature key password in SAML2TokenGenerationImpl: ");
}
/*
Note: the cert alias and private-key alias are the same. If there is a key entry in the keystore, it seems like
they are represented by the same alias.
*/
PrivateKey privateKey = saml2CryptoProvider.getIDPPrivateKey(saml2Config.getSignatureKeyAlias(), signatureKeyPassword);
try {
assertion.sign(privateKey, saml2CryptoProvider.getIDPX509Certificate(saml2Config.getSignatureKeyAlias()));
} catch (SAML2Exception e) {
throw new TokenCreationException(ResourceException.INTERNAL_ERROR, "Exception caught signing assertion in SAML2TokenGenerationImpl: " + e, e);
}
}
Aggregations