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