Search in sources :

Example 1 with AuthenticationEventExecutionPlanConfigurer

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

Example 2 with AuthenticationEventExecutionPlanConfigurer

use of org.apereo.cas.authentication.AuthenticationEventExecutionPlanConfigurer in project cas by apereo.

the class WsFedAuthenticationEventExecutionPlanConfiguration method wsfedAuthenticationEventExecutionPlanConfigurer.

@ConditionalOnMissingBean(name = "wsfedAuthenticationEventExecutionPlanConfigurer")
@Bean
public AuthenticationEventExecutionPlanConfigurer wsfedAuthenticationEventExecutionPlanConfigurer() {
    return plan -> casProperties.getAuthn().getWsfed().stream().filter(wsfed -> StringUtils.isNotBlank(wsfed.getIdentityProviderUrl()) && StringUtils.isNotBlank(wsfed.getIdentityProviderIdentifier())).forEach(wsfed -> {
        final AuthenticationHandler handler = new WsFederationAuthenticationHandler(wsfed.getName(), servicesManager, adfsPrincipalFactory());
        if (!wsfed.isAttributeResolverEnabled()) {
            plan.registerAuthenticationHandler(handler);
        } else {
            final WsFederationCredentialsToPrincipalResolver r = new WsFederationCredentialsToPrincipalResolver(attributeRepository, adfsPrincipalFactory(), wsfed.getPrincipal().isReturnNull(), wsfed.getPrincipal().getPrincipalAttribute(), getWsFederationConfiguration(wsfed));
            plan.registerAuthenticationHandlerWithPrincipalResolver(handler, r);
        }
    });
}
Also used : CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) WsFederationAttributeMutator(org.apereo.cas.support.wsfederation.WsFederationAttributeMutator) Autowired(org.springframework.beans.factory.annotation.Autowired) Beans(org.apereo.cas.configuration.support.Beans) StringUtils(org.apache.commons.lang3.StringUtils) IPersonAttributeDao(org.apereo.services.persondir.IPersonAttributeDao) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) HashSet(java.util.HashSet) AuthenticationHandler(org.apereo.cas.authentication.AuthenticationHandler) PrincipalFactory(org.apereo.cas.authentication.principal.PrincipalFactory) WsFederationCookieCipherExecutor(org.apereo.cas.support.wsfederation.web.WsFederationCookieCipherExecutor) DefaultCasCookieValueManager(org.apereo.cas.web.support.DefaultCasCookieValueManager) EncryptionJwtSigningJwtCryptographyProperties(org.apereo.cas.configuration.model.core.util.EncryptionJwtSigningJwtCryptographyProperties) WsFederationAuthenticationHandler(org.apereo.cas.support.wsfederation.authentication.handler.support.WsFederationAuthenticationHandler) WsFederationDelegatedCookieProperties(org.apereo.cas.configuration.model.support.wsfed.WsFederationDelegatedCookieProperties) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) Qualifier(org.springframework.beans.factory.annotation.Qualifier) WsFederationCookieGenerator(org.apereo.cas.support.wsfederation.web.WsFederationCookieGenerator) WsFederationConfiguration(org.apereo.cas.support.wsfederation.WsFederationConfiguration) ServicesManager(org.apereo.cas.services.ServicesManager) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ResourceLoader(org.springframework.core.io.ResourceLoader) WsFederationDelegationProperties(org.apereo.cas.configuration.model.support.wsfed.WsFederationDelegationProperties) Collection(java.util.Collection) CipherExecutor(org.apereo.cas.CipherExecutor) Configuration(org.springframework.context.annotation.Configuration) Slf4j(lombok.extern.slf4j.Slf4j) WsFederationCredentialsToPrincipalResolver(org.apereo.cas.support.wsfederation.authentication.principal.WsFederationCredentialsToPrincipalResolver) Bean(org.springframework.context.annotation.Bean) AuthenticationEventExecutionPlanConfigurer(org.apereo.cas.authentication.AuthenticationEventExecutionPlanConfigurer) DefaultPrincipalFactory(org.apereo.cas.authentication.principal.DefaultPrincipalFactory) AuthenticationHandler(org.apereo.cas.authentication.AuthenticationHandler) WsFederationAuthenticationHandler(org.apereo.cas.support.wsfederation.authentication.handler.support.WsFederationAuthenticationHandler) WsFederationAuthenticationHandler(org.apereo.cas.support.wsfederation.authentication.handler.support.WsFederationAuthenticationHandler) WsFederationCredentialsToPrincipalResolver(org.apereo.cas.support.wsfederation.authentication.principal.WsFederationCredentialsToPrincipalResolver) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

Slf4j (lombok.extern.slf4j.Slf4j)2 AuthenticationEventExecutionPlanConfigurer (org.apereo.cas.authentication.AuthenticationEventExecutionPlanConfigurer)2 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Qualifier (org.springframework.beans.factory.annotation.Qualifier)2 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)2 EnableConfigurationProperties (org.springframework.boot.context.properties.EnableConfigurationProperties)2 Bean (org.springframework.context.annotation.Bean)2 Configuration (org.springframework.context.annotation.Configuration)2 ResourceLoader (org.springframework.core.io.ResourceLoader)2 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 StringUtils (org.apache.commons.lang3.StringUtils)1 CipherExecutor (org.apereo.cas.CipherExecutor)1 AuthenticationHandler (org.apereo.cas.authentication.AuthenticationHandler)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