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);
}
}
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();
}
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());
}
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;
}
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);
}
Aggregations