Example usage for org.apache.http.client AuthenticationStrategy isAuthenticationRequested

List of usage examples for org.apache.http.client AuthenticationStrategy isAuthenticationRequested

Introduction

In this page you can find the example usage for org.apache.http.client AuthenticationStrategy isAuthenticationRequested.

Prototype

boolean isAuthenticationRequested(HttpHost authhost, HttpResponse response, HttpContext context);

Source Link

Document

Determines if the given HTTP response response represents an authentication challenge that was sent back as a result of authentication failure.

Usage

From source file:org.callimachusproject.client.HttpAuthenticator.java

private boolean isAuthenticationRequested(final HttpHost host, final HttpResponse response,
        final AuthenticationStrategy authStrategy, final AuthState authState, final HttpContext context) {
    if (authStrategy.isAuthenticationRequested(host, response, context)) {
        this.log.debug("Authentication required");
        if (authState.getState() == AuthProtocolState.SUCCESS) {
            authStrategy.authFailed(host, authState.getAuthScheme(), context);
        }/* w w  w .  ja v a 2s . c  o  m*/
        return true;
    } else {
        switch (authState.getState()) {
        case CHALLENGED:
        case HANDSHAKE:
            this.log.debug("Authentication succeeded");
            authState.setState(AuthProtocolState.SUCCESS);
            authStrategy.authSucceeded(host, authState.getAuthScheme(), context);
            break;
        case SUCCESS:
            break;
        default:
            authState.setState(AuthProtocolState.UNCHALLENGED);
        }
        return false;
    }
}

From source file:org.apache.http.impl.auth.HttpAuthenticator.java

public boolean isAuthenticationRequested(final HttpHost host, final HttpResponse response,
        final AuthenticationStrategy authStrategy, final AuthState authState, final HttpContext context) {
    if (authStrategy.isAuthenticationRequested(host, response, context)) {
        this.log.debug("Authentication required");
        if (authState.getState() == AuthProtocolState.SUCCESS) {
            authStrategy.authFailed(host, authState.getAuthScheme(), context);
        }/*from   w w  w  . j av  a  2s. co  m*/
        return true;
    } else {
        switch (authState.getState()) {
        case CHALLENGED:
        case HANDSHAKE:
            this.log.debug("Authentication succeeded");
            authState.setState(AuthProtocolState.SUCCESS);
            authStrategy.authSucceeded(host, authState.getAuthScheme(), context);
            break;
        case SUCCESS:
            break;
        default:
            authState.setState(AuthProtocolState.UNCHALLENGED);
        }
        return false;
    }
}