Search in sources :

Example 56 with CredentialsProvider

use of org.graylog.shaded.elasticsearch7.org.apache.http.client.CredentialsProvider in project rdf4j by eclipse.

the class SPARQLProtocolSession method setUsernameAndPasswordForUrl.

protected void setUsernameAndPasswordForUrl(String username, String password, String url) {
    if (username != null && password != null) {
        logger.debug("Setting username '{}' and password for server at {}.", username, url);
        java.net.URI requestURI = java.net.URI.create(url);
        String host = requestURI.getHost();
        int port = requestURI.getPort();
        AuthScope scope = new AuthScope(host, port);
        UsernamePasswordCredentials cred = new UsernamePasswordCredentials(username, password);
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(scope, cred);
        httpContext.setCredentialsProvider(credsProvider);
        AuthCache authCache = new BasicAuthCache();
        BasicScheme basicAuth = new BasicScheme();
        HttpHost httpHost = new HttpHost(requestURI.getHost(), requestURI.getPort(), requestURI.getScheme());
        authCache.put(httpHost, basicAuth);
        httpContext.setAuthCache(authCache);
    } else {
        httpContext.removeAttribute(HttpClientContext.AUTH_CACHE);
        httpContext.removeAttribute(HttpClientContext.CREDS_PROVIDER);
    }
}
Also used : BasicScheme(org.apache.http.impl.auth.BasicScheme) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpHost(org.apache.http.HttpHost) 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 57 with CredentialsProvider

use of org.graylog.shaded.elasticsearch7.org.apache.http.client.CredentialsProvider in project watchdog by TestRoots.

the class NetworkUtils method createAuthenticatedHttpClient.

/**
 * Creates an HTTP client that uses an authenticated connection.
 */
private static CloseableHttpClient createAuthenticatedHttpClient() {
    CredentialsProvider provider = new BasicCredentialsProvider();
    byte[] providerInfo = { 104, 110, 115, 112, 113, 115, 122, 110, 112, 113 };
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("watchdogplugin", new String(providerInfo, Charset.defaultCharset()));
    provider.setCredentials(AuthScope.ANY, credentials);
    return createPlainHttpClientBuilder().setDefaultCredentialsProvider(provider).build();
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 58 with CredentialsProvider

use of org.graylog.shaded.elasticsearch7.org.apache.http.client.CredentialsProvider in project apex-core by apache.

the class WebServicesClientTest method checkUserCredentials.

public static void checkUserCredentials(String username, String password, AuthScheme authScheme) throws NoSuchFieldException, IllegalAccessException {
    CredentialsProvider provider = getCredentialsProvider();
    String httpScheme = AuthScope.ANY_SCHEME;
    if (authScheme == AuthScheme.BASIC) {
        httpScheme = AuthSchemes.BASIC;
    } else if (authScheme == AuthScheme.DIGEST) {
        httpScheme = AuthSchemes.DIGEST;
    }
    AuthScope authScope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, httpScheme);
    Credentials credentials = provider.getCredentials(authScope);
    Assert.assertNotNull("Credentials", credentials);
    Assert.assertTrue("Credentials type is user", UsernamePasswordCredentials.class.isAssignableFrom(credentials.getClass()));
    UsernamePasswordCredentials pwdCredentials = (UsernamePasswordCredentials) credentials;
    Assert.assertEquals("Username", username, pwdCredentials.getUserName());
    Assert.assertEquals("Password", password, pwdCredentials.getPassword());
}
Also used : AuthScope(org.apache.http.auth.AuthScope) CredentialsProvider(org.apache.http.client.CredentialsProvider) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) Credentials(org.apache.http.auth.Credentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 59 with CredentialsProvider

use of org.graylog.shaded.elasticsearch7.org.apache.http.client.CredentialsProvider in project spring-boot-admin by codecentric.

the class AdminServerNotifierAutoConfiguration method createNotifierRestTemplate.

private static RestTemplate createNotifierRestTemplate(NotifierProxyProperties proxyProperties) {
    RestTemplate restTemplate = new RestTemplate();
    if (proxyProperties.getHost() != null) {
        HttpClientBuilder builder = HttpClientBuilder.create();
        builder.setProxy(new HttpHost(proxyProperties.getHost(), proxyProperties.getPort()));
        if (proxyProperties.getUsername() != null && proxyProperties.getPassword() != null) {
            CredentialsProvider credsProvider = new BasicCredentialsProvider();
            credsProvider.setCredentials(new AuthScope(proxyProperties.getHost(), proxyProperties.getPort()), new UsernamePasswordCredentials(proxyProperties.getUsername(), proxyProperties.getPassword()));
            builder.setDefaultCredentialsProvider(credsProvider);
        }
        restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(builder.build()));
    }
    return restTemplate;
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpHost(org.apache.http.HttpHost) RestTemplate(org.springframework.web.client.RestTemplate) AuthScope(org.apache.http.auth.AuthScope) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 60 with CredentialsProvider

use of org.graylog.shaded.elasticsearch7.org.apache.http.client.CredentialsProvider in project dropwizard by dropwizard.

the class JerseyClientBuilderTest method usesACustomCredentialsProvider.

@Test
void usesACustomCredentialsProvider() {
    CredentialsProvider customCredentialsProvider = new SystemDefaultCredentialsProvider();
    builder.using(customCredentialsProvider);
    verify(apacheHttpClientBuilder).using(customCredentialsProvider);
}
Also used : CredentialsProvider(org.apache.http.client.CredentialsProvider) SystemDefaultCredentialsProvider(org.apache.http.impl.client.SystemDefaultCredentialsProvider) SystemDefaultCredentialsProvider(org.apache.http.impl.client.SystemDefaultCredentialsProvider) Test(org.junit.jupiter.api.Test)

Aggregations

CredentialsProvider (org.apache.http.client.CredentialsProvider)271 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)223 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)201 AuthScope (org.apache.http.auth.AuthScope)138 HttpHost (org.apache.http.HttpHost)104 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)73 HttpGet (org.apache.http.client.methods.HttpGet)62 BasicScheme (org.apache.http.impl.auth.BasicScheme)49 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)48 HttpResponse (org.apache.http.HttpResponse)45 Test (org.junit.Test)44 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)41 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)40 IOException (java.io.IOException)39 URI (java.net.URI)36 Credentials (org.apache.http.auth.Credentials)36 AuthCache (org.apache.http.client.AuthCache)33 BasicAuthCache (org.apache.http.impl.client.BasicAuthCache)33 HttpClient (org.apache.http.client.HttpClient)31 RequestConfig (org.apache.http.client.config.RequestConfig)29