Search in sources :

Example 1 with Credentials

use of cz.msebera.android.httpclient.auth.Credentials in project android-async-http by loopj.

the class PreemptiveAuthorizationHttpRequestInterceptor method process.

public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
    CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
    HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
    if (authState.getAuthScheme() == null) {
        AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
        Credentials creds = credsProvider.getCredentials(authScope);
        if (creds != null) {
            authState.setAuthScheme(new BasicScheme());
            authState.setCredentials(creds);
        }
    }
}
Also used : BasicScheme(cz.msebera.android.httpclient.impl.auth.BasicScheme) AuthState(cz.msebera.android.httpclient.auth.AuthState) HttpHost(cz.msebera.android.httpclient.HttpHost) AuthScope(cz.msebera.android.httpclient.auth.AuthScope) CredentialsProvider(cz.msebera.android.httpclient.client.CredentialsProvider) Credentials(cz.msebera.android.httpclient.auth.Credentials)

Aggregations

HttpHost (cz.msebera.android.httpclient.HttpHost)1 AuthScope (cz.msebera.android.httpclient.auth.AuthScope)1 AuthState (cz.msebera.android.httpclient.auth.AuthState)1 Credentials (cz.msebera.android.httpclient.auth.Credentials)1 CredentialsProvider (cz.msebera.android.httpclient.client.CredentialsProvider)1 BasicScheme (cz.msebera.android.httpclient.impl.auth.BasicScheme)1