Better state handling in NegotiateScheme#authenticate
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1181015 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
90b6853111
commit
8f46fbacd8
|
@ -152,10 +152,12 @@ public class NegotiateScheme extends AuthSchemeBase {
|
|||
if (request == null) {
|
||||
throw new IllegalArgumentException("HTTP request may not be null");
|
||||
}
|
||||
if (state != State.CHALLENGE_RECEIVED) {
|
||||
throw new IllegalStateException(
|
||||
"Negotiation authentication process has not been initiated");
|
||||
}
|
||||
switch (state) {
|
||||
case UNINITIATED:
|
||||
throw new AuthenticationException("SPNEGO authentication has not been initiated");
|
||||
case FAILED:
|
||||
throw new AuthenticationException("SPNEGO authentication has failed");
|
||||
case CHALLENGE_RECEIVED:
|
||||
try {
|
||||
String key = null;
|
||||
if (isProxy()) {
|
||||
|
@ -245,11 +247,6 @@ public class NegotiateScheme extends AuthSchemeBase {
|
|||
}
|
||||
|
||||
state = State.TOKEN_GENERATED;
|
||||
String tokenstr = new String(Base64.encodeBase64(token, false));
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Sending response '" + tokenstr + "' back to the auth server");
|
||||
}
|
||||
return new BasicHeader("Authorization", "Negotiate " + tokenstr);
|
||||
} catch (GSSException gsse) {
|
||||
state = State.FAILED;
|
||||
if (gsse.getMajor() == GSSException.DEFECTIVE_CREDENTIAL
|
||||
|
@ -267,8 +264,16 @@ public class NegotiateScheme extends AuthSchemeBase {
|
|||
state = State.FAILED;
|
||||
throw new AuthenticationException(ex.getMessage());
|
||||
}
|
||||
case TOKEN_GENERATED:
|
||||
String tokenstr = new String(Base64.encodeBase64(token, false));
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Sending response '" + tokenstr + "' back to the auth server");
|
||||
}
|
||||
return new BasicHeader("Authorization", "Negotiate " + tokenstr);
|
||||
default:
|
||||
throw new IllegalStateException("Illegal state: " + state);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the authentication parameter with the given name, if available.
|
||||
|
|
Loading…
Reference in New Issue