protected Optional<Pair<Collection<Event>, Collection<MultifactorAuthenticationProvider>>> filterEventsByMultifactorAuthenticationProvider(
        final Collection<Event> resolveEvents,
        final Authentication authentication,
        final RegisteredService registeredService,
        final HttpServletRequest request,
        final Service service) throws Throwable {

        LOGGER.debug("Locating multifactor providers to determine support for this authentication sequence");
        val providers = MultifactorAuthenticationUtils.getAvailableMultifactorAuthenticationProviders(
            getConfigurationContext().getApplicationContext());

        if (providers.isEmpty()) {
            LOGGER.debug("No providers are available to honor this request. Moving on...");
            return Optional.of(Pair.of(resolveEvents, new HashSet<>()));
        }

        val providerValues = providers.values();

        providerValues.removeIf(p -> resolveEvents.stream().noneMatch(e -> p.matches(e.getId())));
        resolveEvents.removeIf(e -> providerValues.stream().noneMatch(p -> p.matches(e.getId())));

        LOGGER.debug("Finalized set of resolved events are [{}]", resolveEvents);
        val selectedProvider = getConfigurationContext().getMultifactorAuthenticationProviderSelector().resolve(providerValues,
            registeredService, authentication.getPrincipal());
        val finalEvent = resolveEvents.stream()
            .filter(event -> selectedProvider.matches(event.getId())).findFirst()
            .orElseThrow(() -> new IllegalArgumentException("Unable to locate multifactor authentication provider by id " + selectedProvider.getId()));
        return Optional.of(Pair.of(List.of(finalEvent), List.of(selectedProvider)));
    }
Resolve events internal set. Implementation may filter events from the collection
to only return the one that is appropriate for this request. The default
implementation returns the entire collection.

@param resolveEvents     the resolve events
@param authentication    the authentication
@param registeredService the registered service
@param request           the request
@param context           the request context
@param service           the service
@return the set of resolved events
core/cas-server-core-webflow-mfa-api/src/main/java/org/apereo/cas/web/flow/resolver/impl/SelectiveMultifactorAuthenticationProviderWebflowEventResolver.java