Search in sources :

Example 1 with SingleSignOnParticipationRequest

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;
}
Also used : lombok.val(lombok.val) SneakyThrows(lombok.SneakyThrows) lombok.val(lombok.val) AuthenticationServiceSelectionPlan(org.apereo.cas.authentication.AuthenticationServiceSelectionPlan) TicketRegistrySupport(org.apereo.cas.ticket.registry.TicketRegistrySupport) AuthenticationAwareTicket(org.apereo.cas.ticket.AuthenticationAwareTicket) AuthenticationEventExecutionPlan(org.apereo.cas.authentication.AuthenticationEventExecutionPlan) Collectors(java.util.stream.Collectors) AuthenticationCredentialsThreadLocalBinder(org.apereo.cas.authentication.AuthenticationCredentialsThreadLocalBinder) Slf4j(lombok.extern.slf4j.Slf4j) AuthenticationHandler(org.apereo.cas.authentication.AuthenticationHandler) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) CollectionUtils(org.apereo.cas.util.CollectionUtils) BaseSingleSignOnParticipationStrategy(org.apereo.cas.web.flow.BaseSingleSignOnParticipationStrategy) Optional(java.util.Optional) ServicesManager(org.apereo.cas.services.ServicesManager) SingleSignOnParticipationRequest(org.apereo.cas.web.flow.SingleSignOnParticipationRequest) AuthenticationAwareTicket(org.apereo.cas.ticket.AuthenticationAwareTicket) SneakyThrows(lombok.SneakyThrows)

Aggregations

Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 SneakyThrows (lombok.SneakyThrows)1 Slf4j (lombok.extern.slf4j.Slf4j)1 lombok.val (lombok.val)1 AuthenticationCredentialsThreadLocalBinder (org.apereo.cas.authentication.AuthenticationCredentialsThreadLocalBinder)1 AuthenticationEventExecutionPlan (org.apereo.cas.authentication.AuthenticationEventExecutionPlan)1 AuthenticationHandler (org.apereo.cas.authentication.AuthenticationHandler)1 AuthenticationServiceSelectionPlan (org.apereo.cas.authentication.AuthenticationServiceSelectionPlan)1 ServicesManager (org.apereo.cas.services.ServicesManager)1 AuthenticationAwareTicket (org.apereo.cas.ticket.AuthenticationAwareTicket)1 TicketRegistrySupport (org.apereo.cas.ticket.registry.TicketRegistrySupport)1 CollectionUtils (org.apereo.cas.util.CollectionUtils)1 BaseSingleSignOnParticipationStrategy (org.apereo.cas.web.flow.BaseSingleSignOnParticipationStrategy)1 SingleSignOnParticipationRequest (org.apereo.cas.web.flow.SingleSignOnParticipationRequest)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1