Search in sources :

Example 1 with RequiredHandlerAuthenticationPolicy

use of org.apereo.cas.authentication.policy.RequiredHandlerAuthenticationPolicy 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 2 with RequiredHandlerAuthenticationPolicy

use of org.apereo.cas.authentication.policy.RequiredHandlerAuthenticationPolicy 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 3 with RequiredHandlerAuthenticationPolicy

use of org.apereo.cas.authentication.policy.RequiredHandlerAuthenticationPolicy 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)

Example 4 with RequiredHandlerAuthenticationPolicy

use of org.apereo.cas.authentication.policy.RequiredHandlerAuthenticationPolicy 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

RequiredHandlerAuthenticationPolicy (org.apereo.cas.authentication.policy.RequiredHandlerAuthenticationPolicy)4 LinkedHashMap (java.util.LinkedHashMap)3 PrincipalResolver (org.apereo.cas.authentication.principal.PrincipalResolver)3 Test (org.junit.Test)3 ApplicationEventPublisher (org.springframework.context.ApplicationEventPublisher)3 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 AllAuthenticationPolicy (org.apereo.cas.authentication.policy.AllAuthenticationPolicy)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 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