Search in sources :

Example 1 with AllAuthenticationPolicy

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");
}
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 2 with AllAuthenticationPolicy

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());
}
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 3 with AllAuthenticationPolicy

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()));
        }
    };
}
Also used : CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) AuthenticationPolicy(org.apereo.cas.authentication.AuthenticationPolicy) GeoLocationService(org.apereo.cas.authentication.adaptive.geo.GeoLocationService) Autowired(org.springframework.beans.factory.annotation.Autowired) ObjectProvider(org.springframework.beans.factory.ObjectProvider) TicketRegistry(org.apereo.cas.ticket.registry.TicketRegistry) NotPreventedAuthenticationPolicy(org.apereo.cas.authentication.policy.NotPreventedAuthenticationPolicy) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) Qualifier(org.springframework.beans.factory.annotation.Qualifier) DefaultAdaptiveAuthenticationPolicy(org.apereo.cas.authentication.adaptive.DefaultAdaptiveAuthenticationPolicy) RestTemplate(org.springframework.web.client.RestTemplate) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) UniquePrincipalAuthenticationPolicy(org.apereo.cas.authentication.policy.UniquePrincipalAuthenticationPolicy) ResourceLoader(org.springframework.core.io.ResourceLoader) RequiredHandlerAuthenticationPolicyFactory(org.apereo.cas.authentication.policy.RequiredHandlerAuthenticationPolicyFactory) AnyAuthenticationPolicy(org.apereo.cas.authentication.policy.AnyAuthenticationPolicy) GroovyScriptAuthenticationPolicy(org.apereo.cas.authentication.policy.GroovyScriptAuthenticationPolicy) AuthenticationPolicyProperties(org.apereo.cas.configuration.model.core.authentication.AuthenticationPolicyProperties) ApplicationContext(org.springframework.context.ApplicationContext) AllAuthenticationPolicy(org.apereo.cas.authentication.policy.AllAuthenticationPolicy) Configuration(org.springframework.context.annotation.Configuration) Slf4j(lombok.extern.slf4j.Slf4j) ContextualAuthenticationPolicyFactory(org.apereo.cas.authentication.ContextualAuthenticationPolicyFactory) RequiredHandlerAuthenticationPolicy(org.apereo.cas.authentication.policy.RequiredHandlerAuthenticationPolicy) Bean(org.springframework.context.annotation.Bean) AuthenticationEventExecutionPlanConfigurer(org.apereo.cas.authentication.AuthenticationEventExecutionPlanConfigurer) RestfulAuthenticationPolicy(org.apereo.cas.authentication.policy.RestfulAuthenticationPolicy) AdaptiveAuthenticationPolicy(org.apereo.cas.authentication.adaptive.AdaptiveAuthenticationPolicy) AnyAuthenticationPolicy(org.apereo.cas.authentication.policy.AnyAuthenticationPolicy) RequiredHandlerAuthenticationPolicy(org.apereo.cas.authentication.policy.RequiredHandlerAuthenticationPolicy) RestTemplate(org.springframework.web.client.RestTemplate) GroovyScriptAuthenticationPolicy(org.apereo.cas.authentication.policy.GroovyScriptAuthenticationPolicy) RestfulAuthenticationPolicy(org.apereo.cas.authentication.policy.RestfulAuthenticationPolicy) AuthenticationPolicyProperties(org.apereo.cas.configuration.model.core.authentication.AuthenticationPolicyProperties) UniquePrincipalAuthenticationPolicy(org.apereo.cas.authentication.policy.UniquePrincipalAuthenticationPolicy) AllAuthenticationPolicy(org.apereo.cas.authentication.policy.AllAuthenticationPolicy) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

AllAuthenticationPolicy (org.apereo.cas.authentication.policy.AllAuthenticationPolicy)3 LinkedHashMap (java.util.LinkedHashMap)2 PrincipalResolver (org.apereo.cas.authentication.principal.PrincipalResolver)2 Test (org.junit.Test)2 ApplicationEventPublisher (org.springframework.context.ApplicationEventPublisher)2 Slf4j (lombok.extern.slf4j.Slf4j)1 AuthenticationEventExecutionPlanConfigurer (org.apereo.cas.authentication.AuthenticationEventExecutionPlanConfigurer)1 AuthenticationPolicy (org.apereo.cas.authentication.AuthenticationPolicy)1 ContextualAuthenticationPolicyFactory (org.apereo.cas.authentication.ContextualAuthenticationPolicyFactory)1 AdaptiveAuthenticationPolicy (org.apereo.cas.authentication.adaptive.AdaptiveAuthenticationPolicy)1 DefaultAdaptiveAuthenticationPolicy (org.apereo.cas.authentication.adaptive.DefaultAdaptiveAuthenticationPolicy)1 GeoLocationService (org.apereo.cas.authentication.adaptive.geo.GeoLocationService)1 AnyAuthenticationPolicy (org.apereo.cas.authentication.policy.AnyAuthenticationPolicy)1 GroovyScriptAuthenticationPolicy (org.apereo.cas.authentication.policy.GroovyScriptAuthenticationPolicy)1 NotPreventedAuthenticationPolicy (org.apereo.cas.authentication.policy.NotPreventedAuthenticationPolicy)1 RequiredHandlerAuthenticationPolicy (org.apereo.cas.authentication.policy.RequiredHandlerAuthenticationPolicy)1 RequiredHandlerAuthenticationPolicyFactory (org.apereo.cas.authentication.policy.RequiredHandlerAuthenticationPolicyFactory)1 RestfulAuthenticationPolicy (org.apereo.cas.authentication.policy.RestfulAuthenticationPolicy)1 UniquePrincipalAuthenticationPolicy (org.apereo.cas.authentication.policy.UniquePrincipalAuthenticationPolicy)1 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)1