Search in sources :

Example 11 with AuthScope

use of org.apache.http.auth.AuthScope in project openhab1-addons by openhab.

the class HubIOStream method open.

@Override
public boolean open() {
    m_client = new DefaultHttpClient();
    if (m_user != null && m_pass != null) {
        m_client.getCredentialsProvider().setCredentials(new AuthScope(m_host, m_port), new UsernamePasswordCredentials(m_user, m_pass));
    }
    HttpConnectionParams.setConnectionTimeout(m_client.getParams(), 5000);
    m_in = new HubInputStream();
    m_pollThread = new Thread(this);
    m_pollThread.start();
    m_out = new HubOutputStream();
    return true;
}
Also used : AuthScope(org.apache.http.auth.AuthScope) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 12 with AuthScope

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

the class DefaultRequestDirector method updateAuthState.

private void updateAuthState(final AuthState authState, final HttpHost host, final CredentialsProvider credsProvider) {
    if (!authState.isValid()) {
        return;
    }
    String hostname = host.getHostName();
    int port = host.getPort();
    if (port < 0) {
        Scheme scheme = connManager.getSchemeRegistry().getScheme(host);
        port = scheme.getDefaultPort();
    }
    AuthScheme authScheme = authState.getAuthScheme();
    AuthScope authScope = new AuthScope(hostname, port, authScheme.getRealm(), authScheme.getSchemeName());
    if (this.log.isDebugEnabled()) {
        this.log.debug("Authentication scope: " + authScope);
    }
    Credentials creds = authState.getCredentials();
    if (creds == null) {
        creds = credsProvider.getCredentials(authScope);
        if (this.log.isDebugEnabled()) {
            if (creds != null) {
                this.log.debug("Found credentials");
            } else {
                this.log.debug("Credentials not found");
            }
        }
    } else {
        if (authScheme.isComplete()) {
            this.log.debug("Authentication failed");
            creds = null;
        }
    }
    authState.setAuthScope(authScope);
    authState.setCredentials(creds);
}
Also used : Scheme(org.apache.http.conn.scheme.Scheme) AuthScheme(org.apache.http.auth.AuthScheme) AuthScope(org.apache.http.auth.AuthScope) Credentials(org.apache.http.auth.Credentials) AuthScheme(org.apache.http.auth.AuthScheme)

Example 13 with AuthScope

use of org.apache.http.auth.AuthScope in project google-analytics-java by brsanthu.

the class GoogleAnalyticsThreadFactory method createHttpClient.

protected CloseableHttpClient createHttpClient(GoogleAnalyticsConfig config) {
    PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();
    connManager.setDefaultMaxPerRoute(getDefaultMaxPerRoute(config));
    HttpClientBuilder builder = HttpClients.custom().setConnectionManager(connManager);
    if (isNotEmpty(config.getUserAgent())) {
        builder.setUserAgent(config.getUserAgent());
    }
    if (isNotEmpty(config.getProxyHost())) {
        builder.setProxy(new HttpHost(config.getProxyHost(), config.getProxyPort()));
        if (isNotEmpty(config.getProxyUserName())) {
            BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
            credentialsProvider.setCredentials(new AuthScope(config.getProxyHost(), config.getProxyPort()), new UsernamePasswordCredentials(config.getProxyUserName(), config.getProxyPassword()));
            builder.setDefaultCredentialsProvider(credentialsProvider);
        }
    }
    return builder.build();
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 14 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) 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 15 with AuthScope

use of org.apache.http.auth.AuthScope in project XobotOS by xamarin.

the class DefaultRequestDirector method updateAuthState.

private void updateAuthState(final AuthState authState, final HttpHost host, final CredentialsProvider credsProvider) {
    if (!authState.isValid()) {
        return;
    }
    String hostname = host.getHostName();
    int port = host.getPort();
    if (port < 0) {
        Scheme scheme = connManager.getSchemeRegistry().getScheme(host);
        port = scheme.getDefaultPort();
    }
    AuthScheme authScheme = authState.getAuthScheme();
    AuthScope authScope = new AuthScope(hostname, port, authScheme.getRealm(), authScheme.getSchemeName());
    if (this.log.isDebugEnabled()) {
        this.log.debug("Authentication scope: " + authScope);
    }
    Credentials creds = authState.getCredentials();
    if (creds == null) {
        creds = credsProvider.getCredentials(authScope);
        if (this.log.isDebugEnabled()) {
            if (creds != null) {
                this.log.debug("Found credentials");
            } else {
                this.log.debug("Credentials not found");
            }
        }
    } else {
        if (authScheme.isComplete()) {
            this.log.debug("Authentication failed");
            creds = null;
        }
    }
    authState.setAuthScope(authScope);
    authState.setCredentials(creds);
}
Also used : Scheme(org.apache.http.conn.scheme.Scheme) AuthScheme(org.apache.http.auth.AuthScheme) AuthScope(org.apache.http.auth.AuthScope) Credentials(org.apache.http.auth.Credentials) AuthScheme(org.apache.http.auth.AuthScheme)

Aggregations

AuthScope (org.apache.http.auth.AuthScope)95 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)60 CredentialsProvider (org.apache.http.client.CredentialsProvider)42 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)41 HttpHost (org.apache.http.HttpHost)28 Credentials (org.apache.http.auth.Credentials)22 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)19 Test (org.junit.Test)19 HttpResponse (org.apache.http.HttpResponse)17 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)14 HttpGet (org.apache.http.client.methods.HttpGet)13 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)12 IOException (java.io.IOException)11 BasicScheme (org.apache.http.impl.auth.BasicScheme)11 HttpEntity (org.apache.http.HttpEntity)10 AuthScheme (org.apache.http.auth.AuthScheme)8 NTCredentials (org.apache.http.auth.NTCredentials)7 AuthCache (org.apache.http.client.AuthCache)7 BasicAuthCache (org.apache.http.impl.client.BasicAuthCache)7 URL (java.net.URL)6