use of org.apereo.cas.authentication.ChainingMultifactorAuthenticationProvider in project cas by apereo.
the class PrepareMultifactorProviderSelectionAction method doExecute.
@Override
protected Event doExecute(final RequestContext requestContext) {
val attributes = requestContext.getCurrentEvent().getAttributes();
val registeredService = (RegisteredService) attributes.get(RegisteredService.class.getName());
WebUtils.putRegisteredService(requestContext, registeredService);
val mfaProvider = (ChainingMultifactorAuthenticationProvider) attributes.get(MultifactorAuthenticationProvider.class.getName());
val authn = WebUtils.getAuthentication(requestContext);
val request = WebUtils.getHttpServletRequestFromExternalWebflowContext(requestContext);
val mfaProviders = mfaProvider.getMultifactorAuthenticationProviders().stream().filter(p -> p.isAvailable(registeredService) && p.getBypassEvaluator().shouldMultifactorAuthenticationProviderExecute(authn, registeredService, p, request)).map(MultifactorAuthenticationProvider::getId).collect(Collectors.toList());
WebUtils.putSelectableMultifactorAuthenticationProviders(requestContext, mfaProviders);
return null;
}
use of org.apereo.cas.authentication.ChainingMultifactorAuthenticationProvider in project cas by apereo.
the class CompositeProviderSelectionMultifactorWebflowEventResolver method filterEventsByMultifactorAuthenticationProvider.
@Override
protected Optional<Pair<Collection<Event>, Collection<MultifactorAuthenticationProvider>>> filterEventsByMultifactorAuthenticationProvider(final Collection<Event> resolveEvents, final Authentication authentication, final RegisteredService registeredService, final HttpServletRequest request) {
val composite = resolveEvents.stream().allMatch(event -> event.getId().equalsIgnoreCase(ChainingMultifactorAuthenticationProvider.DEFAULT_IDENTIFIER));
if (!composite) {
return super.filterEventsByMultifactorAuthenticationProvider(resolveEvents, authentication, registeredService, request);
}
val event = resolveEvents.iterator().next();
val chainingProvider = (ChainingMultifactorAuthenticationProvider) event.getAttributes().get(MultifactorAuthenticationProvider.class.getName());
return chainingProvider.getMultifactorAuthenticationProviders().stream().map(provider -> getConfigurationContext().getAuthenticationContextValidator().validate(authentication, provider.getId(), Optional.ofNullable(registeredService))).filter(MultifactorAuthenticationContextValidationResult::isSuccess).map(result -> {
val validatedProvider = result.getProvider().orElseThrow();
val validatedEvent = CollectionUtils.wrapCollection(new Event(this, validatedProvider.getId(), event.getAttributes()));
val validatedProviders = CollectionUtils.wrapCollection(validatedProvider);
return Optional.of(Pair.of(validatedEvent, validatedProviders));
}).findAny().orElseGet(() -> {
val activeProviders = chainingProvider.getMultifactorAuthenticationProviders().stream().filter(provider -> {
val bypass = provider.getBypassEvaluator();
return bypass == null || bypass.shouldMultifactorAuthenticationProviderExecute(authentication, registeredService, provider, request);
}).collect(Collectors.toList());
LOGGER.debug("Finalized set of resolved events are [{}] with providers [{}]", resolveEvents, activeProviders);
return activeProviders.isEmpty() ? Optional.empty() : Optional.of(Pair.of(resolveEvents, activeProviders));
});
}
Aggregations