Search in sources :

Example 1 with AllSchemesAuthentication

use of org.gradle.internal.authentication.AllSchemesAuthentication 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) Credentials(org.apache.http.auth.Credentials) NTLMCredentials(org.gradle.internal.resource.transport.http.ntlm.NTLMCredentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) NTCredentials(org.apache.http.auth.NTCredentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 2 with AllSchemesAuthentication

use of org.gradle.internal.authentication.AllSchemesAuthentication in project gradle by gradle.

the class HttpClientConfigurer method configureProxy.

private void configureProxy(HttpClientBuilder builder, CredentialsProvider credentialsProvider, HttpSettings httpSettings) {
    HttpProxySettings.HttpProxy httpProxy = httpSettings.getProxySettings().getProxy();
    HttpProxySettings.HttpProxy httpsProxy = httpSettings.getSecureProxySettings().getProxy();
    for (HttpProxySettings.HttpProxy proxy : Lists.newArrayList(httpProxy, httpsProxy)) {
        if (proxy != null) {
            if (proxy.credentials != null) {
                useCredentials(credentialsProvider, proxy.host, proxy.port, Collections.singleton(new AllSchemesAuthentication(proxy.credentials)));
            }
        }
    }
    builder.setRoutePlanner(new SystemDefaultRoutePlanner(ProxySelector.getDefault()));
}
Also used : AllSchemesAuthentication(org.gradle.internal.authentication.AllSchemesAuthentication) SystemDefaultRoutePlanner(org.apache.http.impl.conn.SystemDefaultRoutePlanner)

Aggregations

AllSchemesAuthentication (org.gradle.internal.authentication.AllSchemesAuthentication)2 AuthScope (org.apache.http.auth.AuthScope)1 Credentials (org.apache.http.auth.Credentials)1 NTCredentials (org.apache.http.auth.NTCredentials)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 SystemDefaultRoutePlanner (org.apache.http.impl.conn.SystemDefaultRoutePlanner)1 PasswordCredentials (org.gradle.api.credentials.PasswordCredentials)1 Authentication (org.gradle.authentication.Authentication)1 BasicAuthentication (org.gradle.authentication.http.BasicAuthentication)1 DigestAuthentication (org.gradle.authentication.http.DigestAuthentication)1 NTLMCredentials (org.gradle.internal.resource.transport.http.ntlm.NTLMCredentials)1