Search in sources :

Example 16 with Credentials

use of org.apache.http.auth.Credentials in project sling by apache.

the class PreemptiveAuthInterceptor method process.

public void process(HttpRequest request, 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 not auth scheme has been initialized yet
    if (authState.getAuthScheme() == null) {
        AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
        // Obtain credentials matching the target host
        Credentials creds = credsProvider.getCredentials(authScope);
        // If found, generate BasicScheme preemptively
        if (creds != null) {
            authState.setAuthScheme(new BasicScheme());
            authState.setCredentials(creds);
        }
    }
}
Also used : BasicScheme(org.apache.http.impl.auth.BasicScheme) AuthState(org.apache.http.auth.AuthState) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) CredentialsProvider(org.apache.http.client.CredentialsProvider) Credentials(org.apache.http.auth.Credentials)

Example 17 with Credentials

use of org.apache.http.auth.Credentials in project dropwizard by dropwizard.

the class HttpClientBuilderTest method usesCredentialsProvider.

@Test
public void usesCredentialsProvider() throws Exception {
    final CredentialsProvider credentialsProvider = new CredentialsProvider() {

        @Override
        public void setCredentials(AuthScope authscope, Credentials credentials) {
        }

        @Override
        public Credentials getCredentials(AuthScope authscope) {
            return null;
        }

        @Override
        public void clear() {
        }
    };
    assertThat(builder.using(configuration).using(credentialsProvider).createClient(apacheBuilder, connectionManager, "test")).isNotNull();
    assertThat(spyHttpClientBuilderField("credentialsProvider", apacheBuilder)).isSameAs(credentialsProvider);
}
Also used : AuthScope(org.apache.http.auth.AuthScope) CredentialsProvider(org.apache.http.client.CredentialsProvider) Credentials(org.apache.http.auth.Credentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) Test(org.junit.Test)

Example 18 with Credentials

use of org.apache.http.auth.Credentials in project SmartAndroidSource by jaychou2012.

the class PreemtiveAuthorizationHttpRequestInterceptor 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(org.apache.http.impl.auth.BasicScheme) AuthState(org.apache.http.auth.AuthState) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) CredentialsProvider(org.apache.http.client.CredentialsProvider) Credentials(org.apache.http.auth.Credentials)

Example 19 with Credentials

use of org.apache.http.auth.Credentials in project camel by apache.

the class ProxyHttpClientConfigurer method configureHttpClient.

public void configureHttpClient(HttpClientBuilder clientBuilder) {
    clientBuilder.setProxy(new HttpHost(host, port, scheme));
    if (username != null && password != null) {
        Credentials defaultcreds;
        if (domain != null) {
            defaultcreds = new NTCredentials(username, password, ntHost, domain);
        } else {
            defaultcreds = new UsernamePasswordCredentials(username, password);
        }
        BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(AuthScope.ANY, defaultcreds);
        clientBuilder.setDefaultCredentialsProvider(credentialsProvider);
    }
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpHost(org.apache.http.HttpHost) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) NTCredentials(org.apache.http.auth.NTCredentials) Credentials(org.apache.http.auth.Credentials) NTCredentials(org.apache.http.auth.NTCredentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 20 with Credentials

use of org.apache.http.auth.Credentials in project camel by apache.

the class BasicAuthenticationHttpClientConfigurer method configureHttpClient.

public void configureHttpClient(HttpClientBuilder clientBuilder) {
    Credentials defaultcreds;
    if (domain != null) {
        defaultcreds = new NTCredentials(username, password, host, domain);
    } else {
        defaultcreds = new UsernamePasswordCredentials(username, password);
    }
    BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, defaultcreds);
    clientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) NTCredentials(org.apache.http.auth.NTCredentials) Credentials(org.apache.http.auth.Credentials) NTCredentials(org.apache.http.auth.NTCredentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Aggregations

Credentials (org.apache.http.auth.Credentials)39 AuthScope (org.apache.http.auth.AuthScope)22 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)16 AuthScheme (org.apache.http.auth.AuthScheme)15 CredentialsProvider (org.apache.http.client.CredentialsProvider)13 AuthState (org.apache.http.auth.AuthState)11 AuthenticationException (org.apache.http.auth.AuthenticationException)9 HttpHost (org.apache.http.HttpHost)8 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)7 NTCredentials (org.apache.http.auth.NTCredentials)5 IOException (java.io.IOException)4 Header (org.apache.http.Header)4 HttpException (org.apache.http.HttpException)4 HttpRequest (org.apache.http.HttpRequest)4 HttpResponse (org.apache.http.HttpResponse)4 Scheme (org.apache.http.conn.scheme.Scheme)4 BasicScheme (org.apache.http.impl.auth.BasicScheme)4 HttpEntity (org.apache.http.HttpEntity)3 AbortableHttpRequest (org.apache.http.client.methods.AbortableHttpRequest)3 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)3