use of org.apache.hc.client5.http.auth.AuthScope in project geo-platform by geosdi.
the class DigestPreemptiveSecurityConnector method bindCredentials.
/**
* @param targetHost
* @param targetURI
* @throws Exception
*/
@Override
protected void bindCredentials(@Nonnull(when = NEVER) HttpHost targetHost, @Nonnull(when = NEVER) URI targetURI) throws Exception {
super.bindCredentials(targetHost, targetURI);
BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope(targetHost), this.usernamePasswordCredentials);
localContext.setCredentialsProvider(credentialsProvider);
}
use of org.apache.hc.client5.http.auth.AuthScope 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.auth.AuthScope 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.auth.AuthScope 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()));
}
}
}
use of org.apache.hc.client5.http.auth.AuthScope in project mercury by yellow013.
the class AsyncClientAuthentication 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()));
final CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom().setDefaultCredentialsProvider(credsProvider).build();
httpclient.start();
final SimpleHttpRequest request = SimpleRequestBuilder.get("http://httpbin.org/basic-auth/user/passwd").build();
System.out.println("Executing request " + request);
final Future<SimpleHttpResponse> future = httpclient.execute(SimpleRequestProducer.create(request), SimpleResponseConsumer.create(), new FutureCallback<SimpleHttpResponse>() {
@Override
public void completed(final SimpleHttpResponse response) {
System.out.println(request + "->" + new StatusLine(response));
System.out.println(response.getBody());
}
@Override
public void failed(final Exception ex) {
System.out.println(request + "->" + ex);
}
@Override
public void cancelled() {
System.out.println(request + " cancelled");
}
});
future.get();
System.out.println("Shutting down");
httpclient.close(CloseMode.GRACEFUL);
}
Aggregations