@Override
    public Optional<MultifactorAuthenticationProvider> isActivated(final Authentication authentication,
                                                                   final RegisteredService registeredService,
                                                                   final HttpServletRequest httpServletRequest,
                                                                   final HttpServletResponse response,
                                                                   final Service service) throws Throwable {

        val multifactorMap = casProperties.getAuthn().getAdaptive().getPolicy().getRequireMultifactor();

        if (authentication == null) {
            LOGGER.trace("No authentication is available to determine event for principal");
            return Optional.empty();
        }

        if (multifactorMap == null || multifactorMap.isEmpty()) {
            LOGGER.trace("Adaptive authentication is not configured to require multifactor authentication");
            return Optional.empty();
        }

        val providerMap = MultifactorAuthenticationUtils.getAvailableMultifactorAuthenticationProviders(this.applicationContext);
        if (providerMap.isEmpty()) {
            LOGGER.error("No multifactor authentication providers are available in the application context");
            throw new AuthenticationException(new MultifactorAuthenticationProviderAbsentException());
        }

        val clientInfo = ClientInfoHolder.getClientInfo();
        val clientIp = clientInfo.getClientIpAddress();
        LOGGER.debug("Located client IP address as [{}]", clientIp);

        val agent = HttpRequestUtils.getHttpServletRequestUserAgent(httpServletRequest);

        val entries = multifactorMap.entrySet();
        for (final Map.Entry entry : entries) {
            val mfaMethod = entry.getKey().toString();
            val pattern = entry.getValue().toString();

            val providerFound = MultifactorAuthenticationUtils.resolveProvider(providerMap, mfaMethod);

            if (providerFound.isEmpty()) {
                LOGGER.error("Adaptive authentication is configured to require [{}] for [{}], yet [{}] is absent in the configuration.",
                    mfaMethod, pattern, mfaMethod);
                throw new AuthenticationException();
            }

            if (checkUserAgentOrClientIp(clientIp, agent, mfaMethod, pattern)) {
                return providerFound;
            }

            if (checkRequestGeoLocation(httpServletRequest, clientIp, mfaMethod, pattern)) {
                return providerFound;
            }
        }
        return Optional.empty();
    }
This is {@link AdaptiveMultifactorAuthenticationTrigger}.

@author Misagh Moayyed
@since 6.0.0
core/cas-server-core-authentication-mfa-api/src/main/java/org/apereo/cas/authentication/mfa/trigger/AdaptiveMultifactorAuthenticationTrigger.java