@Override
public boolean assertToken(TokenSecurityEvent<? extends SecurityToken> tokenSecurityEvent,
AbstractToken abstractToken) throws WSSPolicyException {
if (!(tokenSecurityEvent instanceof IssuedTokenSecurityEvent)) {
throw new WSSPolicyException("Expected a IssuedTokenSecurityEvent but got " + tokenSecurityEvent.getClass().getName());
}
IssuedToken issuedToken = (IssuedToken) abstractToken;
IssuedTokenSecurityEvent<? extends SecurityToken> issuedTokenSecurityEvent
= (IssuedTokenSecurityEvent<? extends SecurityToken>) tokenSecurityEvent;
try {
if (issuedToken.getIssuerName() != null &&
!issuedToken.getIssuerName().equals(issuedTokenSecurityEvent.getIssuerName())) {
setErrorMessage("IssuerName in Policy (" + issuedToken.getIssuerName() +
") didn't match with the one in the IssuedToken (" + issuedTokenSecurityEvent.getIssuerName() + ")");
return false;
}
if (issuedToken.getRequestSecurityTokenTemplate() != null) {
if (issuedTokenSecurityEvent instanceof SamlTokenSecurityEvent) {
SamlTokenSecurityEvent samlTokenSecurityEvent = (SamlTokenSecurityEvent) issuedTokenSecurityEvent;
String errorMsg = checkIssuedTokenTemplate(issuedToken.getRequestSecurityTokenTemplate(), samlTokenSecurityEvent);
if (errorMsg != null) {
setErrorMessage(errorMsg);
return false;
}
} else if (issuedTokenSecurityEvent instanceof KerberosTokenSecurityEvent) {
KerberosTokenSecurityEvent kerberosTokenSecurityEvent = (KerberosTokenSecurityEvent) issuedTokenSecurityEvent;
String errorMsg = checkIssuedTokenTemplate(issuedToken.getRequestSecurityTokenTemplate(), kerberosTokenSecurityEvent);
if (errorMsg != null) {
setErrorMessage(errorMsg);
return false;
}
}
}
Element claims = issuedToken.getClaims();
if (claims != null && issuedTokenSecurityEvent instanceof SamlTokenSecurityEvent) {
String errorMsg =
validateClaims((Element) claims, (SamlTokenSecurityEvent)issuedTokenSecurityEvent);
if (errorMsg != null) {
setErrorMessage(errorMsg);
return false;
}
}
} catch (XMLSecurityException e) {
throw new WSSPolicyException(e.getMessage(), e);
}
//always return true to prevent false alarm in case additional tokens with the same usage
//appears in the message but do not fulfill the policy and are also not needed to fulfil the policy.
return true;