public class DigestChallengeResponse
extends java.lang.Object
Authorization HTTP request header. Once the client has
received a HTTP Digest challenge from the server this header should be included in all subsequent
requests to authorize the client.
Instances of this class is normally created as a response to an incoming challenge using
responseTo(DigestChallenge). To generate the Authorization header, som
additional values must be set:
username and password for
authentication.digestUri used in the HTTP request.request method of the request, such as "GET" or "POST".
Here is an example of how to create a response:
DigestChallengeResponse response = DigestChallengeResponse.responseTo(challenge)
.username("user")
.password("passwd")
.digestUri("/example")
.requestMethod("GET");
Each time the challenge response is reused the nonce count must be increased by one, see
incrementNonceCount().
MD5 algorithm is supported, not MD5-sess.qop is always set to auth. The value from the challenge is not used.
auth-int qop is not supported.| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
HTTP_HEADER_AUTHORIZATION
The name of the HTTP request header ("Authorization").
|
| Constructor and Description |
|---|
DigestChallengeResponse()
Creates an empty challenge response.
|
| Modifier and Type | Method and Description |
|---|---|
DigestChallengeResponse |
algorithm(java.lang.String algorithm)
Sets the
algorithm directive, which must be the same as the algorithm directive
of the challenge. |
DigestChallengeResponse |
challenge(DigestChallenge challenge)
Sets the values of the
realm, nonce, opaque, and algorithm
directives based on a challenge. |
DigestChallengeResponse |
clientNonce(java.lang.String clientNonce)
Sets the
cnonce directive, which is a random string generated by the client that will
be included in the challenge response hash. |
DigestChallengeResponse |
digestUri(java.lang.String digestUri)
Sets the
digest-uri directive, which must be exactly the same as the
Request-URI of the Request-Line of the HTTP request. |
java.lang.String |
getAlgorithm()
Returns the value of the
algorithm directive. |
java.lang.String |
getClientNonce()
Returns the value of the
cnonce directive. |
java.lang.String |
getDigestUri()
Returns the value of the
digest-uri directive. |
java.lang.String |
getHeaderValue()
Returns the
credentials, that is, the string to set in the Authorization
HTTP request header. |
java.lang.String |
getNonce()
Returns the unquoted value of the
nonce directive |
int |
getNonceCount()
Returns the integer representation of the
nonce-count directive. |
java.lang.String |
getOpaque()
Returns the the unquoted value of the
opaque directive, or null. |
java.lang.String |
getPassword()
Returns the password to use for authentication.
|
java.lang.String |
getQuotedNonce()
Returns the quoted value of the
nonce directive. |
java.lang.String |
getQuotedOpaque()
Returns the the quoted value of the
opaque directive, or null. |
java.lang.String |
getQuotedRealm()
Returns the quoted value of the
realm directive. |
java.lang.String |
getRealm()
Returns the unquoted value of the
realm directive. |
java.lang.String |
getRequestMethod()
Returns the HTTP method of the request.
|
java.lang.String |
getUsername()
Returns the username to use for authentication.
|
DigestChallengeResponse |
incrementNonceCount()
Increments the value of the
nonce-count by one. |
DigestChallengeResponse |
nonce(java.lang.String unquotedNonce)
Sets the
nonce directive, which must be the same as the nonce directive of the
challenge. |
DigestChallengeResponse |
nonceCount(int nonceCount)
Sets the integer representation of the
nonce-count directive, which indicates how many
times this a challenge response with this nonce has been used. |
DigestChallengeResponse |
opaque(java.lang.String unquotedOpaque)
Sets the
opaque directive, which must be the same as the opaque directive of
the challenge. |
DigestChallengeResponse |
password(java.lang.String password)
Sets the password to use for authentication.
|
DigestChallengeResponse |
quotedNonce(java.lang.String quotedNonce)
Sets the
nonce directive, which must be the same as the nonce directive of the
challenge. |
DigestChallengeResponse |
quotedOpaque(java.lang.String quotedOpaque)
Sets the
opaque directive, which must be the same as the opaque directive of
the challenge. |
DigestChallengeResponse |
quotedRealm(java.lang.String quotedRealm)
Sets the
realm directive, which must be the same as the realm directive of
the challenge. |
DigestChallengeResponse |
realm(java.lang.String unquotedRealm)
Sets the
realm directive, which must be the same as the realm directive of
the challenge. |
DigestChallengeResponse |
requestMethod(java.lang.String requestMethod)
Sets the HTTP method of the request (GET, POST, etc).
|
DigestChallengeResponse |
resetNonceCount()
Sets the value of the
nonce-count to one. |
static DigestChallengeResponse |
responseTo(DigestChallenge challenge)
Creates a digest challenge response, setting the values of the
realm, nonce,
opaque, and algorithm directives based on a challenge. |
DigestChallengeResponse |
username(java.lang.String username)
Sets the username to use for authentication.
|
public static final java.lang.String HTTP_HEADER_AUTHORIZATION
public DigestChallengeResponse()
public static DigestChallengeResponse responseTo(DigestChallenge challenge)
realm, nonce,
opaque, and algorithm directives based on a challenge.challenge - the challengepublic DigestChallengeResponse algorithm(java.lang.String algorithm)
algorithm directive, which must be the same as the algorithm directive
of the challenge. The only value currently supported is "MD5".algorithm - the value of the algorithm directivegetAlgorithm(),
Section 3.2.2 of RFC 2617public java.lang.String getAlgorithm()
algorithm directive.algorithm directivealgorithm(String)public DigestChallengeResponse username(java.lang.String username)
username - the usernamegetUsername(),
Section 3.2.2 of RFC 2617public java.lang.String getUsername()
username(String)public DigestChallengeResponse password(java.lang.String password)
password - the passwordgetPassword()public java.lang.String getPassword()
password(String)public DigestChallengeResponse clientNonce(java.lang.String clientNonce)
cnonce directive, which is a random string generated by the client that will
be included in the challenge response hash.
There is normally no need to manually set the client nonce since it will have a default value of a randomly generated string.
clientNonce - The unquoted value of the cnonce directive.getClientNonce(),
Section 3.2.2 of RFC 2617public java.lang.String getClientNonce()
cnonce directive.
Unless overridden by calling clientNonce(String), the cnonce directive is
set to a randomly generated string.
cnonce directiveclientNonce(String)public DigestChallengeResponse quotedNonce(java.lang.String quotedNonce)
nonce directive, which must be the same as the nonce directive of the
challenge.
Setting the nonce directive resets the nonce count to one.
quotedNonce - the quoted value of the nonce directivegetQuotedNonce(),
nonce(String),
getNonce(),
Section 3.2.2 of RFC 2617public java.lang.String getQuotedNonce()
nonce directive.nonce directivequotedNonce(String),
nonce(String),
getNonce()public DigestChallengeResponse nonce(java.lang.String unquotedNonce)
nonce directive, which must be the same as the nonce directive of the
challenge.
Setting the nonce directive resets the nonce count to one.
unquotedNonce - the unquoted value of the nonce directivegetNonce(),
quotedNonce(String),
getQuotedNonce(),
Section 3.2.2 of RFC 2617public java.lang.String getNonce()
nonce directivenonce directivenonce(String),
quotedNonce(String),
getQuotedNonce()public DigestChallengeResponse nonceCount(int nonceCount)
nonce-count directive, which indicates how many
times this a challenge response with this nonce has been used.
This is useful when using a challenge response from a previous challenge when sending a request. For each time a challenge response is used, the nonce count should be increased by one.
nonceCount - integer representation of the nonce-count directivegetNonceCount(),
resetNonceCount(),
incrementNonceCount(),
Section 3.2.2 of RFC 2617public DigestChallengeResponse incrementNonceCount()
nonce-count by one.nonceCount(int),
getNonceCount(),
resetNonceCount()public DigestChallengeResponse resetNonceCount()
nonce-count to one.nonceCount(int),
getNonceCount(),
incrementNonceCount()public int getNonceCount()
nonce-count directive.nonce-count directivenonceCount(int),
resetNonceCount(),
incrementNonceCount()public DigestChallengeResponse quotedOpaque(java.lang.String quotedOpaque)
opaque directive, which must be the same as the opaque directive of
the challenge.quotedOpaque - the quoted value of the opaque directive, or null if no
opaque directive should be included in the challenge responsegetQuotedOpaque(),
opaque(String),
getOpaque(),
Section 3.2.2 of RFC 2617public java.lang.String getQuotedOpaque()
opaque directive, or null.opaque directive, or null if the opaque is not setquotedOpaque(String),
opaque(String),
getOpaque()public DigestChallengeResponse opaque(java.lang.String unquotedOpaque)
opaque directive, which must be the same as the opaque directive of
the challenge.
Note: Since the value of the opaque directive is always received from a challenge
quoted it is normally better to use the quotedOpaque(String) method to avoid
unnecessary quoting/unquoting.
unquotedOpaque - the unquoted value of the opaque directive, or null if no
opaque directive should be included in the challenge responsegetOpaque(),
quotedOpaque(String),
getQuotedOpaque(),
Section 3.2.2 of RFC 2617public java.lang.String getOpaque()
opaque directive, or null.opaque directive, or null if the opaque is not setopaque(String),
quotedOpaque(String),
getQuotedOpaque()public DigestChallengeResponse digestUri(java.lang.String digestUri)
digest-uri directive, which must be exactly the same as the
Request-URI of the Request-Line of the HTTP request.
The digest URI is explained in Section 3.2.2 of RFC 2617, and refers to the explanation of Request-URI found in Section 5.1.2 of RFC 2616.
Examples: If the Request-Line is
GET http://www.w3.org/pub/WWW/TheProject.html HTTP/1.1the
Request-URI (and digest-uri) is "http://www.w3.org/pub/WWW/TheProject.html". If Request-Line is
GET /pub/WWW/TheProject.html HTTP/1.1the
Request-URI is "/pub/WWW/TheProject.html".
This can be problematic since depending on the HTTP stack being used the Request-Line
and Request-URI values may not be accessible. If in doubt, a sensible guess is to set
the digest-uri to the path part of the URL being requested, for instance using
getPath() in the URL class.
digestUri - the value of the digest-uri directivegetDigestUri()public java.lang.String getDigestUri()
digest-uri directive.digest-uri directivedigestUri(String)public DigestChallengeResponse quotedRealm(java.lang.String quotedRealm)
realm directive, which must be the same as the realm directive of
the challenge.quotedRealm - the quoted value of the realm directivegetQuotedRealm(),
realm(String),
getRealm(),
Section 3.2.1 of RFC 2617,
Section 3.2.2 of RFC 2617public java.lang.String getQuotedRealm()
realm directive.realm directivequotedRealm(String),
realm(String),
getRealm()public DigestChallengeResponse realm(java.lang.String unquotedRealm)
realm directive, which must be the same as the realm directive of
the challenge.unquotedRealm - the unquoted value of the realm directivegetRealm(),
quotedRealm(String),
getQuotedRealm(),
Section 3.2.1 of RFC 2617,
Section 3.2.2 of RFC 2617public java.lang.String getRealm()
realm directive.realm directiverealm(String),
quotedRealm(String),
getQuotedRealm()public DigestChallengeResponse requestMethod(java.lang.String requestMethod)
requestMethod - the request methodgetRequestMethod(),
Section 5.1.1 of RFC 2616public java.lang.String getRequestMethod()
requestMethod(String)public DigestChallengeResponse challenge(DigestChallenge challenge)
realm, nonce, opaque, and algorithm
directives based on a challenge.challenge - the challengepublic java.lang.String getHeaderValue()
credentials, that is, the string to set in the Authorization
HTTP request header.
Before calling this method, the following values and directives must be set:
Authorization HTTP request headerjava.lang.IllegalStateException - if any of the mandatory directives and values listed above has
not been set