@Override
    public Set<Event> resolveInternal(final RequestContext context) throws Throwable {
        val tgt = WebUtils.getTicketGrantingTicketId(context);
        val registeredService = WebUtils.getRegisteredService(context);
        val service = WebUtils.getService(context);

        if (registeredService == null) {
            LOGGER.debug("No service is available to determine event for principal");
            return resumeFlow(context);
        }

        if (StringUtils.isBlank(tgt)) {
            LOGGER.trace("Ticket-granting ticket is blank; proceed with flow normally.");
            return resumeFlow(context);
        }
        val authentication = getConfigurationContext().getTicketRegistrySupport().getAuthenticationFrom(tgt);
        if (authentication == null) {
            LOGGER.trace("Ticket-granting ticket has no authentication and is blank; proceed with flow normally.");
            return resumeFlow(context);
        }

        val credentials = getConfigurationContext().getCasWebflowCredentialProvider().extract(context);
        val builder = getConfigurationContext().getAuthenticationSystemSupport()
            .establishAuthenticationContextFromInitial(authentication, credentials.toArray(Credential.EMPTY_CREDENTIALS_ARRAY));

        LOGGER.trace("Recording and tracking initial authentication results in the request context");
        WebUtils.putAuthenticationResultBuilder(builder, context);
        WebUtils.putAuthentication(authentication, context);

        val ssoRequest = SingleSignOnParticipationRequest.builder()
            .requestContext(context)
            .build();
        if (singleSignOnParticipationStrategy.supports(ssoRequest) && !singleSignOnParticipationStrategy.isParticipating(ssoRequest)) {
            LOGGER.debug("Cannot proceed with existing authenticated session for [{}] since the single sign-on participation "
                + "strategy for this request could now allow participation in the current session.", authentication);
            return resumeFlow(context);
        }

        val event = casDelegatingWebflowEventResolver.resolveSingle(context);
        if (event == null) {
            LOGGER.trace("Request does not indicate a requirement for authentication policy; proceed with flow normally.");
            return resumeFlow(context);
        }

        val id = event.getId();
        LOGGER.trace("Resolved event from the initial authentication leg is [{}]", id);

        if (getOperableTransitions().contains(id)) {
            LOGGER.trace("Returning webflow event as [{}]", id);
            return CollectionUtils.wrapSet(event);
        }

        LOGGER.trace("Validating authentication context for event [{}] and service [{}]", id, registeredService);
        val result = authenticationContextValidator.validate(authentication, id, Optional.of(registeredService));
        val validatedProvider = result.getProvider();

        if (result.isSuccess()) {
            if (registeredService.getMultifactorAuthenticationPolicy().isForceExecution() && validatedProvider.isPresent()) {
                val provider = validatedProvider.get();
                LOGGER.trace("Multifactor authentication policy for [{}] is set to force execution for [{}]", registeredService, provider);
                return buildEventForMultifactorProvider(context, service, registeredService, authentication, id, provider);
            }
            LOGGER.debug("Authentication context is successfully validated by [{}] for service [{}]", id, registeredService);
            return resumeFlow(context);
        }

        if (validatedProvider.isPresent()) {
            val provider = validatedProvider.get();
            return buildEventForMultifactorProvider(context, service, registeredService, authentication, id, provider);
        }

        LOGGER.warn("The authentication context cannot be satisfied and the requested event [{}] is unrecognized", id);
        return CollectionUtils.wrapSet(new Event(this, CasWebflowConstants.TRANSITION_ID_ERROR));
    }
This is {@link RankedMultifactorAuthenticationProviderWebflowEventResolver}.

@author Misagh Moayyed
@since 5.0.0
core/cas-server-core-webflow-mfa-api/src/main/java/org/apereo/cas/web/flow/resolver/impl/RankedMultifactorAuthenticationProviderWebflowEventResolver.java