Search in sources :

Example 51 with AuthScope

use of org.apache.http.auth.AuthScope in project gradle by gradle.

the class HttpClientConfigurer method useCredentials.

private void useCredentials(CredentialsProvider credentialsProvider, String host, int port, Collection<? extends Authentication> authentications) {
    Credentials httpCredentials;
    for (Authentication authentication : authentications) {
        String scheme = getAuthScheme(authentication);
        PasswordCredentials credentials = getPasswordCredentials(authentication);
        if (authentication instanceof AllSchemesAuthentication) {
            NTLMCredentials ntlmCredentials = new NTLMCredentials(credentials);
            httpCredentials = new NTCredentials(ntlmCredentials.getUsername(), ntlmCredentials.getPassword(), ntlmCredentials.getWorkstation(), ntlmCredentials.getDomain());
            credentialsProvider.setCredentials(new AuthScope(host, port, AuthScope.ANY_REALM, AuthSchemes.NTLM), httpCredentials);
            LOGGER.debug("Using {} and {} for authenticating against '{}:{}' using {}", credentials, ntlmCredentials, host, port, AuthSchemes.NTLM);
        }
        httpCredentials = new UsernamePasswordCredentials(credentials.getUsername(), credentials.getPassword());
        credentialsProvider.setCredentials(new AuthScope(host, port, AuthScope.ANY_REALM, scheme), httpCredentials);
        LOGGER.debug("Using {} for authenticating against '{}:{}' using {}", credentials, host, port, scheme);
    }
}
Also used : PasswordCredentials(org.gradle.api.credentials.PasswordCredentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) NTLMCredentials(org.gradle.internal.resource.transport.http.ntlm.NTLMCredentials) Authentication(org.gradle.authentication.Authentication) DigestAuthentication(org.gradle.authentication.http.DigestAuthentication) AllSchemesAuthentication(org.gradle.internal.authentication.AllSchemesAuthentication) BasicAuthentication(org.gradle.authentication.http.BasicAuthentication) AuthScope(org.apache.http.auth.AuthScope) AllSchemesAuthentication(org.gradle.internal.authentication.AllSchemesAuthentication) PasswordCredentials(org.gradle.api.credentials.PasswordCredentials) NTCredentials(org.apache.http.auth.NTCredentials) NTLMCredentials(org.gradle.internal.resource.transport.http.ntlm.NTLMCredentials) Credentials(org.apache.http.auth.Credentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) NTCredentials(org.apache.http.auth.NTCredentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 52 with AuthScope

use of org.apache.http.auth.AuthScope in project Lucee by lucee.

the class HTTPEngine4Impl method setCredentials.

public static BasicHttpContext setCredentials(HttpClientBuilder builder, HttpHost httpHost, String username, String password, boolean preAuth) {
    // set Username and Password
    if (!StringUtil.isEmpty(username, true)) {
        if (password == null)
            password = "";
        CredentialsProvider cp = new BasicCredentialsProvider();
        builder.setDefaultCredentialsProvider(cp);
        cp.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(username, password));
        BasicHttpContext httpContext = new BasicHttpContext();
        if (preAuth) {
            AuthCache authCache = new BasicAuthCache();
            authCache.put(httpHost, new BasicScheme());
            httpContext.setAttribute(ClientContext.AUTH_CACHE, authCache);
        }
        return httpContext;
    }
    return null;
}
Also used : BasicScheme(org.apache.http.impl.auth.BasicScheme) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) BasicHttpContext(org.apache.http.protocol.BasicHttpContext) AuthScope(org.apache.http.auth.AuthScope) AuthCache(org.apache.http.client.AuthCache) BasicAuthCache(org.apache.http.impl.client.BasicAuthCache) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) BasicAuthCache(org.apache.http.impl.client.BasicAuthCache) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 53 with AuthScope

use of org.apache.http.auth.AuthScope in project Lucee by lucee.

the class HTTPEngine4Impl method setNTCredentials.

public static void setNTCredentials(HttpClientBuilder builder, String username, String password, String workStation, String domain) {
    // set Username and Password
    if (!StringUtil.isEmpty(username, true)) {
        if (password == null)
            password = "";
        CredentialsProvider cp = new BasicCredentialsProvider();
        builder.setDefaultCredentialsProvider(cp);
        cp.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new NTCredentials(username, password, workStation, domain));
    }
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) AuthScope(org.apache.http.auth.AuthScope) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) NTCredentials(org.apache.http.auth.NTCredentials)

Example 54 with AuthScope

use of org.apache.http.auth.AuthScope in project janusgraph by JanusGraph.

the class BasicAuthHttpClientConfigCallbackTest method testSetDefaultCredentialsProviderWithRealm.

@Test
public void testSetDefaultCredentialsProviderWithRealm() throws Exception {
    final CredentialsProvider cp = basicAuthTestBase(HTTP_REALM);
    // expected: will match any host in that specific realm
    final Credentials credentialsForRealm1 = cp.getCredentials(new AuthScope("dummyhost1", 1234, HTTP_REALM));
    assertEquals(HTTP_USER, credentialsForRealm1.getUserPrincipal().getName());
    assertEquals(HTTP_PASSWORD, credentialsForRealm1.getPassword());
    // ...but not in any other realms
    final Credentials credentialsForRealm3 = cp.getCredentials(new AuthScope("dummyhost1", 1234, "Not_" + HTTP_REALM));
    assertNull(credentialsForRealm3);
}
Also used : AuthScope(org.apache.http.auth.AuthScope) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) Credentials(org.apache.http.auth.Credentials) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 55 with AuthScope

use of org.apache.http.auth.AuthScope in project androidquery by androidquery.

the class NTLMProxyHandle method applyProxy.

@Override
public void applyProxy(AbstractAjaxCallback<?, ?> cb, HttpRequest request, DefaultHttpClient client) {
    if (!isIntranet(cb.getUrl())) {
        if (!TextUtils.isEmpty(host) && !TextUtils.isEmpty(user)) {
            AQUtility.debug("ntlm token");
            client.getAuthSchemes().register("ntlm", new NTLMSchemeFactory());
            client.getCredentialsProvider().setCredentials(new AuthScope(host, port), new NTCredentials(user, password, host, domain));
            cb.proxy(host, port);
        }
    }
}
Also used : AuthScope(org.apache.http.auth.AuthScope) NTCredentials(org.apache.http.auth.NTCredentials)

Aggregations

AuthScope (org.apache.http.auth.AuthScope)103 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)64 CredentialsProvider (org.apache.http.client.CredentialsProvider)50 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)49 HttpHost (org.apache.http.HttpHost)30 Credentials (org.apache.http.auth.Credentials)25 Test (org.junit.Test)22 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)19 HttpResponse (org.apache.http.HttpResponse)17 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)15 HttpGet (org.apache.http.client.methods.HttpGet)14 BasicScheme (org.apache.http.impl.auth.BasicScheme)14 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)12 IOException (java.io.IOException)11 HttpEntity (org.apache.http.HttpEntity)10 AuthCache (org.apache.http.client.AuthCache)10 BasicAuthCache (org.apache.http.impl.client.BasicAuthCache)10 AuthScheme (org.apache.http.auth.AuthScheme)8 NTCredentials (org.apache.http.auth.NTCredentials)8 URL (java.net.URL)6