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; } }
localContext.setAuthCache( authCache ); } catch ( Exception e ) { return null;
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; }
context.setAuthCache(authCache);
protected HttpClientContext createPreemptiveAuthContext(Set<HttpHost> targetHosts) { HttpClientContext context = HttpClientContext.create(); context.setCredentialsProvider(httpClientConfig.getCredentialsProvider()); context.setAuthCache(createBasicAuthCache(targetHosts)); return context; }
protected HttpClientContext createContextInstance() { HttpClientContext context = HttpClientContext.create(); context.setCredentialsProvider(httpClientContextTemplate.getCredentialsProvider()); context.setAuthCache(httpClientContextTemplate.getAuthCache()); return context; }
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 BasicScheme basicScheme = new BasicScheme(); authCache.put(getHost(request), basicScheme); context.setAuthCache(authCache);
authCache.put(target, new BasicScheme()); clientContext = HttpClientContext.create(); clientContext.setAuthCache(authCache);
localContext.setAuthCache( authCache ); httpResponse = httpClient.execute( target, method, localContext ); } else {
localContext.setAuthCache( authCache ); httpResponse = httpClient.execute( target, post, localContext ); } else {
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.put(new HttpHost(urlHost, urlPort, urlProtocol), authScheme); HttpClientContext localContext = HttpClientContext.create(); localContext.setAuthCache(authCache); httpContext = localContext;
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; }
this.httpContext = HttpClientContext.create(); this.httpContext.setCredentialsProvider(provider); this.httpContext.setAuthCache(authCache);
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); } } }