@Override
    public Optional<GoogleRecaptchaProperties> shouldActivate(final RequestContext requestContext,
                                                              final GoogleRecaptchaProperties properties) {
        val service = WebUtils.getService(requestContext);
        val registeredService = servicesManager.findServiceBy(service);

        if (RegisteredServiceProperties.CAPTCHA_ENABLED.isAssignedTo(registeredService)) {
            LOGGER.trace("Checking for activation of captcha defined for service [{}]", registeredService);

            if (RegisteredServiceProperties.CAPTCHA_IP_ADDRESS_PATTERN.isAssignedTo(registeredService)) {
                val ip = Optional.ofNullable(ClientInfoHolder.getClientInfo())
                    .map(ClientInfo::getClientIpAddress).orElse(StringUtils.EMPTY).trim();
                LOGGER.trace("Checking for activation of captcha defined for service [{}] based on IP address [{}]", registeredService, ip);
                val ipPattern = RegisteredServiceProperties.CAPTCHA_IP_ADDRESS_PATTERN.getPropertyValues(registeredService, Set.class);
                val result = Objects.requireNonNull(ipPattern).stream().anyMatch(pattern -> RegexUtils.find(pattern.toString().trim(), ip));
                return evaluateResult(result, properties);
            }

            val result = RegisteredServiceProperties.CAPTCHA_ENABLED.getPropertyBooleanValue(registeredService);
            return evaluateResult(result, properties);
        }

        if (StringUtils.isNotBlank(properties.getActivateForIpAddressPattern())) {
            val ip = Optional.ofNullable(ClientInfoHolder.getClientInfo())
                .map(ClientInfo::getClientIpAddress).orElse(StringUtils.EMPTY);
            LOGGER.debug("Remote IP address [{}] will be checked against [{}]", ip, properties.getActivateForIpAddressPattern());
            val activate = RegexUtils.find(properties.getActivateForIpAddressPattern(), ip);
            return evaluateResult(activate, properties);
        }
        val siteKey = SpringExpressionLanguageValueResolver.getInstance().resolve(properties.getSiteKey());
        LOGGER.trace("Checking for activation of captcha defined under site key [{}]", siteKey);
        return evaluateResult(properties.isEnabled(), properties);
    }
This is {@link DefaultCaptchaActivationStrategy}.

@author Misagh Moayyed
@since 6.5.0
support/cas-server-support-captcha-core/src/main/java/org/apereo/cas/web/DefaultCaptchaActivationStrategy.java