@Override
    public Optional<MultifactorAuthenticationProvider> isActivated(final Authentication authentication,
                                                                   final RegisteredService registeredService,
                                                                   final HttpServletRequest request,
                                                                   final HttpServletResponse response,
                                                                   final Service service) {
        val grouperField = casProperties.getAuthn().getMfa()
            .getTriggers().getGrouper().getGrouperGroupField();
        if (StringUtils.isBlank(grouperField)) {
            LOGGER.debug("No group field is defined to process for Grouper multifactor trigger");
            return Optional.empty();
        }
        if (authentication == null || registeredService == null) {
            LOGGER.debug("No authentication or service 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();
        }

        val principal = authentication.getPrincipal();
        val results = grouperFacade.getGroupsForSubjectId(principal.getId());
        if (results.isEmpty()) {
            LOGGER.debug("No groups could be found for [{}] to resolve events for MFA", principal);
            return Optional.empty();
        }
        
        val groupField = GrouperGroupField.valueOf(grouperField);

        val values = results.stream()
            .flatMap(wsGetGroupsResult -> Stream.of(wsGetGroupsResult.getWsGroups()))
            .map(g -> GrouperFacade.getGrouperGroupAttribute(groupField, g))
            .collect(Collectors.toSet());

        return MultifactorAuthenticationUtils.resolveProvider(providerMap, values);
    }
This is {@link GrouperMultifactorAuthenticationTrigger}.

@author Misagh Moayyed
@since 6.0.0
support/cas-server-support-grouper/src/main/java/org/apereo/cas/web/flow/GrouperMultifactorAuthenticationTrigger.java