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());
}
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());
}
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());
}
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");
}
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");
}
Aggregations