}
public void process(WSSecHeader secHeader, Document doc, PropertyExpansionContext context) {
try {
SAMLParms samlParms = new SAMLParms();
SAMLCallbackHandler callbackHandler = null;
if (!signed) {
WSSecSAMLToken wsSecSAMLToken = new WSSecSAMLToken();
if (samlVersion.equals(SAML_VERSION_1)) {
callbackHandler = new SAML1CallbackHandler(assertionType, confirmationMethod);
} else if (samlVersion.equals(SAML_VERSION_2)) {
callbackHandler = new SAML2CallbackHandler(assertionType, confirmationMethod);
} else {
throw new IllegalArgumentException(NOT_A_VALID_SAML_VERSION);
}
AssertionWrapper assertion = createAssertion(context, samlParms, callbackHandler);
wsSecSAMLToken.build(doc, assertion, secHeader);
} else {
WSSecSignatureSAML wsSecSignatureSAML = new WSSecSignatureSAML();
WssCrypto wssCrypto = getWssContainer().getCryptoByName(crypto, true);
String alias = context.expand(getUsername());
if (wssCrypto == null) {
throw new RuntimeException("Missing keystore [" + crypto + "] for signature entry");
} else if (Strings.isNullOrEmpty(alias)) {
throw new RuntimeException(" No alias was provided for the keystore '" + crypto + "'. Please check your SAML (Form) configurations");
}
if (samlVersion.equals(SAML_VERSION_1)) {
callbackHandler = new SAML1CallbackHandler(wssCrypto.getCrypto(), alias,
assertionType, confirmationMethod);
} else if (samlVersion.equals(SAML_VERSION_2)) {
callbackHandler = new SAML2CallbackHandler(wssCrypto.getCrypto(), alias,
assertionType, confirmationMethod);
} else {
throw new IllegalArgumentException(NOT_A_VALID_SAML_VERSION);
}
AssertionWrapper assertion = createAssertion(context, samlParms, callbackHandler);
assertion.signAssertion(context.expand(getUsername()), context.expand(getPassword()),
wssCrypto.getCrypto(), false);
wsSecSignatureSAML.setUserInfo(context.expand(getUsername()), context.expand(getPassword()));
if (confirmationMethod.equals(SENDER_VOUCHES_CONFIRMATION_METHOD)) {
wsSecSignatureSAML.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
wsSecSignatureSAML.build(doc, null, assertion, wssCrypto.getCrypto(), context.expand(getUsername()),
context.expand(getPassword()), secHeader);
} else if (confirmationMethod.equals(HOLDER_OF_KEY_CONFIRMATION_METHOD)) {
wsSecSignatureSAML.setDigestAlgo(digestAlgorithm);
if (assertionType.equals(AUTHENTICATION_ASSERTION_TYPE)) {
wsSecSignatureSAML.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE);
wsSecSignatureSAML.setSignatureAlgorithm(signatureAlgorithm);
} else if (assertionType.equals(ATTRIBUTE_ASSERTION_TYPE)) {
wsSecSignatureSAML.setKeyIdentifierType(WSConstants.X509_KEY_IDENTIFIER);
wsSecSignatureSAML.setSignatureAlgorithm(signatureAlgorithm);
byte[] ephemeralKey = callbackHandler.getEphemeralKey();
wsSecSignatureSAML.setSecretKey(ephemeralKey);
}
wsSecSignatureSAML.build(doc, wssCrypto.getCrypto(), assertion, null, null, null, secHeader);
}