List of usage examples for org.apache.http.impl.auth BasicScheme getSchemeName
public String getSchemeName()
From source file:io.kahu.hawaii.util.call.http.HttpRequestBuilder.java
private void addAuthentication(AbortableHttpRequest<T> request, URI uri) { if (credentials != null) { CredentialsProvider credentialsProvider = null; switch (credentials.getAuthenticationType()) { case BASIC: // fall-through to default default://from w ww.j av a 2s . c om BasicScheme authenticationScheme = new BasicScheme(); credentialsProvider = new BasicCredentialsProvider(); // Explicitly set the AuthScope to ANY_REALM in order to get // 'preemptive authentication' to work credentialsProvider.setCredentials( new AuthScope(uri.getHost(), uri.getPort(), AuthScope.ANY_REALM, authenticationScheme.getSchemeName()), new UsernamePasswordCredentials(credentials.getUsername(), credentials.getPassword())); // Create an auth cache for preemptive authentication. AuthCache authCache = new BasicAuthCache(); authCache.put(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()), authenticationScheme); request.getHttpClientContext().setAuthCache(authCache); break; } request.getHttpClientContext().setCredentialsProvider(credentialsProvider); } }
From source file:org.apache.abdera2.common.protocol.Session.java
public void usePreemptiveAuthentication(String target, String realm) throws URISyntaxException { AuthCache cache = (AuthCache) localContext.getAttribute(ClientContext.AUTH_CACHE); if (cache == null) { String host = AuthScope.ANY_HOST; int port = AuthScope.ANY_PORT; if (target != null) { URI uri = new URI(target); host = uri.getHost();//from w w w .jav a 2s. c o m port = uri.getPort(); } BasicScheme basicAuth = new BasicScheme(); HttpHost targetHost = new HttpHost(host, port, basicAuth.getSchemeName()); cache = new BasicAuthCache(); cache.put(targetHost, basicAuth); localContext.setAttribute(ClientContext.AUTH_CACHE, cache); } }