SAML2KeyInfo saml2KeyInfo = SAML2Utils.
getSAML2KeyInfo(assertion, signatureCrypto, tokenCallbackHandler);
//Store the token
try {
TokenStorage store = rmd.getTokenStorage();
if (store.getToken(id) == null) {
Token token = new Token(id, (OMElement) SAML2Utils.getElementFromAssertion(assertion), dateOfCreation, dateOfExpiration);
token.setSecret(saml2KeyInfo.getSecret());
store.add(token);
}
} catch (Exception e) {
throw new RampartException(
"errorInAddingTokenIntoStore", e);
}
}
//if this is a SAML1.1 assertion
else {
final SAMLAssertion assertion = ((SAMLAssertion) wser.get(
WSSecurityEngineResult.TAG_SAML_ASSERTION));
// if the subject confirmation method is Bearer, do not try to get the KeyInfo
if(RahasConstants.SAML11_SUBJECT_CONFIRMATION_BEARER.equals(
TrustUtil.getSAML11SubjectConfirmationMethod(assertion))){
break;
}
String id = assertion.getId();
Date created = assertion.getNotBefore();
Date expires = assertion.getNotOnOrAfter();
SAMLKeyInfo samlKi = SAMLUtil.getSAMLKeyInfo(assertion,
signatureCrypto, tokenCallbackHandler);
try {
TokenStorage store = rmd.getTokenStorage();
if (store.getToken(id) == null) {
Token token = new Token(id, (OMElement) assertion.toDOM(), created, expires);
token.setSecret(samlKi.getSecret());
store.add(token);
}
} catch (Exception e) {
throw new RampartException(
"errorInAddingTokenIntoStore", e);
}