Search in sources :

Example 1 with AuthSchemeRegistry

use of org.apache.http.auth.AuthSchemeRegistry in project XobotOS by xamarin.

the class AbstractAuthenticationHandler method selectScheme.

public AuthScheme selectScheme(final Map<String, Header> challenges, final HttpResponse response, final HttpContext context) throws AuthenticationException {
    AuthSchemeRegistry registry = (AuthSchemeRegistry) context.getAttribute(ClientContext.AUTHSCHEME_REGISTRY);
    if (registry == null) {
        throw new IllegalStateException("AuthScheme registry not set in HTTP context");
    }
    List<?> authPrefs = (List<?>) context.getAttribute(ClientContext.AUTH_SCHEME_PREF);
    if (authPrefs == null) {
        authPrefs = getAuthPreferences();
    }
    if (this.log.isDebugEnabled()) {
        this.log.debug("Authentication schemes in the order of preference: " + authPrefs);
    }
    AuthScheme authScheme = null;
    for (int i = 0; i < authPrefs.size(); i++) {
        String id = (String) authPrefs.get(i);
        Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH));
        if (challenge != null) {
            if (this.log.isDebugEnabled()) {
                this.log.debug(id + " authentication scheme selected");
            }
            try {
                authScheme = registry.getAuthScheme(id, response.getParams());
                break;
            } catch (IllegalStateException e) {
                if (this.log.isWarnEnabled()) {
                    this.log.warn("Authentication scheme " + id + " not supported");
                // Try again
                }
            }
        } else {
            if (this.log.isDebugEnabled()) {
                this.log.debug("Challenge for " + id + " authentication scheme not available");
            // Try again
            }
        }
    }
    if (authScheme == null) {
        // If none selected, something is wrong
        throw new AuthenticationException("Unable to respond to any of these challenges: " + challenges);
    }
    return authScheme;
}
Also used : Header(org.apache.http.Header) FormattedHeader(org.apache.http.FormattedHeader) AuthenticationException(org.apache.http.auth.AuthenticationException) AuthSchemeRegistry(org.apache.http.auth.AuthSchemeRegistry) List(java.util.List) AuthScheme(org.apache.http.auth.AuthScheme)

Example 2 with AuthSchemeRegistry

use of org.apache.http.auth.AuthSchemeRegistry in project robovm by robovm.

the class DefaultHttpClient method createAuthSchemeRegistry.

@Override
protected AuthSchemeRegistry createAuthSchemeRegistry() {
    AuthSchemeRegistry registry = new AuthSchemeRegistry();
    registry.register(AuthPolicy.BASIC, new BasicSchemeFactory());
    registry.register(AuthPolicy.DIGEST, new DigestSchemeFactory());
    return registry;
}
Also used : BasicSchemeFactory(org.apache.http.impl.auth.BasicSchemeFactory) AuthSchemeRegistry(org.apache.http.auth.AuthSchemeRegistry) DigestSchemeFactory(org.apache.http.impl.auth.DigestSchemeFactory)

Example 3 with AuthSchemeRegistry

use of org.apache.http.auth.AuthSchemeRegistry in project platform_external_apache-http by android.

the class DefaultHttpClient method createAuthSchemeRegistry.

@Override
protected AuthSchemeRegistry createAuthSchemeRegistry() {
    AuthSchemeRegistry registry = new AuthSchemeRegistry();
    registry.register(AuthPolicy.BASIC, new BasicSchemeFactory());
    registry.register(AuthPolicy.DIGEST, new DigestSchemeFactory());
    return registry;
}
Also used : BasicSchemeFactory(org.apache.http.impl.auth.BasicSchemeFactory) AuthSchemeRegistry(org.apache.http.auth.AuthSchemeRegistry) DigestSchemeFactory(org.apache.http.impl.auth.DigestSchemeFactory)

Example 4 with AuthSchemeRegistry

