Example usage for org.apache.http.auth AuthScheme getSchemeName

List of usage examples for org.apache.http.auth AuthScheme getSchemeName

Introduction

In this page you can find the example usage for org.apache.http.auth AuthScheme getSchemeName.

Prototype

String getSchemeName();

Source Link

Document

Returns textual designation of the given authentication scheme.

Usage

From source file:org.apache.http.impl.client.AuthenticationStrategyAdaptor.java

public void authSucceeded(final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) {
    AuthCache authCache = (AuthCache) context.getAttribute(ClientContext.AUTH_CACHE);
    if (isCachable(authScheme)) {
        if (authCache == null) {
            authCache = new BasicAuthCache();
            context.setAttribute(ClientContext.AUTH_CACHE, authCache);
        }//  w  w w  . j av  a 2 s .c o  m
        if (this.log.isDebugEnabled()) {
            this.log.debug("Caching '" + authScheme.getSchemeName() + "' auth scheme for " + authhost);
        }
        authCache.put(authhost, authScheme);
    }
}

From source file:org.apache.http.impl.client.AuthenticationStrategyAdaptor.java

public void authFailed(final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) {
    final AuthCache authCache = (AuthCache) context.getAttribute(ClientContext.AUTH_CACHE);
    if (authCache == null) {
        return;/*from www.ja  v a 2 s . com*/
    }
    if (this.log.isDebugEnabled()) {
        this.log.debug("Removing from cache '" + authScheme.getSchemeName() + "' auth scheme for " + authhost);
    }
    authCache.remove(authhost);
}

From source file:org.apache.http.impl.client.AuthenticationStrategyAdaptor.java

private boolean isCachable(final AuthScheme authScheme) {
    if (authScheme == null || !authScheme.isComplete()) {
        return false;
    }/*from ww w. j a  v  a  2s  .c  om*/
    final String schemeName = authScheme.getSchemeName();
    return schemeName.equalsIgnoreCase(AuthPolicy.BASIC) || schemeName.equalsIgnoreCase(AuthPolicy.DIGEST);
}

From source file:org.apache.http.impl.client.AuthenticationStrategyImpl.java

public Queue<AuthOption> select(final Map<String, Header> challenges, final HttpHost authhost,
        final HttpResponse response, final HttpContext context) throws MalformedChallengeException {
    Args.notNull(challenges, "Map of auth challenges");
    Args.notNull(authhost, "Host");
    Args.notNull(response, "HTTP response");
    Args.notNull(context, "HTTP context");
    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    final Queue<AuthOption> options = new LinkedList<AuthOption>();
    final Lookup<AuthSchemeProvider> registry = clientContext.getAuthSchemeRegistry();
    if (registry == null) {
        this.log.debug("Auth scheme registry not set in the context");
        return options;
    }//from  w ww.  j  a  va  2 s  .co m
    final CredentialsProvider credsProvider = clientContext.getCredentialsProvider();
    if (credsProvider == null) {
        this.log.debug("Credentials provider not set in the context");
        return options;
    }
    final RequestConfig config = clientContext.getRequestConfig();
    Collection<String> authPrefs = getPreferredAuthSchemes(config);
    if (authPrefs == null) {
        authPrefs = DEFAULT_SCHEME_PRIORITY;
    }
    if (this.log.isDebugEnabled()) {
        this.log.debug("Authentication schemes in the order of preference: " + authPrefs);
    }

    for (final String id : authPrefs) {
        final Header challenge = challenges.get(id.toLowerCase(Locale.US));
        if (challenge != null) {
            final AuthSchemeProvider authSchemeProvider = registry.lookup(id);
            if (authSchemeProvider == null) {
                if (this.log.isWarnEnabled()) {
                    this.log.warn("Authentication scheme " + id + " not supported");
                    // Try again
                }
                continue;
            }
            final AuthScheme authScheme = authSchemeProvider.create(context);
            authScheme.processChallenge(challenge);

            final AuthScope authScope = new AuthScope(authhost.getHostName(), authhost.getPort(),
                    authScheme.getRealm(), authScheme.getSchemeName());

            final Credentials credentials = credsProvider.getCredentials(authScope);
            if (credentials != null) {
                options.add(new AuthOption(authScheme, credentials));
            }
        } else {
            if (this.log.isDebugEnabled()) {
                this.log.debug("Challenge for " + id + " authentication scheme not available");
                // Try again
            }
        }
    }
    return options;
}

From source file:org.apache.http.impl.client.AuthenticationStrategyImpl.java

public void authSucceeded(final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) {
    Args.notNull(authhost, "Host");
    Args.notNull(authScheme, "Auth scheme");
    Args.notNull(context, "HTTP context");

    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    if (isCachable(authScheme)) {
        AuthCache authCache = clientContext.getAuthCache();
        if (authCache == null) {
            authCache = new BasicAuthCache();
            clientContext.setAuthCache(authCache);
        }//from  w  w  w  .j  a  v a  2  s . com
        if (this.log.isDebugEnabled()) {
            this.log.debug("Caching '" + authScheme.getSchemeName() + "' auth scheme for " + authhost);
        }
        authCache.put(authhost, authScheme);
    }
}

From source file:org.apache.http.impl.client.AuthenticationStrategyImpl.java

protected boolean isCachable(final AuthScheme authScheme) {
    if (authScheme == null || !authScheme.isComplete()) {
        return false;
    }/*from ww w.j  av  a  2 s. c  o m*/
    final String schemeName = authScheme.getSchemeName();
    return schemeName.equalsIgnoreCase(AuthSchemes.BASIC) || schemeName.equalsIgnoreCase(AuthSchemes.DIGEST);
}