Search in sources :

Example 1 with PrincipalResolver

use of org.apereo.cas.authentication.principal.PrincipalResolver in project cas by apereo.

the class PolicyBasedAuthenticationManagerTests method verifyAuthenticateAnySuccess.

@Test
public void verifyAuthenticateAnySuccess() throws Exception {
    final Map<AuthenticationHandler, PrincipalResolver> map = new HashMap<>();
    map.put(newMockHandler(true), null);
    map.put(newMockHandler(false), null);
    final AuthenticationEventExecutionPlan authenticationExecutionPlan = getAuthenticationExecutionPlan(map);
    authenticationExecutionPlan.registerAuthenticationPolicy(new AnyAuthenticationPolicy());
    final PolicyBasedAuthenticationManager manager = new PolicyBasedAuthenticationManager(authenticationExecutionPlan, false, mock(ApplicationEventPublisher.class));
    final Authentication auth = manager.authenticate(transaction);
    assertEquals(1, auth.getSuccesses().size());
    assertEquals(2, auth.getCredentials().size());
}
Also used : AnyAuthenticationPolicy(org.apereo.cas.authentication.policy.AnyAuthenticationPolicy) PrincipalResolver(org.apereo.cas.authentication.principal.PrincipalResolver) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) Test(org.junit.Test)

Example 2 with PrincipalResolver

use of org.apereo.cas.authentication.principal.PrincipalResolver in project cas by apereo.

the class PolicyBasedAuthenticationManagerTests method verifyAuthenticateRequiredHandlerTryAllSuccess.

@Test
public void verifyAuthenticateRequiredHandlerTryAllSuccess() throws Exception {
    final Map<AuthenticationHandler, PrincipalResolver> map = new LinkedHashMap<>();
    map.put(newMockHandler(HANDLER_A, true), null);
    map.put(newMockHandler(HANDLER_B, false), null);
    final AuthenticationEventExecutionPlan authenticationExecutionPlan = getAuthenticationExecutionPlan(map);
    authenticationExecutionPlan.registerAuthenticationPolicy(new RequiredHandlerAuthenticationPolicy(HANDLER_A, true));
    final PolicyBasedAuthenticationManager manager = new PolicyBasedAuthenticationManager(authenticationExecutionPlan, false, mock(ApplicationEventPublisher.class));
    final Authentication auth = manager.authenticate(transaction);
    assertEquals(1, auth.getSuccesses().size());
    assertEquals(1, auth.getFailures().size());
    assertEquals(2, auth.getCredentials().size());
}
Also used : PrincipalResolver(org.apereo.cas.authentication.principal.PrincipalResolver) RequiredHandlerAuthenticationPolicy(org.apereo.cas.authentication.policy.RequiredHandlerAuthenticationPolicy) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 3 with PrincipalResolver

use of org.apereo.cas.authentication.principal.PrincipalResolver in project cas by apereo.

the class PolicyBasedAuthenticationManagerTests method verifyAuthenticateRequiredHandlerSuccess.

@Test
public void verifyAuthenticateRequiredHandlerSuccess() throws Exception {
    final Map<AuthenticationHandler, PrincipalResolver> map = new LinkedHashMap<>();
    map.put(newMockHandler(HANDLER_A, true), null);
    map.put(newMockHandler(HANDLER_B, false), null);
    final AuthenticationEventExecutionPlan authenticationExecutionPlan = getAuthenticationExecutionPlan(map);
    authenticationExecutionPlan.registerAuthenticationPolicy(new RequiredHandlerAuthenticationPolicy(HANDLER_A));
    final PolicyBasedAuthenticationManager manager = new PolicyBasedAuthenticationManager(authenticationExecutionPlan, false, mock(ApplicationEventPublisher.class));
    final Authentication auth = manager.authenticate(transaction);
    assertEquals(1, auth.getSuccesses().size());
    assertEquals(2, auth.getCredentials().size());
}
Also used : PrincipalResolver(org.apereo.cas.authentication.principal.PrincipalResolver) RequiredHandlerAuthenticationPolicy(org.apereo.cas.authentication.policy.RequiredHandlerAuthenticationPolicy) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 4 with PrincipalResolver

