use of org.apache.http.impl.client.BasicCredentialsProvider in project indy by Commonjava.
the class AbstractHttproxFunctionalTest method proxyContext.
protected HttpClientContext proxyContext(final String user, final String pass) {
final CredentialsProvider creds = new BasicCredentialsProvider();
creds.setCredentials(new AuthScope(HOST, proxyPort), new UsernamePasswordCredentials(user, pass));
final HttpClientContext ctx = HttpClientContext.create();
ctx.setCredentialsProvider(creds);
return ctx;
}
use of org.apache.http.impl.client.BasicCredentialsProvider in project indy by Commonjava.
the class BasicAuthenticator method decoratePrototypeContext.
@Override
public HttpClientContext decoratePrototypeContext(AuthScope scope, SiteConfig location, PasswordType type, HttpClientContext ctx) {
if (user != null) {
final CredentialsProvider credProvider = new BasicCredentialsProvider();
credProvider.setCredentials(scope, new UsernamePasswordCredentials(user, pass));
ctx.setCredentialsProvider(credProvider);
}
return ctx;
}
use of org.apache.http.impl.client.BasicCredentialsProvider in project elasticsearch by elastic.
the class RestClientSingleHostIntegTests method createRestClient.
private static RestClient createRestClient(final boolean useAuth, final boolean usePreemptiveAuth) {
// provide the username/password for every request
final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("user", "pass"));
final RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost(httpServer.getAddress().getHostString(), httpServer.getAddress().getPort())).setDefaultHeaders(defaultHeaders);
if (pathPrefix.length() > 0) {
// sometimes cut off the leading slash
restClientBuilder.setPathPrefix(randomBoolean() ? pathPrefix.substring(1) : pathPrefix);
}
if (useAuth) {
restClientBuilder.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
@Override
public HttpAsyncClientBuilder customizeHttpClient(final HttpAsyncClientBuilder httpClientBuilder) {
if (usePreemptiveAuth == false) {
// disable preemptive auth by ignoring any authcache
httpClientBuilder.disableAuthCaching();
}
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}
});
}
return restClientBuilder.build();
}
use of org.apache.http.impl.client.BasicCredentialsProvider in project elasticsearch by elastic.
the class TransportReindexAction method buildRestClient.
/**
* Build the {@link RestClient} used for reindexing from remote clusters.
* @param remoteInfo connection information for the remote cluster
* @param taskId the id of the current task. This is added to the thread name for easier tracking
* @param threadCollector a list in which we collect all the threads created by the client
*/
static RestClient buildRestClient(RemoteInfo remoteInfo, long taskId, List<Thread> threadCollector) {
Header[] clientHeaders = new Header[remoteInfo.getHeaders().size()];
int i = 0;
for (Map.Entry<String, String> header : remoteInfo.getHeaders().entrySet()) {
clientHeaders[i] = new BasicHeader(header.getKey(), header.getValue());
}
return RestClient.builder(new HttpHost(remoteInfo.getHost(), remoteInfo.getPort(), remoteInfo.getScheme())).setDefaultHeaders(clientHeaders).setRequestConfigCallback(c -> {
c.setConnectTimeout(Math.toIntExact(remoteInfo.getConnectTimeout().millis()));
c.setSocketTimeout(Math.toIntExact(remoteInfo.getSocketTimeout().millis()));
return c;
}).setHttpClientConfigCallback(c -> {
if (remoteInfo.getUsername() != null) {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials(remoteInfo.getUsername(), remoteInfo.getPassword());
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, creds);
c.setDefaultCredentialsProvider(credentialsProvider);
}
AtomicInteger threads = new AtomicInteger();
c.setThreadFactory(r -> {
String name = "es-client-" + taskId + "-" + threads.getAndIncrement();
Thread t = new Thread(r, name);
threadCollector.add(t);
return t;
});
c.setDefaultIOReactorConfig(IOReactorConfig.custom().setIoThreadCount(1).build());
return c;
}).build();
}
use of org.apache.http.impl.client.BasicCredentialsProvider in project h2o-2 by h2oai.
the class GoogleAnalyticsThreadFactory method createHttpClient.
protected HttpClient createHttpClient(GoogleAnalyticsConfig config) {
ThreadSafeClientConnManager connManager = new ThreadSafeClientConnManager();
connManager.setDefaultMaxPerRoute(getDefaultMaxPerRoute(config));
BasicHttpParams params = new BasicHttpParams();
if (isNotEmpty(config.getUserAgent())) {
params.setParameter(CoreProtocolPNames.USER_AGENT, config.getUserAgent());
}
if (isNotEmpty(config.getProxyHost())) {
params.setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(config.getProxyHost(), config.getProxyPort()));
}
DefaultHttpClient client = new DefaultHttpClient(connManager, params);
if (isNotEmpty(config.getProxyUserName())) {
BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope(config.getProxyHost(), config.getProxyPort()), new UsernamePasswordCredentials(config.getProxyUserName(), config.getProxyPassword()));
client.setCredentialsProvider(credentialsProvider);
}
return client;
}
Aggregations