use of org.apache.http.impl.client.BasicCredentialsProvider in project orientdb by orientechnologies.
the class BaseHttpTest method exec.
protected BaseHttpTest exec() throws IOException {
final HttpHost targetHost = new HttpHost(getHost(), getPort(), getProtocol());
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(targetHost), new UsernamePasswordCredentials(getUserName(), getUserPassword()));
// Create AuthCache instance
AuthCache authCache = new BasicAuthCache();
// Generate BASIC scheme object and add it to the local auth cache
BasicScheme basicAuth = new BasicScheme();
authCache.put(targetHost, basicAuth);
// Add AuthCache to the execution context
HttpClientContext context = HttpClientContext.create();
context.setCredentialsProvider(credsProvider);
context.setAuthCache(authCache);
if (keepAlive != null)
request.addHeader("Connection", keepAlive ? "Keep-Alive" : "Close");
if (payload != null && request instanceof HttpEntityEnclosingRequestBase)
((HttpEntityEnclosingRequestBase) request).setEntity(payload);
final CloseableHttpClient httpClient = HttpClients.createDefault();
// DefaultHttpMethodRetryHandler retryhandler = new DefaultHttpMethodRetryHandler(retry, false);
// context.setAttribute(HttpMethodParams.RETRY_HANDLER, retryhandler);
response = httpClient.execute(targetHost, request, context);
return this;
}
use of org.apache.http.impl.client.BasicCredentialsProvider in project geode by apache.
the class GeodeRestClient method doRequest.
public HttpResponse doRequest(HttpRequestBase request, String username, String password) throws Exception {
HttpHost targetHost = new HttpHost(bindAddress, restPort, protocol);
HttpClientBuilder clientBuilder = HttpClients.custom();
HttpClientContext clientContext = HttpClientContext.create();
// configures the clientBuilder and clientContext
if (username != null) {
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials(username, password));
clientBuilder.setDefaultCredentialsProvider(credsProvider);
}
if (useHttps) {
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(new KeyManager[0], new TrustManager[] { new DefaultTrustManager() }, new SecureRandom());
clientBuilder.setSSLContext(ctx);
clientBuilder.setSSLHostnameVerifier(new NoopHostnameVerifier());
}
return clientBuilder.build().execute(targetHost, request, clientContext);
}
use of org.apache.http.impl.client.BasicCredentialsProvider in project jackrabbit by apache.
the class RepositoryServiceImpl method getContext.
protected HttpContext getContext(SessionInfo sessionInfo) throws RepositoryException {
HttpClientContext result = HttpClientContext.create();
if (sessionInfo != null) {
checkSessionInfo(sessionInfo);
org.apache.http.auth.Credentials creds = ((SessionInfoImpl) sessionInfo).getCredentials().getHttpCredentials();
if (creds != null) {
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new org.apache.http.auth.AuthScope(httpHost.getHostName(), httpHost.getPort()), creds);
BasicScheme basicAuth = new BasicScheme();
AuthCache authCache = new BasicAuthCache();
authCache.put(httpHost, basicAuth);
result.setCredentialsProvider(credsProvider);
result.setAuthCache(authCache);
}
}
return result;
}
use of org.apache.http.impl.client.BasicCredentialsProvider in project jackrabbit by apache.
the class WebDAVTest method setUp.
protected void setUp() throws Exception {
this.uri = URI.create(System.getProperty("webdav.test.url", "http://localhost:8080/repository/default/"));
this.root = this.uri.toASCIIString();
if (!this.root.endsWith("/")) {
this.root += "/";
}
this.username = System.getProperty("webdav.test.username", "admin");
this.password = System.getProperty("webdav.test.password", "admin");
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
HttpHost targetHost = new HttpHost(uri.getHost(), uri.getPort());
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials(this.username, this.password));
AuthCache authCache = new BasicAuthCache();
// Generate BASIC scheme object and add it to the local auth cache
BasicScheme basicAuth = new BasicScheme();
authCache.put(targetHost, basicAuth);
// Add AuthCache to the execution context
this.context = HttpClientContext.create();
this.context.setCredentialsProvider(credsProvider);
this.context.setAuthCache(authCache);
this.client = HttpClients.custom().setConnectionManager(cm).build();
super.setUp();
}
use of org.apache.http.impl.client.BasicCredentialsProvider in project jena by apache.
the class TestAuth method update_with_auth_11.
@Test
public void update_with_auth_11() {
UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate);
// Auth credentials for valid user with correct password scoped to correct URI
// Also using pre-emptive auth
BasicCredentialsProvider credsProv = new BasicCredentialsProvider();
URI scope = URI.create(authServiceUpdate);
credsProv.setCredentials(new AuthScope(scope.getHost(), scope.getPort()), new UsernamePasswordCredentials("allowed", "password"));
// Create AuthCache instance
AuthCache authCache = new BasicAuthCache();
// Generate BASIC scheme object and add it to the local auth cache
BasicScheme basicAuth = new BasicScheme();
authCache.put(new HttpHost(scope.getHost()), basicAuth);
// Add AuthCache to the execution context
HttpClientContext context = HttpClientContext.create();
context.setCredentialsProvider(credsProv);
context.setAuthCache(authCache);
HttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProv).build();
ue.setClient(client);
ue.setHttpContext(context);
ue.execute();
}
Aggregations