Search in sources :

Example 31 with AuthenticationException

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

the class RequestTargetAuthentication method process.

public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }
    if (context == null) {
        throw new IllegalArgumentException("HTTP context may not be null");
    }
    if (request.containsHeader(AUTH.WWW_AUTH_RESP)) {
        return;
    }
    // Obtain authentication state
    AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
    if (authState == null) {
        return;
    }
    AuthScheme authScheme = authState.getAuthScheme();
    if (authScheme == null) {
        return;
    }
    Credentials creds = authState.getCredentials();
    if (creds == null) {
        this.log.debug("User credentials not available");
        return;
    }
    if (authState.getAuthScope() != null || !authScheme.isConnectionBased()) {
        try {
            request.addHeader(authScheme.authenticate(creds, request));
        } catch (AuthenticationException ex) {
            if (this.log.isErrorEnabled()) {
                this.log.error("Authentication error: " + ex.getMessage());
            }
        }
    }
}
Also used : AuthState(org.apache.http.auth.AuthState) AuthenticationException(org.apache.http.auth.AuthenticationException) Credentials(org.apache.http.auth.Credentials) AuthScheme(org.apache.http.auth.AuthScheme)

Aggregations

AuthenticationException (org.apache.http.auth.AuthenticationException)31 AuthScheme (org.apache.http.auth.AuthScheme)17 Header (org.apache.http.Header)16 HttpHost (org.apache.http.HttpHost)9 Credentials (org.apache.http.auth.Credentials)9 HttpRequest (org.apache.http.HttpRequest)8 CredentialsProvider (org.apache.http.client.CredentialsProvider)8 AbortableHttpRequest (org.apache.http.client.methods.AbortableHttpRequest)8 BasicHttpRequest (org.apache.http.message.BasicHttpRequest)8 AuthState (org.apache.http.auth.AuthState)6 InvalidCredentialsException (org.apache.http.auth.InvalidCredentialsException)6 BufferedHeader (org.apache.http.message.BufferedHeader)5 CharArrayBuffer (org.apache.http.util.CharArrayBuffer)5 URI (java.net.URI)4 HttpEntity (org.apache.http.HttpEntity)4 HttpException (org.apache.http.HttpException)4 HttpResponse (org.apache.http.HttpResponse)4 NTCredentials (org.apache.http.auth.NTCredentials)4 RedirectException (org.apache.http.client.RedirectException)4 HttpGet (org.apache.http.client.methods.HttpGet)4