use of org.apereo.cas.authentication.principal.PrincipalResolver in project cas by apereo.

the class PolicyBasedAuthenticationManagerTests method verifyAuthenticateAllFailure.

@Test
public void verifyAuthenticateAllFailure() throws Exception {
    final Map<AuthenticationHandler, PrincipalResolver> map = new LinkedHashMap<>();
    map.put(newMockHandler(false), null);
    map.put(newMockHandler(false), null);
    final AuthenticationEventExecutionPlan authenticationExecutionPlan = getAuthenticationExecutionPlan(map);
    authenticationExecutionPlan.registerAuthenticationPolicy(new AllAuthenticationPolicy());
    final PolicyBasedAuthenticationManager manager = new PolicyBasedAuthenticationManager(authenticationExecutionPlan, false, mock(ApplicationEventPublisher.class));
    this.thrown.expect(AuthenticationException.class);
    manager.authenticate(transaction);
    throw new AssertionError("Should have thrown authentication exception");
}
Also used : PrincipalResolver(org.apereo.cas.authentication.principal.PrincipalResolver) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) LinkedHashMap(java.util.LinkedHashMap) AllAuthenticationPolicy(org.apereo.cas.authentication.policy.AllAuthenticationPolicy) Test(org.junit.Test)

Example 5 with PrincipalResolver

use of org.apereo.cas.authentication.principal.PrincipalResolver in project cas by apereo.

the class PolicyBasedAuthenticationManagerTests method verifyAuthenticateRequiredHandlerFailure.

@Test
public void verifyAuthenticateRequiredHandlerFailure() throws Exception {
    final Map<AuthenticationHandler, PrincipalResolver> map = new LinkedHashMap<>();
    map.put(newMockHandler(HANDLER_A, true), null);
    map.put(newMockHandler(HANDLER_B, false), null);
    final AuthenticationEventExecutionPlan authenticationExecutionPlan = getAuthenticationExecutionPlan(map);
    authenticationExecutionPlan.registerAuthenticationPolicy(new RequiredHandlerAuthenticationPolicy(HANDLER_B));
    final PolicyBasedAuthenticationManager manager = new PolicyBasedAuthenticationManager(authenticationExecutionPlan, false, mock(ApplicationEventPublisher.class));
    this.thrown.expect(AuthenticationException.class);
    manager.authenticate(transaction);
    throw new AssertionError("Should have thrown AuthenticationException");
}
Also used : PrincipalResolver(org.apereo.cas.authentication.principal.PrincipalResolver) RequiredHandlerAuthenticationPolicy(org.apereo.cas.authentication.policy.RequiredHandlerAuthenticationPolicy) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

PrincipalResolver (org.apereo.cas.authentication.principal.PrincipalResolver)10 LinkedHashMap (java.util.LinkedHashMap)8 Test (org.junit.Test)8 ApplicationEventPublisher (org.springframework.context.ApplicationEventPublisher)8 AnyAuthenticationPolicy (org.apereo.cas.authentication.policy.AnyAuthenticationPolicy)3 RequiredHandlerAuthenticationPolicy (org.apereo.cas.authentication.policy.RequiredHandlerAuthenticationPolicy)3 HashMap (java.util.HashMap)2 AllAuthenticationPolicy (org.apereo.cas.authentication.policy.AllAuthenticationPolicy)2 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 NonNull (lombok.NonNull)1 lombok.val (lombok.val)1 UnresolvedPrincipalException (org.apereo.cas.authentication.exceptions.UnresolvedPrincipalException)1 MergingPersonAttributeDaoImpl (org.apereo.services.persondir.support.MergingPersonAttributeDaoImpl)1