protected DelegatedAuthenticationDynamicDiscoveryProvider getMatchingProvider(
        final Principal principal, final String keyPattern,
        final DelegatedAuthenticationDynamicDiscoveryProvider provider) {
        val attrName = properties.getAuthn().getPac4j().getCore().getDiscoverySelection().getJson().getPrincipalAttribute();
        if (StringUtils.isNotBlank(attrName) && principal.getAttributes().containsKey(attrName)) {
            val attrValues = principal.getAttributes().get(attrName);
            LOGGER.debug("Checking attribute values [{}] against [{}]", attrValues, keyPattern);
            return attrValues.stream().anyMatch(value -> RegexUtils.find(keyPattern, value.toString())) ? provider : null;
        }
        return RegexUtils.find(keyPattern, principal.getId()) ? provider : null;
    }
This is {@link DefaultDelegatedAuthenticationDynamicDiscoveryProviderLocator}.

@author Misagh Moayyed
@since 6.5.0
support/cas-server-support-pac4j-core/src/main/java/org/apereo/cas/pac4j/discovery/DefaultDelegatedAuthenticationDynamicDiscoveryProviderLocator.java