log.debug("Found SAML Assertion element");
}
Validator validator =
data.getValidator(new QName(elem.getNamespaceURI(), elem.getLocalName()));
Credential credential = handleSAMLToken(elem, data, validator, wsDocInfo);
AssertionWrapper assertion = credential.getAssertion();
if (log.isDebugEnabled()) {
log.debug("SAML Assertion issuer " + assertion.getIssuerString());
log.debug(DOM2Writer.nodeToString(elem));
}
// See if the token has been previously processed
String id = assertion.getId();
Element foundElement = wsDocInfo.getTokenElement(id);
if (elem.equals(foundElement)) {
WSSecurityEngineResult result = wsDocInfo.getResult(id);
return java.util.Collections.singletonList(result);
} else if (foundElement != null) {
throw new WSSecurityException(
WSSecurityException.INVALID_SECURITY_TOKEN, "duplicateError"
);
}
wsDocInfo.addTokenElement(elem);
WSSecurityEngineResult result = null;
if (assertion.isSigned()) {
result = new WSSecurityEngineResult(WSConstants.ST_SIGNED, assertion);
} else {
result = new WSSecurityEngineResult(WSConstants.ST_UNSIGNED, assertion);
}
result.put(WSSecurityEngineResult.TAG_ID, assertion.getId());
if (validator != null) {
result.put(WSSecurityEngineResult.TAG_VALIDATED_TOKEN, Boolean.TRUE);
if (credential.getTransformedToken() != null) {
result.put(
WSSecurityEngineResult.TAG_TRANSFORMED_TOKEN, credential.getTransformedToken()
);
SAMLTokenPrincipal samlPrincipal =
new SAMLTokenPrincipal(credential.getTransformedToken());
result.put(WSSecurityEngineResult.TAG_PRINCIPAL, samlPrincipal);
} else if (credential.getPrincipal() != null) {
result.put(WSSecurityEngineResult.TAG_PRINCIPAL, credential.getPrincipal());
} else {
result.put(WSSecurityEngineResult.TAG_PRINCIPAL, new SAMLTokenPrincipal(assertion));
}
}
wsDocInfo.addResult(result);