FileDocCategorySizeDatePackage
AuthSchemeBase.javaAPI DocAndroid 1.5 API4880Wed May 06 22:41:10 BST 2009org.apache.http.impl.auth

AuthSchemeBase

public abstract class AuthSchemeBase extends Object implements AuthScheme
Abstract authentication scheme class that serves as a basis for all authentication schemes supported by HttpClient. This class defines the generic way of parsing an authentication challenge. It does not make any assumptions regarding the format of the challenge nor does it impose any specific way of responding to that challenge.
author
Oleg Kalnichevski

Fields Summary
private boolean
proxy
Flag whether authenticating against a proxy.
Constructors Summary
public AuthSchemeBase()

        super();
    
Methods Summary
public booleanisProxy()
Returns true if authenticating against a proxy, false otherwise.

return
true if authenticating against a proxy, false otherwise

        return this.proxy;
    
protected abstract voidparseChallenge(org.apache.http.util.CharArrayBuffer buffer, int pos, int len)

public voidprocessChallenge(org.apache.http.Header header)
Processes the given challenge token. Some authentication schemes may involve multiple challenge-response exchanges. Such schemes must be able to maintain the state information when dealing with sequential challenges

param
header the challenge header
throws
MalformedChallengeException is thrown if the authentication challenge is malformed

        if (header == null) {
            throw new IllegalArgumentException("Header may not be null");
        }
        String authheader = header.getName();
        if (authheader.equalsIgnoreCase(AUTH.WWW_AUTH)) {
            this.proxy = false;
        } else if (authheader.equalsIgnoreCase(AUTH.PROXY_AUTH)) {
            this.proxy = true;
        } else {
            throw new MalformedChallengeException("Unexpected header name: " + authheader);
        }

        CharArrayBuffer buffer;
        int pos;
        if (header instanceof FormattedHeader) {
            buffer = ((FormattedHeader) header).getBuffer();
            pos = ((FormattedHeader) header).getValuePos();
        } else {
            String s = header.getValue();
            if (s == null) {
                throw new MalformedChallengeException("Header value is null");
            }
            buffer = new CharArrayBuffer(s.length());
            buffer.append(s);
            pos = 0;
        }
        while (pos < buffer.length() && HTTP.isWhitespace(buffer.charAt(pos))) {
            pos++;
        }
        int beginIndex = pos;
        while (pos < buffer.length() && !HTTP.isWhitespace(buffer.charAt(pos))) {
            pos++;
        }
        int endIndex = pos;
        String s = buffer.substring(beginIndex, endIndex);
        if (!s.equalsIgnoreCase(getSchemeName())) {
            throw new MalformedChallengeException("Invalid scheme identifier: " + s);
        }
        
        parseChallenge(buffer, pos, buffer.length());