protected HttpClientContext createContextInstance() { HttpClientContext context = HttpClientContext.create(); context.setCredentialsProvider(httpClientContextTemplate.getCredentialsProvider()); context.setAuthCache(httpClientContextTemplate.getAuthCache()); 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); }
@Test public void testAuthCredentialsSchemeWithoutSSL() { slaveServer.setUsername( "admin" ); slaveServer.setPassword( "password" ); slaveServer.setHostname( "localhost" ); slaveServer.setPort( "8080" ); slaveServer.setSslMode( false ); AuthCache cache = slaveServer.getAuthContext().getAuthCache(); assertNull( cache.get( new HttpHost( "localhost", 8080, "https" ) ) ); assertNotNull( cache.get( new HttpHost( "localhost", 8080, "http" ) ) ); }
@Test public void testAuthCredentialsSchemeWithSSL() { slaveServer.setUsername( "admin" ); slaveServer.setPassword( "password" ); slaveServer.setHostname( "localhost" ); slaveServer.setPort( "8443" ); slaveServer.setSslMode( true ); AuthCache cache = slaveServer.getAuthContext().getAuthCache(); assertNotNull( cache.get( new HttpHost( "localhost", 8443, "https" ) ) ); assertNull( cache.get( new HttpHost( "localhost", 8443, "http" ) ) ); }
@Override public void authFailed(final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) { Objects.requireNonNull(authhost, "Authentication host must be present"); Objects.requireNonNull(context, "HTTP context must be present"); LOG.debug("HTTP Signature authentication failed"); final HttpClientContext clientContext = HttpClientContext.adapt(context); final AuthCache authCache = clientContext.getAuthCache(); if (authCache != null) { if (LOG.isDebugEnabled()) { LOG.debug("Clearing cached auth scheme for " + authhost); } authCache.remove(authhost); } } }
protected HttpClientContext createContextInstance() { HttpClientContext context = HttpClientContext.create(); context.setCredentialsProvider(httpClientContextTemplate.getCredentialsProvider()); context.setAuthCache(httpClientContextTemplate.getAuthCache()); return context; }
public void authFailed( final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) { Args.notNull(authhost, "Host"); Args.notNull(context, "HTTP context"); final HttpClientContext clientContext = HttpClientContext.adapt(context); final AuthCache authCache = clientContext.getAuthCache(); if (authCache != null) { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Clearing cached auth scheme for " + authhost); } authCache.remove(authhost); } }
public void authFailed( final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) { Args.notNull(authhost, "Host"); Args.notNull(context, "HTTP context"); final HttpClientContext clientContext = HttpClientContext.adapt(context); final AuthCache authCache = clientContext.getAuthCache(); if (authCache != null) { if (this.log.isDebugEnabled()) { this.log.debug("Clearing cached auth scheme for " + authhost); } authCache.remove(authhost); } }
@Override public void authFailed( final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) { Args.notNull(authhost, "Host"); Args.notNull(context, "HTTP context"); final HttpClientContext clientContext = HttpClientContext.adapt(context); final AuthCache authCache = clientContext.getAuthCache(); if (authCache != null) { if (this.log.isDebugEnabled()) { this.log.debug("Clearing cached auth scheme for " + authhost); } authCache.remove(authhost); } }
public void enablePreemptiveAuthentication(String hostname, int httpPort, int httpsPort, Charset credentialsCharset) { AuthCache cache = this.context.getAuthCache(); if (cache == null) { // Add AuthCache to the execution context cache = new BasicAuthCache(); this.context.setAuthCache(cache); } // Generate Basic preemptive scheme object and stick it to the local execution context BasicScheme basicAuth = new BasicScheme(credentialsCharset); // Configure HttpClient to authenticate preemptively by prepopulating the authentication data cache. cache.put(new HttpHost(hostname, httpPort, "http"), basicAuth); cache.put(new HttpHost(hostname, httpsPort, "https"), basicAuth); }
@Override public void authFailed( final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) { Args.notNull(authhost, "Host"); Args.notNull(context, "HTTP context"); final HttpClientContext clientContext = HttpClientContext.adapt(context); final AuthCache authCache = clientContext.getAuthCache(); if (authCache != null) { if (this.log.isDebugEnabled()) { this.log.debug("Clearing cached auth scheme for " + authhost); } authCache.remove(authhost); } }
@Override public void authFailed( final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) { Args.notNull(authhost, "Host"); Args.notNull(context, "HTTP context"); final HttpClientContext clientContext = HttpClientContext.adapt(context); final AuthCache authCache = clientContext.getAuthCache(); if (authCache != null) { if (this.log.isDebugEnabled()) { this.log.debug("Clearing cached auth scheme for " + authhost); } authCache.remove(authhost); } }
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); }
@Override public void authFailed( final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) { Args.notNull(authhost, "Host"); Args.notNull(context, "HTTP context"); final HttpClientContext clientContext = HttpClientContext.adapt(context); final AuthCache authCache = clientContext.getAuthCache(); if (authCache != null) { if (this.log.isDebugEnabled()) { this.log.debug("Clearing cached auth scheme for " + authhost); } authCache.remove(authhost); } }
@Override public void authFailed( final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) { Args.notNull(authhost, "Host"); Args.notNull(context, "HTTP context"); final HttpClientContext clientContext = HttpClientContext.adapt(context); final AuthCache authCache = clientContext.getAuthCache(); if (authCache != null) { if (this.log.isDebugEnabled()) { this.log.debug("Clearing cached auth scheme for " + authhost); } authCache.remove(authhost); } }
public void authSucceeded( final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) { Args.notNull(authhost, "Host"); Args.notNull(authScheme, "Auth scheme"); Args.notNull(context, "HTTP context"); final HttpClientContext clientContext = HttpClientContext.adapt(context); if (isCachable(authScheme)) { AuthCache authCache = clientContext.getAuthCache(); if (authCache == null) { authCache = new BasicAuthCache(); clientContext.setAuthCache(authCache); } if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Caching '" + authScheme.getSchemeName() + "' auth scheme for " + authhost); } authCache.put(authhost, authScheme); } }
@Override public void authSucceeded( final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) { Args.notNull(authhost, "Host"); Args.notNull(authScheme, "Auth scheme"); Args.notNull(context, "HTTP context"); final HttpClientContext clientContext = HttpClientContext.adapt(context); if (isCachable(authScheme)) { AuthCache authCache = clientContext.getAuthCache(); if (authCache == null) { authCache = new BasicAuthCache(); clientContext.setAuthCache(authCache); } if (this.log.isDebugEnabled()) { this.log.debug("Caching '" + authScheme.getSchemeName() + "' auth scheme for " + authhost); } authCache.put(authhost, authScheme); } }
@Override public void authSucceeded( final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) { Args.notNull(authhost, "Host"); Args.notNull(authScheme, "Auth scheme"); Args.notNull(context, "HTTP context"); final HttpClientContext clientContext = HttpClientContext.adapt(context); if (isCachable(authScheme)) { AuthCache authCache = clientContext.getAuthCache(); if (authCache == null) { authCache = new BasicAuthCache(); clientContext.setAuthCache(authCache); } if (this.log.isDebugEnabled()) { this.log.debug("Caching '" + authScheme.getSchemeName() + "' auth scheme for " + authhost); } authCache.put(authhost, authScheme); } }
@Override public void authSucceeded( final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) { Args.notNull(authhost, "Host"); Args.notNull(authScheme, "Auth scheme"); Args.notNull(context, "HTTP context"); final HttpClientContext clientContext = HttpClientContext.adapt(context); if (isCachable(authScheme)) { AuthCache authCache = clientContext.getAuthCache(); if (authCache == null) { authCache = new BasicAuthCache(); clientContext.setAuthCache(authCache); } if (this.log.isDebugEnabled()) { this.log.debug("Caching '" + authScheme.getSchemeName() + "' auth scheme for " + authhost); } authCache.put(authhost, authScheme); } }
private void copyContextPrototype( final HttpClientContext prototype, final HttpClientContext target ) { target.setRequestConfig( prototype.getRequestConfig() ); target.setAuthCache( prototype.getAuthCache() ); target.setAuthSchemeRegistry( prototype.getAuthSchemeRegistry() ); target.setCookieSpecRegistry( prototype.getCookieSpecRegistry() ); target.setCookieStore( prototype.getCookieStore() ); target.setCredentialsProvider( prototype.getCredentialsProvider() ); target.setUserToken( prototype.getUserToken() ); }