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);
}
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();
}
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();
}
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();
}
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;
}
Aggregations