use of org.apereo.cas.web.flow.SingleSignOnParticipationRequest in project cas by apereo.
the class RegisteredServiceAuthenticationPolicySingleSignOnParticipationStrategy method isParticipating.
@Override
@SneakyThrows
public boolean isParticipating(final SingleSignOnParticipationRequest ssoRequest) {
val registeredService = getRegisteredService(ssoRequest);
if (registeredService == null) {
return true;
}
val authenticationPolicy = registeredService.getAuthenticationPolicy();
if (authenticationPolicy == null) {
return true;
}
val ticketGrantingTicketId = getTicketGrantingTicketId(ssoRequest);
if (ticketGrantingTicketId.isEmpty()) {
return true;
}
val ca = AuthenticationCredentialsThreadLocalBinder.getCurrentAuthentication();
try {
val authentication = getTicketState(ssoRequest).map(AuthenticationAwareTicket.class::cast).map(AuthenticationAwareTicket::getAuthentication).orElseThrow();
AuthenticationCredentialsThreadLocalBinder.bindCurrent(authentication);
if (authentication != null) {
val successfulHandlerNames = CollectionUtils.toCollection(authentication.getAttributes().get(AuthenticationHandler.SUCCESSFUL_AUTHENTICATION_HANDLERS));
val assertedHandlers = authenticationEventExecutionPlan.getAuthenticationHandlers().stream().filter(handler -> successfulHandlerNames.contains(handler.getName())).collect(Collectors.toSet());
LOGGER.debug("Asserted authentication handlers are [{}]", assertedHandlers);
val criteria = authenticationPolicy.getCriteria();
if (criteria != null) {
val policy = criteria.toAuthenticationPolicy(registeredService);
val result = policy.isSatisfiedBy(authentication, assertedHandlers, applicationContext, Optional.empty());
return result.isSuccess();
}
}
} finally {
AuthenticationCredentialsThreadLocalBinder.bindCurrent(ca);
}
return true;
}
Aggregations