use of org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider in project gradle-download-task by michel-kraemer.
the class DownloadAction method addAuthentication.
/**
* Add authentication information for the given host
* @param host the host
* @param credentials the credentials
* @param context the context in which the authentication information
* should be saved
*/
private void addAuthentication(HttpHost host, Credentials credentials, HttpClientContext context) {
AuthCache authCache = context.getAuthCache();
if (authCache == null) {
authCache = new BasicAuthCache();
context.setAuthCache(authCache);
}
CredentialsProvider credsProvider = context.getCredentialsProvider();
if (credsProvider == null) {
credsProvider = new BasicCredentialsProvider();
context.setCredentialsProvider(credsProvider);
}
((CredentialsStore) credsProvider).setCredentials(new AuthScope(host), credentials);
}
use of org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider in project wildfly-clustering-spring-session by wildfly-clustering.
the class AuthSmokeITCase method createClient.
private static CloseableHttpClient createClient(URL url1, URL url2) {
CredentialsStore provider = new BasicCredentialsProvider();
Credentials credentials = new UsernamePasswordCredentials("admin", "password".toCharArray());
provider.setCredentials(new AuthScope(url1.getHost(), url1.getPort()), credentials);
provider.setCredentials(new AuthScope(url2.getHost(), url2.getPort()), credentials);
return HttpClients.custom().setDefaultCredentialsProvider(provider).build();
}
use of org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider in project wildfly-clustering-spring-session by wildfly-clustering.
the class AuthSmokeITCase method createClient.
private static CloseableHttpClient createClient(URL url1, URL url2) {
CredentialsStore provider = new BasicCredentialsProvider();
Credentials credentials = new UsernamePasswordCredentials("admin", "password".toCharArray());
provider.setCredentials(new AuthScope(url1.getHost(), url1.getPort()), credentials);
provider.setCredentials(new AuthScope(url2.getHost(), url2.getPort()), credentials);
return HttpClients.custom().setDefaultCredentialsProvider(provider).build();
}
use of org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider in project mercury by yellow013.
the class ClientProxyAuthentication method main.
public static void main(final String[] args) throws Exception {
final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope("localhost", 8888), new UsernamePasswordCredentials("squid", "squid".toCharArray()));
credsProvider.setCredentials(new AuthScope("httpbin.org", 80), new UsernamePasswordCredentials("user", "passwd".toCharArray()));
try (final CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build()) {
final HttpHost target = new HttpHost("http", "httpbin.org", 80);
final HttpHost proxy = new HttpHost("localhost", 8888);
final RequestConfig config = RequestConfig.custom().setProxy(proxy).build();
final HttpGet httpget = new HttpGet("/basic-auth/user/passwd");
httpget.setConfig(config);
System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri() + " via " + proxy);
try (final CloseableHttpResponse response = httpclient.execute(target, httpget)) {
System.out.println("----------------------------------------");
System.out.println(response.getCode() + " " + response.getReasonPhrase());
System.out.println(EntityUtils.toString(response.getEntity()));
}
}
}
use of org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider in project mercury by yellow013.
the class ClientAuthentication method main.
public static void main(final String[] args) throws Exception {
final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope("httpbin.org", 80), new UsernamePasswordCredentials("user", "passwd".toCharArray()));
try (final CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build()) {
final HttpGet httpget = new HttpGet("http://httpbin.org/basic-auth/user/passwd");
System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
try (final CloseableHttpResponse response = httpclient.execute(httpget)) {
System.out.println("----------------------------------------");
System.out.println(response.getCode() + " " + response.getReasonPhrase());
System.out.println(EntityUtils.toString(response.getEntity()));
}
}
}
Aggregations