AuthSchemeBasepublic abstract class AuthSchemeBase extends Object implements AuthSchemeAbstract 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. |
Fields Summary |
---|
private boolean | proxyFlag whether authenticating against a proxy. |
Constructors Summary |
---|
public AuthSchemeBase()
super();
|
Methods Summary |
---|
public boolean | isProxy()Returns true if authenticating against a proxy, false
otherwise.
return this.proxy;
| protected abstract void | parseChallenge(org.apache.http.util.CharArrayBuffer buffer, int pos, int len)
| public void | processChallenge(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
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());
|
|