Code example for AuthState

Methods: getAuthScheme, getCredentials, isValid, setAuthScheme

0
                        return null; 
                    } 
                } 
                updateAuthState(this.targetAuthState, target, credsProvider);
                 
                if (this.targetAuthState.getCredentials() != null) {
                    // Re-try the same request via the same route 
                    return roureq;
                } else { 
                    return null; 
                } 
            } else { 
                // Reset target auth scope 
                this.targetAuthState.setAuthScope(null);
            } 
             
            if (this.proxyAuthHandler.isAuthenticationRequested(response, context)) {
 
                this.log.debug("Proxy requested authentication");
                Map<String, Header> challenges = this.proxyAuthHandler.getChallenges(
                        response, context);
                try { 
                    processChallenges(challenges, 
                            this.proxyAuthState, this.proxyAuthHandler, 
                            response, context);
                } catch (AuthenticationException ex) {
                    if (this.log.isWarnEnabled()) {
                        this.log.warn("Authentication error: " +  ex.getMessage());
                        return null; 
                    } 
                } 
                updateAuthState(this.proxyAuthState, proxy, credsProvider);
                 
                if (this.proxyAuthState.getCredentials() != null) {
                    // Re-try the same request via the same route 
                    return roureq;
                } else { 
                    return null; 
                } 
            } else { 
                // Reset proxy auth scope 
                this.proxyAuthState.setAuthScope(null);
            } 
        } 
        return null; 
    } // handleResponse 
 
 
    /** 
     * Shuts down the connection. 
     * This method is called from a <code>catch</code> block in 
     * {@link #execute execute} during exception handling. 
     */ 
    private void abortConnection() { 
        ManagedClientConnection mcc = managedConn;
        if (mcc != null) {
            // we got here as the result of an exception 
            // no response will be returned, release the connection 
            managedConn = null;
            try { 
                mcc.abortConnection();
            } catch (IOException ex) {
                if (this.log.isDebugEnabled()) {
                    this.log.debug(ex.getMessage(), ex);
                } 
            } 
            // ensure the connection manager properly releases this connection 
            try { 
                mcc.releaseConnection();
            } catch(IOException ignored) {
                this.log.debug("Error releasing connection", ignored);
            } 
        } 
    } // abortConnection 
 
 
    private void processChallenges( 
            final Map<String, Header> challenges, 
            final AuthState authState,
            final AuthenticationHandler authHandler,
            final HttpResponse response, 
            final HttpContext context) 
                throws MalformedChallengeException, AuthenticationException { 
         
        AuthScheme authScheme = authState.getAuthScheme();
        if (authScheme == null) {
            // Authentication not attempted before 
            authScheme = authHandler.selectScheme(challenges, response, context);
            authState.setAuthScheme(authScheme);
        } 
        String id = authScheme.getSchemeName();
 
        Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH));
        if (challenge == null) {
            throw new AuthenticationException(id + 
                " authorization challenge expected, but not found"); 
        } 
        authScheme.processChallenge(challenge);
        this.log.debug("Authorization challenge processed");
    } 
     
     
    private void updateAuthState( 
            final AuthState authState, 
            final HttpHost host,
            final CredentialsProvider credsProvider) {
         
        if (!authState.isValid()) {
            return; 
        } 
         
        String hostname = host.getHostName();
        int port = host.getPort();