Search in sources :

Example 6 with MultifactorAuthenticationProvider

use of org.apereo.cas.services.MultifactorAuthenticationProvider in project cas by apereo.

the class CasServerProfileRegistrar method locateMultifactorAuthenticationProviderTypesSupported.

private Map<String, String> locateMultifactorAuthenticationProviderTypesSupported() {
    final Function<Class, Object> mapper = c -> {
        try {
            final MultifactorAuthenticationProvider p = MultifactorAuthenticationProvider.class.cast(c.getDeclaredConstructor().newInstance());
            LOGGER.debug("Located supported multifactor authentication provider [{}]", p.getId());
            return p;
        } catch (final Exception e) {
            LOGGER.error(e.getMessage(), e);
            return null;
        }
    };
    final Predicate filter = o -> !VariegatedMultifactorAuthenticationProvider.class.isAssignableFrom(Class.class.cast(o));
    final Collector collector = Collectors.toMap(MultifactorAuthenticationProvider::getId, MultifactorAuthenticationProvider::getFriendlyName);
    return (Map) locateSubtypesByReflection(mapper, collector, AbstractMultifactorAuthenticationProvider.class, filter, CentralAuthenticationService.NAMESPACE);
}
Also used : CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) Setter(lombok.Setter) RequiredArgsConstructor(lombok.RequiredArgsConstructor) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) Reflections(org.reflections.Reflections) Function(java.util.function.Function) AbstractRegisteredService(org.apereo.cas.services.AbstractRegisteredService) Pair(org.apache.commons.lang3.tuple.Pair) Clients(org.pac4j.core.client.Clients) Client(org.pac4j.core.client.Client) Map(java.util.Map) Predicates(com.google.common.base.Predicates) Collector(java.util.stream.Collector) MultifactorAuthenticationUtils(org.apereo.cas.authentication.MultifactorAuthenticationUtils) IndirectClient(org.pac4j.core.client.IndirectClient) VariegatedMultifactorAuthenticationProvider(org.apereo.cas.services.VariegatedMultifactorAuthenticationProvider) ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) LinkedHashSet(java.util.LinkedHashSet) ServicesManager(org.apereo.cas.services.ServicesManager) MultifactorAuthenticationProvider(org.apereo.cas.services.MultifactorAuthenticationProvider) Predicate(java.util.function.Predicate) Set(java.util.Set) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) AbstractMultifactorAuthenticationProvider(org.apereo.cas.authentication.AbstractMultifactorAuthenticationProvider) RegisteredService(org.apereo.cas.services.RegisteredService) ClasspathHelper(org.reflections.util.ClasspathHelper) SubTypesScanner(org.reflections.scanners.SubTypesScanner) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) Modifier(java.lang.reflect.Modifier) ApplicationContextAware(org.springframework.context.ApplicationContextAware) Collector(java.util.stream.Collector) VariegatedMultifactorAuthenticationProvider(org.apereo.cas.services.VariegatedMultifactorAuthenticationProvider) VariegatedMultifactorAuthenticationProvider(org.apereo.cas.services.VariegatedMultifactorAuthenticationProvider) MultifactorAuthenticationProvider(org.apereo.cas.services.MultifactorAuthenticationProvider) AbstractMultifactorAuthenticationProvider(org.apereo.cas.authentication.AbstractMultifactorAuthenticationProvider) Map(java.util.Map) Predicate(java.util.function.Predicate) AbstractMultifactorAuthenticationProvider(org.apereo.cas.authentication.AbstractMultifactorAuthenticationProvider)

Example 7 with MultifactorAuthenticationProvider

use of org.apereo.cas.services.MultifactorAuthenticationProvider in project cas by apereo.

the class DuoAuthenticationHandler method getDuoAuthenticationService.

private DuoSecurityAuthenticationService getDuoAuthenticationService() {
    final RequestContext requestContext = RequestContextHolder.getRequestContext();
    if (requestContext == null) {
        throw new IllegalArgumentException("No request context is held to locate the Duo authentication service");
    }
    final Collection<MultifactorAuthenticationProvider> col = WebUtils.getResolvedMultifactorAuthenticationProviders(requestContext);
    if (col.isEmpty()) {
        throw new IllegalArgumentException("No multifactor providers are found in the current request context");
    }
    final MultifactorAuthenticationProvider pr = col.iterator().next();
    return provider.findProvider(pr.getId(), DuoMultifactorAuthenticationProvider.class).getDuoAuthenticationService();
}
Also used : RequestContext(org.springframework.webflow.execution.RequestContext) MultifactorAuthenticationProvider(org.apereo.cas.services.MultifactorAuthenticationProvider) VariegatedMultifactorAuthenticationProvider(org.apereo.cas.services.VariegatedMultifactorAuthenticationProvider)

Example 8 with MultifactorAuthenticationProvider

use of org.apereo.cas.services.MultifactorAuthenticationProvider in project cas by apereo.

the class DetermineDuoUserAccountAction method doExecute.

