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

        return FunctionUtils.doUnchecked(() -> {
            val args = new Object[]{service, registeredService, authentication, httpServletRequest, LOGGER};
            val provider = this.watchableScript.execute(args, String.class);
            LOGGER.debug("Groovy script run for [{}] returned the provider id [{}]", registeredService, provider);
            if (StringUtils.isBlank(provider)) {
                return Optional.empty();
            }
            val principal = multifactorAuthenticationProviderResolver.resolvePrincipal(authentication.getPrincipal());
            if (provider.equals(ChainingMultifactorAuthenticationProvider.DEFAULT_IDENTIFIER)) {
                return Optional.of(multifactorAuthenticationProviderSelector.resolve(providerMap.values(), registeredService, principal));
            }
            return MultifactorAuthenticationUtils.resolveProvider(providerMap, provider);
        });

    }
This is {@link GroovyScriptMultifactorAuthenticationTrigger}.

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