use of org.apache.http.impl.client.BasicAuthCache in project tomee by apache.
the class AuthBeanTest method get.
private String get(final String user, final String password) {
final BasicCredentialsProvider basicCredentialsProvider = new BasicCredentialsProvider();
basicCredentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password));
final CloseableHttpClient client = HttpClients.custom().setDefaultCredentialsProvider(basicCredentialsProvider).build();
final HttpHost httpHost = new HttpHost(webapp.getHost(), webapp.getPort(), webapp.getProtocol());
final AuthCache authCache = new BasicAuthCache();
final BasicScheme basicAuth = new BasicScheme();
authCache.put(httpHost, basicAuth);
final HttpClientContext context = HttpClientContext.create();
context.setAuthCache(authCache);
final HttpGet get = new HttpGet(webapp.toExternalForm() + "servlet");
CloseableHttpResponse response = null;
try {
response = client.execute(httpHost, get, context);
return response.getStatusLine().getStatusCode() + " " + EntityUtils.toString(response.getEntity());
} catch (final IOException e) {
throw new IllegalStateException(e);
} finally {
try {
IO.close(response);
} catch (final IOException e) {
// no-op
}
}
}
use of org.apache.http.impl.client.BasicAuthCache in project project-build-plugin by axonivy.
the class HttpDeployer method getRequestContext.
private HttpClientContext getRequestContext(String url) throws URISyntaxException, MojoExecutionException {
String username = "admin";
String password = "admin";
if (server != null) {
username = server.getUsername();
try {
password = secDispatcher.decrypt(server.getPassword());
} catch (SecDispatcherException ex) {
throw new MojoExecutionException("Could not decrypt maven password", ex);
}
}
HttpHost httpHost = URIUtils.extractHost(new URI(url));
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
AuthCache authCache = new BasicAuthCache();
authCache.put(httpHost, new BasicScheme());
HttpClientContext context = HttpClientContext.create();
context.setCredentialsProvider(credsProvider);
context.setAuthCache(authCache);
return context;
}
use of org.apache.http.impl.client.BasicAuthCache in project metron by apache.
the class TaxiiHandler method createContext.
private static HttpClientContext createContext(URL endpoint, String username, String password, int port) {
HttpClientContext context = null;
HttpHost target = new HttpHost(endpoint.getHost(), port, endpoint.getProtocol());
if (username != null && password != null) {
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(target.getHostName(), target.getPort()), new UsernamePasswordCredentials(username, password));
// http://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html
AuthCache authCache = new BasicAuthCache();
authCache.put(target, new BasicScheme());
// Add AuthCache to the execution context
context = HttpClientContext.create();
context.setCredentialsProvider(credsProvider);
context.setAuthCache(authCache);
} else {
context = null;
}
return context;
}
use of org.apache.http.impl.client.BasicAuthCache in project flow by vaadin.
the class DefaultFileDownloader method makeLocalContext.
private HttpClientContext makeLocalContext(URL requestUrl) {
// Auth target host
HttpHost target = new HttpHost(requestUrl.getHost(), requestUrl.getPort(), requestUrl.getProtocol());
// 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(target, basicAuth);
// Add AuthCache to the execution context
HttpClientContext localContext = HttpClientContext.create();
localContext.setAuthCache(authCache);
return localContext;
}
use of org.apache.http.impl.client.BasicAuthCache in project pentaho-kettle by pentaho.
the class SlaveServer method addCredentials.
private void addCredentials(HttpClientContext context) {
String userName;
String password;
String host;
int port;
String proxyHost;
lock.readLock().lock();
try {
host = environmentSubstitute(hostname);
port = Const.toInt(environmentSubstitute(this.port), 80);
userName = environmentSubstitute(username);
password = Encr.decryptPasswordOptionallyEncrypted(environmentSubstitute(this.password));
proxyHost = environmentSubstitute(proxyHostname);
} finally {
lock.readLock().unlock();
}
CredentialsProvider provider = new BasicCredentialsProvider();
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(userName, password);
if (!Utils.isEmpty(proxyHost) && host.equals("localhost")) {
host = "127.0.0.1";
}
provider.setCredentials(new AuthScope(host, port), credentials);
context.setCredentialsProvider(provider);
// Generate BASIC scheme object and add it to the local auth cache
HttpHost target = new HttpHost(host, port, isSslMode() ? HTTPS : HTTP);
AuthCache authCache = new BasicAuthCache();
BasicScheme basicAuth = new BasicScheme();
authCache.put(target, basicAuth);
context.setAuthCache(authCache);
}
Aggregations