Example usage for org.apache.http.auth AuthProtocolState equals

List of usage examples for org.apache.http.auth AuthProtocolState equals

Introduction

In this page you can find the example usage for org.apache.http.auth AuthProtocolState equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:com.joyent.http.signature.apache.httpclient.HttpSignatureAuthenticationStrategy.java

/**
 * Determines if the given HTTP response response represents
 * an authentication challenge that was sent back as a result
 * of authentication failure.//www  . j  av a2 s .c  o  m
 *
 * @param authHost authentication host.
 * @param response HTTP response.
 * @param context  HTTP context.
 * @return {@code true} if user authentication is required,
 *                      {@code false} otherwise.
 */
@Override
public boolean isAuthenticationRequested(final HttpHost authHost, final HttpResponse response,
        final HttpContext context) {
    final StatusLine line = response.getStatusLine();
    final int code = line.getStatusCode();
    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    final AuthState authState = clientContext.getTargetAuthState();
    final AuthProtocolState authProtocolState = authState.getState();

    if (code == HttpStatus.SC_UNAUTHORIZED) {
        if (authProtocolState.equals(AuthProtocolState.CHALLENGED)) {
            clientContext.getTargetAuthState().setState(AuthProtocolState.FAILURE);
            authFailed(authHost, authState.getAuthScheme(), context);
        }

        return true;
    }

    if (clientContext.getTargetAuthState() == null) {
        return true;
    }

    return false;
}