use of org.apache.http.auth.AuthSchemeRegistry in project XobotOS by xamarin.

the class DefaultHttpClient method createAuthSchemeRegistry.

@Override
protected AuthSchemeRegistry createAuthSchemeRegistry() {
    AuthSchemeRegistry registry = new AuthSchemeRegistry();
    registry.register(AuthPolicy.BASIC, new BasicSchemeFactory());
    registry.register(AuthPolicy.DIGEST, new DigestSchemeFactory());
    return registry;
}
Also used : BasicSchemeFactory(org.apache.http.impl.auth.BasicSchemeFactory) AuthSchemeRegistry(org.apache.http.auth.AuthSchemeRegistry) DigestSchemeFactory(org.apache.http.impl.auth.DigestSchemeFactory)

Example 5 with AuthSchemeRegistry

use of org.apache.http.auth.AuthSchemeRegistry in project robovm by robovm.

the class AbstractAuthenticationHandler method selectScheme.

public AuthScheme selectScheme(final Map<String, Header> challenges, final HttpResponse response, final HttpContext context) throws AuthenticationException {
    AuthSchemeRegistry registry = (AuthSchemeRegistry) context.getAttribute(ClientContext.AUTHSCHEME_REGISTRY);
    if (registry == null) {
        throw new IllegalStateException("AuthScheme registry not set in HTTP context");
    }
    List<?> authPrefs = (List<?>) context.getAttribute(ClientContext.AUTH_SCHEME_PREF);
    if (authPrefs == null) {
        authPrefs = getAuthPreferences();
    }
    if (this.log.isDebugEnabled()) {
        this.log.debug("Authentication schemes in the order of preference: " + authPrefs);
    }
    AuthScheme authScheme = null;
    for (int i = 0; i < authPrefs.size(); i++) {
        String id = (String) authPrefs.get(i);
        Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH));
        if (challenge != null) {
            if (this.log.isDebugEnabled()) {
                this.log.debug(id + " authentication scheme selected");
            }
            try {
                authScheme = registry.getAuthScheme(id, response.getParams());
                break;
            } catch (IllegalStateException e) {
                if (this.log.isWarnEnabled()) {
                    this.log.warn("Authentication scheme " + id + " not supported");
                // Try again
                }
            }
        } else {
            if (this.log.isDebugEnabled()) {
                this.log.debug("Challenge for " + id + " authentication scheme not available");
            // Try again
            }
        }
    }
    if (authScheme == null) {
        // If none selected, something is wrong
        throw new AuthenticationException("Unable to respond to any of these challenges: " + challenges);
    }
    return authScheme;
}
Also used : Header(org.apache.http.Header) FormattedHeader(org.apache.http.FormattedHeader) AuthenticationException(org.apache.http.auth.AuthenticationException) AuthSchemeRegistry(org.apache.http.auth.AuthSchemeRegistry) List(java.util.List) AuthScheme(org.apache.http.auth.AuthScheme)

Aggregations

AuthSchemeRegistry (org.apache.http.auth.AuthSchemeRegistry)7 BasicSchemeFactory (org.apache.http.impl.auth.BasicSchemeFactory)4 List (java.util.List)3 FormattedHeader (org.apache.http.FormattedHeader)3 Header (org.apache.http.Header)3 AuthScheme (org.apache.http.auth.AuthScheme)3 AuthenticationException (org.apache.http.auth.AuthenticationException)3 DigestSchemeFactory (org.apache.http.impl.auth.DigestSchemeFactory)3 AuthScope (org.apache.http.auth.AuthScope)1 Credentials (org.apache.http.auth.Credentials)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 SPNegoSchemeFactory (org.apache.http.impl.auth.SPNegoSchemeFactory)1 DecompressingHttpClient (org.apache.http.impl.client.DecompressingHttpClient)1 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)1 PoolingClientConnectionManager (org.apache.http.impl.conn.PoolingClientConnectionManager)1