use of org.apache.http.impl.auth.BasicScheme 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.auth.BasicScheme in project ats-framework by Axway.
the class HttpClient method addRequestHeaders.
private void addRequestHeaders(HttpRequestBase httpMethod) throws FileTransferException {
// pass user credentials with the very first headers
if (preemptiveBasicAuthentication) {
if (this.username == null) {
throw new FileTransferException("We cannot set user credentials as the user name is not set");
}
try {
BasicScheme schema = new BasicScheme(Charset.forName("US-ASCII"));
Header authenticationHeader = schema.authenticate(// here we make 'empty' http request, just so we could authenticate the credentials
new UsernamePasswordCredentials(this.username, this.userpass), new HttpGet(), httpContext);
httpMethod.addHeader(authenticationHeader);
} catch (AuthenticationException ae) {
throw new FileTransferException("Unable to add Basic Authentication header", ae);
}
}
// Add the rest of the request headers
for (Header header : requestHeaders) {
httpMethod.setHeader(header);
}
}
use of org.apache.http.impl.auth.BasicScheme 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.auth.BasicScheme 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.auth.BasicScheme 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