public List select()

in httpclient5/src/main/java/org/apache/hc/client5/http/impl/DefaultAuthenticationStrategy.java [75:123]


    public List<AuthScheme> select(
            final ChallengeType challengeType,
            final Map<String, AuthChallenge> challenges,
            final HttpContext context) {
        Args.notNull(challengeType, "ChallengeType");
        Args.notNull(challenges, "Map of auth challenges");
        Args.notNull(context, "HTTP context");
        final HttpClientContext clientContext = HttpClientContext.adapt(context);
        final String exchangeId = clientContext.getExchangeId();

        final List<AuthScheme> options = new ArrayList<>();
        final Lookup<AuthSchemeFactory> registry = clientContext.getAuthSchemeRegistry();
        if (registry == null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("{} Auth scheme registry not set in the context", exchangeId);
            }
            return options;
        }
        final RequestConfig config = clientContext.getRequestConfig();
        Collection<String> authPrefs = challengeType == ChallengeType.TARGET ?
                config.getTargetPreferredAuthSchemes() : config.getProxyPreferredAuthSchemes();
        if (authPrefs == null) {
            authPrefs = DEFAULT_SCHEME_PRIORITY;
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("{} Authentication schemes in the order of preference: {}", exchangeId, authPrefs);
        }

        for (final String schemeName: authPrefs) {
            final AuthChallenge challenge = challenges.get(schemeName.toLowerCase(Locale.ROOT));
            if (challenge != null) {
                final AuthSchemeFactory authSchemeFactory = registry.lookup(schemeName);
                if (authSchemeFactory == null) {
                    if (LOG.isWarnEnabled()) {
                        LOG.warn("{} Authentication scheme {} not supported", exchangeId, schemeName);
                        // Try again
                    }
                    continue;
                }
                final AuthScheme authScheme = authSchemeFactory.create(context);
                options.add(authScheme);
            } else {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("{} Challenge for {} authentication scheme not available", exchangeId, schemeName);
                }
            }
        }
        return options;
    }