// See if the token has been previously processed
String id = samlAssertion.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.ErrorCode.INVALID_SECURITY_TOKEN, "duplicateError"
);
}
wsDocInfo.addTokenElement(elem);
WSSecurityEngineResult result = null;
if (samlAssertion.isSigned()) {
result = new WSSecurityEngineResult(WSConstants.ST_SIGNED, samlAssertion);
} else {
result = new WSSecurityEngineResult(WSConstants.ST_UNSIGNED, samlAssertion);
}
result.put(WSSecurityEngineResult.TAG_ID, samlAssertion.getId());
if (validator != null) {
result.put(WSSecurityEngineResult.TAG_VALIDATED_TOKEN, Boolean.TRUE);
if (credential.getTransformedToken() != null) {
result.put(
WSSecurityEngineResult.TAG_TRANSFORMED_TOKEN, credential.getTransformedToken()
);
if (credential.getPrincipal() != null) {
result.put(WSSecurityEngineResult.TAG_PRINCIPAL, credential.getPrincipal());
} else {
SAMLTokenPrincipalImpl samlPrincipal =
new SAMLTokenPrincipalImpl(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 SAMLTokenPrincipalImpl(samlAssertion));
}
result.put(WSSecurityEngineResult.TAG_SUBJECT, credential.getSubject());
}
wsDocInfo.addResult(result);
return java.util.Collections.singletonList(result);
}