use of org.apereo.cas.authentication.policy.AllAuthenticationPolicy 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.policy.AllAuthenticationPolicy in project cas by apereo.
the class PolicyBasedAuthenticationManagerTests method verifyAuthenticateAllSuccess.
@Test
public void verifyAuthenticateAllSuccess() throws Exception {
final Map<AuthenticationHandler, PrincipalResolver> map = new LinkedHashMap<>();
map.put(newMockHandler(true), null);
map.put(newMockHandler(true), null);
final AuthenticationEventExecutionPlan authenticationExecutionPlan = getAuthenticationExecutionPlan(map);
authenticationExecutionPlan.registerAuthenticationPolicy(new AllAuthenticationPolicy());
final PolicyBasedAuthenticationManager manager = new PolicyBasedAuthenticationManager(authenticationExecutionPlan, false, mock(ApplicationEventPublisher.class));
final Authentication auth = manager.authenticate(transaction);
assertEquals(2, auth.getSuccesses().size());
assertEquals(0, auth.getFailures().size());
assertEquals(2, auth.getCredentials().size());
}
use of org.apereo.cas.authentication.policy.AllAuthenticationPolicy in project cas by apereo.
the class CasCoreAuthenticationPolicyConfiguration method authenticationPolicyExecutionPlanConfigurer.
@ConditionalOnMissingBean(name = "authenticationPolicyExecutionPlanConfigurer")
@Bean
public AuthenticationEventExecutionPlanConfigurer authenticationPolicyExecutionPlanConfigurer() {
return plan -> {
final AuthenticationPolicyProperties police = casProperties.getAuthn().getPolicy();
if (police.getReq().isEnabled()) {
LOGGER.debug("Activating authentication policy [{}]", RequiredHandlerAuthenticationPolicy.class.getSimpleName());
plan.registerAuthenticationPolicy(new RequiredHandlerAuthenticationPolicy(police.getReq().getHandlerName(), police.getReq().isTryAll()));
} else if (police.getAll().isEnabled()) {
LOGGER.debug("Activating authentication policy [{}]", AllAuthenticationPolicy.class.getSimpleName());
plan.registerAuthenticationPolicy(new AllAuthenticationPolicy());
} else if (police.getNotPrevented().isEnabled()) {
LOGGER.debug("Activating authentication policy [{}]", NotPreventedAuthenticationPolicy.class.getSimpleName());
plan.registerAuthenticationPolicy(notPreventedAuthenticationPolicy());
} else if (police.getUniquePrincipal().isEnabled()) {
LOGGER.debug("Activating authentication policy [{}]", UniquePrincipalAuthenticationPolicy.class.getSimpleName());
plan.registerAuthenticationPolicy(new UniquePrincipalAuthenticationPolicy(ticketRegistry.getIfAvailable()));
} else if (!police.getGroovy().isEmpty()) {
LOGGER.debug("Activating authentication policy [{}]", GroovyScriptAuthenticationPolicy.class.getSimpleName());
police.getGroovy().forEach(groovy -> plan.registerAuthenticationPolicy(new GroovyScriptAuthenticationPolicy(resourceLoader, groovy.getScript())));
} else if (!police.getRest().isEmpty()) {
LOGGER.debug("Activating authentication policy [{}]", RestfulAuthenticationPolicy.class.getSimpleName());
police.getRest().forEach(r -> plan.registerAuthenticationPolicy(new RestfulAuthenticationPolicy(new RestTemplate(), r.getEndpoint())));
} else if (police.getAny().isEnabled()) {
LOGGER.debug("Activating authentication policy [{}]", AnyAuthenticationPolicy.class.getSimpleName());
plan.registerAuthenticationPolicy(new AnyAuthenticationPolicy(police.getAny().isTryAll()));
}
};
}
Aggregations