private AuthCache createBasicAuthCache(Set<HttpHost> targetHosts) { AuthCache authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); for (HttpHost eachTargetHost : targetHosts) { authCache.put(eachTargetHost, basicAuth); } return authCache; }
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; } }
private void initHttpRestClient() { httpClient = new DefaultHttpClient(); restHost = new HttpHost(kaaRestHost, kaaRestPort, "http"); AuthCache authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); authCache.put(restHost, basicAuth); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials( new AuthScope(kaaRestHost, kaaRestPort, AuthScope.ANY_REALM), new UsernamePasswordCredentials(kaaRestUser, kaaRestPassword)); httpContext = new BasicHttpContext(); httpContext.setAttribute(ClientContext.AUTH_CACHE, authCache); httpContext.setAttribute(ClientContext.CREDS_PROVIDER, credsProvider); }
AuthCache authCache = new BasicAuthCache();
private HttpContext createHttpContext() { AuthCache authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); authCache.put(host, basicAuth); HttpClientContext context = HttpClientContext.create(); context.setCredentialsProvider(credsProvider); context.setAuthCache(authCache); return context; }
AuthCache authCache = new BasicAuthCache();
private HttpContext createContext() { final IpCamAuth auth = getAuth(); if (auth == null) { return null; } final URI uri = toURI(url); final HttpHost host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); final Credentials credentials = new UsernamePasswordCredentials(auth.getUserName(), auth.getPassword()); final CredentialsProvider provider = new BasicCredentialsProvider(); provider.setCredentials(AuthScope.ANY, credentials); final AuthCache cache = new BasicAuthCache(); cache.put(host, new BasicScheme()); final HttpClientContext context = HttpClientContext.create(); context.setCredentialsProvider(provider); context.setAuthCache(cache); return context; }
protected void populateHttpCredential(HttpHost host, AuthScheme authScheme, String user, String password) { UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(user, password); AuthCache authCache = httpClientContext.getAuthCache(); if (authCache == null) { authCache = new BasicAuthCache(); httpClientContext.setAuthCache(authCache); } authCache.put(host, authScheme); if (httpClientContext.getCredentialsProvider() == null) { httpClientContext.setCredentialsProvider(new BasicCredentialsProvider()); } httpClientContext.getCredentialsProvider().setCredentials(new AuthScope(host), credentials); }
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 ); }
private static void addPreemptiveAuthenticationProxy(HttpClientContext clientContext, HttpClientSettings settings) { if (settings.isPreemptiveBasicProxyAuth()) { HttpHost targetHost = new HttpHost(settings.getProxyHost(), settings .getProxyPort()); final CredentialsProvider credsProvider = newProxyCredentialsProvider(settings); // 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); clientContext.setCredentialsProvider(credsProvider); clientContext.setAuthCache(authCache); } } }
final HttpClientContext context = HttpClientContext.create(); if (preemptiveBasicAuth) { final AuthCache authCache = new BasicAuthCache(); final BasicScheme basicScheme = new BasicScheme(); authCache.put(getHost(request), basicScheme);
new AuthScope(target.getHostName(), target.getPort()), new UsernamePasswordCredentials(crowdProps.getApplicationName(), crowdProps.getApplicationPassword())); final AuthCache authCache = new BasicAuthCache(); authCache.put(target, new BasicScheme()); clientContext = HttpClientContext.create();
HttpHost target = new HttpHost( data.realProxyHost, data.realProxyPort, "http" ); AuthCache authCache = new BasicAuthCache();
HttpHost target = new HttpHost( data.realProxyHost, data.realProxyPort, "http" ); AuthCache authCache = new BasicAuthCache();
private HttpClient getHttpClient( HttpClientContext context ) { HttpClientManager.HttpClientBuilderFacade clientBuilder = HttpClientManager.getInstance().createBuilder(); String login = environmentSubstitute( meta.getHttpLogin() ); if ( StringUtils.isNotBlank( login ) ) { clientBuilder.setCredentials( login, Encr.decryptPasswordOptionallyEncrypted( environmentSubstitute( meta.getHttpPassword() ) ) ); } int proxyPort = 0; if ( StringUtils.isNotBlank( meta.getProxyHost() ) ) { proxyPort = Const.toInt( environmentSubstitute( meta.getProxyPort() ), 8080 ); clientBuilder.setProxy( meta.getProxyHost(), proxyPort ); } CloseableHttpClient httpClient = clientBuilder.build(); if ( proxyPort != 0 ) { // Preemptive authentication HttpHost target = new HttpHost( meta.getProxyHost(), proxyPort, "http" ); // 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 context.setAuthCache( authCache ); } return httpClient; }
AuthCache authCache = new BasicAuthCache(); AuthSchemeBase authScheme = a instanceof BasicAuth? new BasicScheme(): new DigestScheme();
/** * Gets the context. * * @param httpHost * the http host * @return the context */ public static HttpContext getContext(HttpHost httpHost) { AuthCache authCache = new BasicAuthCache(); authCache.put(httpHost, new BasicScheme()); HttpContext context = new BasicHttpContext(); context.setAttribute(ClientContext.AUTH_CACHE, authCache); return context; }
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; }
provider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password)); final HttpHost adminHost = new HttpHost(host, port, scheme); final AuthCache authCache = new BasicAuthCache(); authCache.put(adminHost, new BasicScheme());
private static void addPreemptiveAuthenticationProxy(HttpClientContext clientContext, HttpClientSettings settings) { if (settings.isPreemptiveBasicProxyAuth()) { HttpHost targetHost = new HttpHost(settings.getProxyHost(), settings .getProxyPort()); final CredentialsProvider credsProvider = newProxyCredentialsProvider(settings); // 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); clientContext.setCredentialsProvider(credsProvider); clientContext.setAuthCache(authCache); } } }