@Override
    public Optional<MultifactorAuthenticationProvider> isActivated(final Authentication authentication,
                                                                   final RegisteredService registeredService,
                                                                   final HttpServletRequest httpServletRequest,
                                                                   final HttpServletResponse response,
                                                                   final Service service) throws Throwable {
        if (registeredService == null || authentication == null) {
            LOGGER.debug("No service or authentication is available to determine event for principal");
            return Optional.empty();
        }

        val policy = registeredService.getMultifactorAuthenticationPolicy();
        if (policy == null || policy.getMultifactorAuthenticationProviders().isEmpty()) {
            LOGGER.trace("Authentication policy does not contain any multifactor authentication providers");
            return Optional.empty();
        }

        if (StringUtils.isNotBlank(policy.getPrincipalAttributeNameTrigger())
            || StringUtils.isNotBlank(policy.getPrincipalAttributeValueToMatch())) {
            LOGGER.debug("Authentication policy for [{}] has defined principal attribute triggers. Skipping...",
                registeredService.getServiceId());
            return Optional.empty();
        }

        val principal = authentication.getPrincipal();
        val providers = MultifactorAuthenticationUtils.getMultifactorAuthenticationProviderForService(registeredService, applicationContext);
        if (providers != null && !providers.isEmpty()) {
            val provider = multifactorAuthenticationProviderSelector.resolve(providers, registeredService, principal);
            LOGGER.debug("Selected multifactor authentication provider for this transaction is [{}]", provider);
            if (provider != null) {
                return Optional.of(provider);
            }
        }
        return Optional.empty();
    }
This is {@link RegisteredServiceMultifactorAuthenticationTrigger}.

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