@Override
protected Event doExecute(final RequestContext requestContext) {
    final Authentication authentication = WebUtils.getAuthentication(requestContext);
    final Principal p = authentication.getPrincipal();
    final Collection<MultifactorAuthenticationProvider> providers = WebUtils.getResolvedMultifactorAuthenticationProviders(requestContext);
    for (final MultifactorAuthenticationProvider pr : providers) {
        final DuoMultifactorAuthenticationProvider duoProvider = this.provider.findProvider(pr.getId(), DuoMultifactorAuthenticationProvider.class);
        final DuoSecurityAuthenticationService duoAuthenticationService = duoProvider.getDuoAuthenticationService();
        final DuoUserAccount account = duoAuthenticationService.getDuoUserAccount(p.getId());
        if (account.getStatus() == DuoUserAccountAuthStatus.ENROLL && StringUtils.isNotBlank(duoProvider.getRegistrationUrl())) {
            requestContext.getFlowScope().put("duoRegistrationUrl", duoProvider.getRegistrationUrl());
            return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_ENROLL);
        }
    }
    return success();
}
Also used : DuoUserAccount(org.apereo.cas.adaptors.duo.DuoUserAccount) Authentication(org.apereo.cas.authentication.Authentication) DuoMultifactorAuthenticationProvider(org.apereo.cas.adaptors.duo.authn.DuoMultifactorAuthenticationProvider) MultifactorAuthenticationProvider(org.apereo.cas.services.MultifactorAuthenticationProvider) DuoMultifactorAuthenticationProvider(org.apereo.cas.adaptors.duo.authn.DuoMultifactorAuthenticationProvider) VariegatedMultifactorAuthenticationProvider(org.apereo.cas.services.VariegatedMultifactorAuthenticationProvider) DuoSecurityAuthenticationService(org.apereo.cas.adaptors.duo.authn.DuoSecurityAuthenticationService) Principal(org.apereo.cas.authentication.principal.Principal) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport)

Example 9 with MultifactorAuthenticationProvider

use of org.apereo.cas.services.MultifactorAuthenticationProvider in project cas by apereo.

the class PrepareDuoWebLoginFormAction method doExecute.

@Override
protected Event doExecute(final RequestContext requestContext) {
    final Principal p = WebUtils.getAuthentication(requestContext).getPrincipal();
    final DuoCredential c = requestContext.getFlowScope().get(CasWebflowConstants.VAR_ID_CREDENTIAL, DuoCredential.class);
    c.setUsername(p.getId());
    final Collection<MultifactorAuthenticationProvider> providers = WebUtils.getResolvedMultifactorAuthenticationProviders(requestContext);
    providers.forEach(pr -> {
        final DuoSecurityAuthenticationService duoAuthenticationService = provider.findProvider(pr.getId(), DuoMultifactorAuthenticationProvider.class).getDuoAuthenticationService();
        final MutableAttributeMap<Object> viewScope = requestContext.getViewScope();
        viewScope.put("sigRequest", duoAuthenticationService.signRequestToken(p.getId()));
        viewScope.put("apiHost", duoAuthenticationService.getApiHost());
        viewScope.put("commandName", "credential");
        viewScope.put("principal", p);
    });
    return success();
}
Also used : DuoCredential(org.apereo.cas.adaptors.duo.authn.DuoCredential) DuoMultifactorAuthenticationProvider(org.apereo.cas.adaptors.duo.authn.DuoMultifactorAuthenticationProvider) MultifactorAuthenticationProvider(org.apereo.cas.services.MultifactorAuthenticationProvider) DuoMultifactorAuthenticationProvider(org.apereo.cas.adaptors.duo.authn.DuoMultifactorAuthenticationProvider) VariegatedMultifactorAuthenticationProvider(org.apereo.cas.services.VariegatedMultifactorAuthenticationProvider) DuoSecurityAuthenticationService(org.apereo.cas.adaptors.duo.authn.DuoSecurityAuthenticationService) Principal(org.apereo.cas.authentication.principal.Principal)

Example 10 with MultifactorAuthenticationProvider

use of org.apereo.cas.services.MultifactorAuthenticationProvider in project cas by apereo.

the class RankedMultifactorAuthenticationProviderSelector method resolve.

@Override
public MultifactorAuthenticationProvider resolve(final Collection<MultifactorAuthenticationProvider> providers, final RegisteredService service, final Principal principal) {
    final List<MultifactorAuthenticationProvider> sorted = new ArrayList<>(providers);
    if (sorted.isEmpty()) {
        throw new IllegalArgumentException("List of candidate multifactor authentication providers is empty");
    }
    OrderComparator.sort(sorted);
    final MultifactorAuthenticationProvider provider = sorted.get(sorted.size() - 1);
    LOGGER.debug("Selected the provider [{}] for service [{}] out of [{}] providers", provider, service, providers.size());
    return provider;
}
Also used : ArrayList(java.util.ArrayList) MultifactorAuthenticationProvider(org.apereo.cas.services.MultifactorAuthenticationProvider)

Aggregations

MultifactorAuthenticationProvider (org.apereo.cas.services.MultifactorAuthenticationProvider)35 Authentication (org.apereo.cas.authentication.Authentication)21 RegisteredService (org.apereo.cas.services.RegisteredService)20 Event (org.springframework.webflow.execution.Event)20 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)14 Map (java.util.Map)9 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)8 Principal (org.apereo.cas.authentication.principal.Principal)8 Set (java.util.Set)7 ServicesManager (org.apereo.cas.services.ServicesManager)7 RequestContext (org.springframework.webflow.execution.RequestContext)7 AuthenticationServiceSelectionPlan (org.apereo.cas.authentication.AuthenticationServiceSelectionPlan)6 AuthenticationSystemSupport (org.apereo.cas.authentication.AuthenticationSystemSupport)6 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)6 MultifactorAuthenticationProviderSelector (org.apereo.cas.services.MultifactorAuthenticationProviderSelector)6 TicketRegistrySupport (org.apereo.cas.ticket.registry.TicketRegistrySupport)6 BaseMultifactorAuthenticationProviderEventResolver (org.apereo.cas.web.flow.authentication.BaseMultifactorAuthenticationProviderEventResolver)6 WebUtils (org.apereo.cas.web.support.WebUtils)6 CookieGenerator (org.springframework.web.util.CookieGenerator)6 Collection (java.util.Collection)5