Log.d(TAG, "Authentication required"); if (authState.getState() == AuthProtocolState.SUCCESS) { authStrategy.authFailed(host, authState.getAuthScheme(), context); switch (authState.getState()) { case CHALLENGED: case HANDSHAKE: Log.d(TAG, "Authentication succeeded"); authState.setState(AuthProtocolState.SUCCESS); authStrategy.authSucceeded(host, authState.getAuthScheme(), context); break; case SUCCESS: break; default: authState.setState(AuthProtocolState.UNCHALLENGED);
private static Principal getAuthPrincipal(final AuthStateHC4 authState) { final AuthScheme scheme = authState.getAuthScheme(); if (scheme != null && scheme.isComplete() && scheme.isConnectionBased()) { final Credentials creds = authState.getCredentials(); if (creds != null) { return creds.getUserPrincipal(); } } return null; }
/** * Invalidates the authentication state by resetting its parameters. * * @deprecated (4.2) use {@link #reset()} */ @Deprecated public void invalidate() { reset(); }
private void doPreemptiveAuth( final HttpHost host, final AuthScheme authScheme, final AuthStateHC4 authState, final CredentialsProvider credsProvider) { final String schemeName = authScheme.getSchemeName(); if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Re-using cached '" + schemeName + "' auth scheme for " + host); } final AuthScope authScope = new AuthScope(host.getHostName(), host.getPort(), AuthScope.ANY_REALM, schemeName); final Credentials creds = credsProvider.getCredentials(authScope); if (creds != null) { if ("BASIC".equalsIgnoreCase(authScheme.getSchemeName())) { authState.setState(AuthProtocolState.CHALLENGED); } else { authState.setState(AuthProtocolState.SUCCESS); } authState.update(authScheme, creds); } else { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "No credentials for preemptive authentication"); } } }
final AuthScheme authScheme = authState.getAuthScheme(); switch (authState.getState()) { case FAILURE: return false; case SUCCESS: authState.reset(); break; case CHALLENGED: authState.reset(); authState.setState(AuthProtocolState.FAILURE); return false; authStrategy.authFailed(host, authState.getAuthScheme(), context); authState.reset(); authState.setState(AuthProtocolState.FAILURE); return false; } else { authState.setState(AuthProtocolState.HANDSHAKE); return true; authState.reset(); authState.setState(AuthProtocolState.CHALLENGED); authState.update(authOptions); return true; } else { authState.reset();
final AuthStateHC4 authState, final HttpContext context) throws HttpException, IOException { AuthScheme authScheme = authState.getAuthScheme(); Credentials creds = authState.getCredentials(); switch (authState.getState()) { case FAILURE: return; final Queue<AuthOption> authOptions = authState.getAuthOptions(); if (authOptions != null) { while (!authOptions.isEmpty()) { authScheme = authOption.getAuthScheme(); creds = authOption.getCredentials(); authState.update(authScheme, creds); if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Generating response to an authentication challenge using "
targetAuthState = new AuthStateHC4(); context.setAttribute(HttpClientContext.TARGET_AUTH_STATE, targetAuthState); proxyAuthState = new AuthStateHC4(); context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, proxyAuthState); Log.d(TAG, "Target auth state: " + targetAuthState.getState()); Log.d(TAG, "Proxy auth state: " + proxyAuthState.getState()); } else { managedConn.close(); if (proxyAuthState.getState() == AuthProtocolState.SUCCESS && proxyAuthState.getAuthScheme() != null && proxyAuthState.getAuthScheme().isConnectionBased()) { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Resetting proxy auth state"); proxyAuthState.reset(); if (targetAuthState.getState() == AuthProtocolState.SUCCESS && targetAuthState.getAuthScheme() != null && targetAuthState.getAuthScheme().isConnectionBased()) { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Resetting target auth state"); targetAuthState.reset();
Log.d(TAG, "Resetting target auth state"); targetAuthState.reset(); final AuthScheme authScheme = proxyAuthState.getAuthScheme(); if (authScheme != null && authScheme.isConnectionBased()) { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Resetting proxy auth state"); proxyAuthState.reset();
private void setupContext(final HttpClientContext context) { if (context.getAttribute(HttpClientContext.TARGET_AUTH_STATE) == null) { context.setAttribute(HttpClientContext.TARGET_AUTH_STATE, new AuthStateHC4()); } if (context.getAttribute(HttpClientContext.PROXY_AUTH_STATE) == null) { context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, new AuthStateHC4()); } if (context.getAttribute(HttpClientContext.AUTHSCHEME_REGISTRY) == null) { context.setAttribute(HttpClientContext.AUTHSCHEME_REGISTRY, this.authSchemeRegistry); } if (context.getAttribute(HttpClientContext.COOKIESPEC_REGISTRY) == null) { context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry); } if (context.getAttribute(HttpClientContext.COOKIE_STORE) == null) { context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore); } if (context.getAttribute(HttpClientContext.CREDS_PROVIDER) == null) { context.setAttribute(HttpClientContext.CREDS_PROVIDER, this.credentialsProvider); } if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) { context.setAttribute(HttpClientContext.REQUEST_CONFIG, this.defaultConfig); } }
if (targetState != null && targetState.getState() == AuthProtocolState.UNCHALLENGED) { final AuthScheme authScheme = authCache.get(target); if (authScheme != null) { if (proxy != null && proxyState != null && proxyState.getState() == AuthProtocolState.UNCHALLENGED) { final AuthScheme authScheme = authCache.get(proxy); if (authScheme != null) {
/** * @since 4.3 */ public ProxyClient( final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory, final ConnectionConfig connectionConfig, final RequestConfig requestConfig) { super(); this.connFactory = connFactory != null ? connFactory : ManagedHttpClientConnectionFactory.INSTANCE; this.connectionConfig = connectionConfig != null ? connectionConfig : ConnectionConfig.DEFAULT; this.requestConfig = requestConfig != null ? requestConfig : RequestConfig.DEFAULT; this.httpProcessor = new ImmutableHttpProcessor( new RequestTargetHostHC4(), new RequestClientConnControl(), new RequestUserAgentHC4()); this.requestExec = new HttpRequestExecutor(); this.proxyAuthStrategy = new ProxyAuthenticationStrategy(); this.authenticator = new HttpAuthenticator(); this.proxyAuthState = new AuthStateHC4(); this.authSchemeRegistry = new AuthSchemeRegistry(); this.authSchemeRegistry.register(AuthSchemes.BASIC, new BasicSchemeFactoryHC4()); this.authSchemeRegistry.register(AuthSchemes.DIGEST, new DigestSchemeFactoryHC4()); this.authSchemeRegistry.register(AuthSchemes.NTLM, new NTLMSchemeFactory()); this.reuseStrategy = new DefaultConnectionReuseStrategyHC4(); }
/** * Assigns the given {@link AuthScheme authentication scheme}. * * @param authScheme the {@link AuthScheme authentication scheme} * * @deprecated (4.2) use {@link #update(AuthScheme, Credentials)} */ @Deprecated public void setAuthScheme(final AuthScheme authScheme) { if (authScheme == null) { reset(); return; } this.authScheme = authScheme; }