Search in sources :

Example 1 with DefaultAuthenticationHandlerResolver

use of org.apereo.cas.authentication.handler.DefaultAuthenticationHandlerResolver in project cas by apereo.

the class DefaultAuthenticationEventExecutionPlan method getAuthenticationHandlers.

@Override
@NonNull
public Set<AuthenticationHandler> getAuthenticationHandlers(final AuthenticationTransaction transaction) {
    val handlers = getAuthenticationHandlers();
    LOGGER.debug("Candidate/Registered authentication handlers for this transaction are [{}]", handlers);
    val handlerResolvers = getAuthenticationHandlerResolvers(transaction);
    LOGGER.debug("Authentication handler resolvers for this transaction are [{}]", handlerResolvers);
    val resolvedHandlers = handlerResolvers.stream().filter(r -> r.supports(handlers, transaction)).map(r -> r.resolve(handlers, transaction)).flatMap(Set::stream).collect(Collectors.toCollection(LinkedHashSet::new));
    if (resolvedHandlers.isEmpty()) {
        LOGGER.debug("Authentication handler resolvers produced no candidate authentication handler. Using the default handler resolver instead...");
        val defaultHandlerResolver = new DefaultAuthenticationHandlerResolver();
        if (defaultHandlerResolver.supports(handlers, transaction)) {
            resolvedHandlers.addAll(defaultHandlerResolver.resolve(handlers, transaction));
        }
    }
    if (resolvedHandlers.isEmpty()) {
        throw new AuthenticationException("No authentication handlers could be resolved to support the authentication transaction");
    }
    LOGGER.debug("Resolved and finalized authentication handlers to carry out this authentication transaction are [{}]", handlerResolvers);
    return resolvedHandlers;
}
Also used : lombok.val(lombok.val) IntStream(java.util.stream.IntStream) NonNull(lombok.NonNull) Collection(java.util.Collection) PrincipalResolver(org.apereo.cas.authentication.principal.PrincipalResolver) RequiredArgsConstructor(lombok.RequiredArgsConstructor) lombok.val(lombok.val) Set(java.util.Set) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) DefaultAuthenticationHandlerResolver(org.apereo.cas.authentication.handler.DefaultAuthenticationHandlerResolver) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Map(java.util.Map) CollectionUtils(org.apereo.cas.util.CollectionUtils) AnnotationAwareOrderComparator(org.springframework.core.annotation.AnnotationAwareOrderComparator) LinkedHashSet(java.util.LinkedHashSet) DefaultAuthenticationHandlerResolver(org.apereo.cas.authentication.handler.DefaultAuthenticationHandlerResolver) NonNull(lombok.NonNull)

Example 2 with DefaultAuthenticationHandlerResolver

use of org.apereo.cas.authentication.handler.DefaultAuthenticationHandlerResolver in project cas by apereo.

the class DefaultAuthenticationManagerTests method getAuthenticationExecutionPlan.

private static AuthenticationEventExecutionPlan getAuthenticationExecutionPlan(final Map<AuthenticationHandler, PrincipalResolver> map) {
    val plan = new DefaultAuthenticationEventExecutionPlan();
    plan.registerAuthenticationHandlerWithPrincipalResolver(map);
    plan.registerAuthenticationHandlerResolver(new RegisteredServiceAuthenticationHandlerResolver(mockServicesManager(), new DefaultAuthenticationServiceSelectionPlan(new DefaultAuthenticationServiceSelectionStrategy())));
    plan.registerAuthenticationHandlerResolver(new DefaultAuthenticationHandlerResolver());
    plan.registerAuthenticationPostProcessor((builder, transaction) -> LOGGER.trace("Running authentication post processor"));
    return plan;
}
Also used : lombok.val(lombok.val) RegisteredServiceAuthenticationHandlerResolver(org.apereo.cas.authentication.handler.RegisteredServiceAuthenticationHandlerResolver) DefaultAuthenticationHandlerResolver(org.apereo.cas.authentication.handler.DefaultAuthenticationHandlerResolver)

Example 3 with DefaultAuthenticationHandlerResolver

use of org.apereo.cas.authentication.handler.DefaultAuthenticationHandlerResolver in project cas by apereo.

the class RegisteredServiceAuthenticationHandlerResolverTests method checkAuthenticationHandlerResolution.

@Test
public void checkAuthenticationHandlerResolution() {
    val resolver = new DefaultAuthenticationHandlerResolver();
    val transaction = new DefaultAuthenticationTransactionFactory().newTransaction(RegisteredServiceTestUtils.getService("serviceid2"), RegisteredServiceTestUtils.getCredentialsWithSameUsernameAndPassword("casuser"));
    val handlers = resolver.resolve(this.authenticationHandlers, transaction);
    assertEquals(handlers.size(), this.authenticationHandlers.size());
}
Also used : lombok.val(lombok.val) DefaultAuthenticationHandlerResolver(org.apereo.cas.authentication.handler.DefaultAuthenticationHandlerResolver) DefaultAuthenticationTransactionFactory(org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory) Test(org.junit.jupiter.api.Test)

Example 4 with DefaultAuthenticationHandlerResolver

use of org.apereo.cas.authentication.handler.DefaultAuthenticationHandlerResolver in project cas by apereo.

the class DefaultAuthenticationHandlerResolverTests method verifyOperation.

@Test
public void verifyOperation() {
    val h1 = new SimpleTestUsernamePasswordAuthenticationHandler("h1");
    val h2 = new SimpleTestUsernamePasswordAuthenticationHandler("h2");
    h2.setState(AuthenticationHandlerStates.STANDBY);
    val resolver = new DefaultAuthenticationHandlerResolver();
    assertTrue(resolver.supports(of(h1, h2), mock(AuthenticationTransaction.class)));
    val result = resolver.resolve(of(h1, h2), mock(AuthenticationTransaction.class));
    assertTrue(result.contains(h1));
    assertFalse(result.contains(h2));
    assertEquals(Ordered.LOWEST_PRECEDENCE, resolver.getOrder());
}
Also used : lombok.val(lombok.val) DefaultAuthenticationHandlerResolver(org.apereo.cas.authentication.handler.DefaultAuthenticationHandlerResolver) AuthenticationTransaction(org.apereo.cas.authentication.AuthenticationTransaction) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)4 DefaultAuthenticationHandlerResolver (org.apereo.cas.authentication.handler.DefaultAuthenticationHandlerResolver)4 Test (org.junit.jupiter.api.Test)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 NonNull (lombok.NonNull)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 Slf4j (lombok.extern.slf4j.Slf4j)1 AuthenticationTransaction (org.apereo.cas.authentication.AuthenticationTransaction)1 DefaultAuthenticationTransactionFactory (org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory)1 RegisteredServiceAuthenticationHandlerResolver (org.apereo.cas.authentication.handler.RegisteredServiceAuthenticationHandlerResolver)1 PrincipalResolver (org.apereo.cas.authentication.principal.PrincipalResolver)1 CollectionUtils (org.apereo.cas.util.CollectionUtils)1