Top Description Fields Constructors Methods
org.apache.http.impl.auth

public Class DigestScheme

extends RFC2617Scheme
Class Inheritance
Imports
java.io.IOException, java.nio.charset.Charset, java.security.MessageDigest, .SecureRandom, java.util.ArrayList, .Formatter, .HashSet, .List, .Locale, .Set, .StringTokenizer, org.apache.http.Consts, .Header, .HttpEntity, .HttpEntityEnclosingRequest, .HttpRequest, org.apache.http.auth.AUTH, .AuthenticationException, .ChallengeState, .Credentials, .MalformedChallengeException, org.apache.http.message.BasicHeaderValueFormatter, .BasicNameValuePair, .BufferedHeader, org.apache.http.protocol.BasicHttpContext, .HttpContext, org.apache.http.util.Args, .CharArrayBuffer, .EncodingUtils

Digest authentication scheme as defined in RFC 2617. Both MD5 (default) and MD5-sess are supported. Currently only qop=auth or no qop is supported. qop=auth-int is unsupported. If auth and auth-int are provided, auth is used.

Since the digest username is included as clear text in the generated Authentication header, the charset of the username must be compatible with the HTTP element charset used by the connection.

Since
4.0

Field Summary

Modifier and TypeField and Description
private String
private String
private String
private boolean
complete

Whether the digest authentication process is complete

private static final char[]
HEXADECIMAL

Hexa values used when creating 32 character long digest in HTTP DigestScheme in case of authentication.

private String
private long
private static final int
private static final int
private static final int
private static final int
private static final long

Constructor Summary

AccessConstructor and Description
public
DigestScheme(final Charset credentialsCharset)

public
DigestScheme(final ChallengeState challengeState)

Deprecated (4.3) do not use.
Creates an instance of DigestScheme with the given challenge state.
public

Method Summary

Modifier and TypeMethod and Description
public Header
authenticate(final Credentials
The set of credentials to be used for athentication
credentials
,
final HttpRequest
The request being authenticated
request
)

Implements org.apache.http.auth.AuthScheme.authenticate.

Produces an authorization string for the given set of Credentials.
public Header

Returns:

a digest authorization string
authenticate
(final Credentials
A set of credentials to be used for athentication
credentials
,
final HttpRequest
The request being authenticated
request
,
final HttpContext
HTTP context
context
)

Overrides org.apache.http.impl.auth.AuthSchemeBase.authenticate.

Implements org.apache.http.auth.ContextAwareAuthScheme.authenticate.

Produces a digest authorization string for the given set of Credentials, method name and URI.
public static String

Returns:

The cnonce value as String.
createCnonce
()

Creates a random cnonce value based on the current time.

private Header

Returns:

The digest-response as String.
createDigestHeader
(final Credentials
User credentials
credentials
,
final HttpRequest request)

Creates digest-response header as defined in RFC2617.

private static MessageDigest
pack-priv static String

Returns:

encoded MD5, or null if encoding failed
encode
(final byte[]
array containing the digest
binaryData
)

Encodes the 128 bit (16 bytes) MD5 digest into a 32 characters long String according to RFC 2617.

pack-priv String
pack-priv String
pack-priv String
public String

Returns:

digest
getSchemeName
()

Implements org.apache.http.auth.AuthScheme.getSchemeName.

Returns textual designation of the digest authentication scheme.
public boolean

Returns:

true if Digest authorization has been processed, false otherwise.
isComplete
()

Implements org.apache.http.auth.AuthScheme.isComplete.

Tests if the Digest authentication process has been completed.
public boolean

Returns:

false.
isConnectionBased
()

Implements org.apache.http.auth.AuthScheme.isConnectionBased.

Returns false.
public void
overrideParamter(final String name, final String value)

public void
processChallenge(final Header
the challenge header
header
)

Overrides org.apache.http.impl.auth.AuthSchemeBase.processChallenge.

Implements org.apache.http.auth.AuthScheme.processChallenge.

Processes the Digest challenge.
public String
toString()

Overrides org.apache.http.impl.auth.AuthSchemeBase.toString.

Returns a string representation of the object.
Inherited from org.apache.http.impl.auth.RFC2617Scheme:
getCredentialsCharsetgetCredentialsCharsetgetParametergetParametersgetRealmparseChallenge

Field Detail

a1back to summary
private String a1
a2back to summary
private String a2
cnonceback to summary
private String cnonce
completeback to summary
private boolean complete

Whether the digest authentication process is complete

HEXADECIMALback to summary
private static final char[] HEXADECIMAL

Hexa values used when creating 32 character long digest in HTTP DigestScheme in case of authentication.

See Also
encode(byte[])
lastNonceback to summary
private String lastNonce
nounceCountback to summary
private long nounceCount
QOP_AUTHback to summary
private static final int QOP_AUTH
QOP_AUTH_INTback to summary
private static final int QOP_AUTH_INT
QOP_MISSINGback to summary
private static final int QOP_MISSING
QOP_UNKNOWNback to summary
private static final int QOP_UNKNOWN
serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.http.impl.auth.RFC2617Scheme.serialVersionUID.

Constructor Detail

DigestSchemeback to summary
public DigestScheme(final Charset credentialsCharset)
Since
4.3
DigestSchemeback to summary
public DigestScheme(final ChallengeState challengeState)

Deprecated

(4.3) do not use.

Creates an instance of DigestScheme with the given challenge state.

Annotations
@Deprecated
Since
4.2
DigestSchemeback to summary
public DigestScheme()

Method Detail

authenticateback to summary
public Header authenticate(final Credentials credentials, final HttpRequest request) throws AuthenticationException

Implements org.apache.http.auth.AuthScheme.authenticate.

Doc from org.apache.http.auth.AuthScheme.authenticate.

Produces an authorization string for the given set of Credentials.

Parameters
credentials:Credentials

The set of credentials to be used for athentication

request:HttpRequest

The request being authenticated

Returns:Header

the authorization string

Annotations
@Override
@Deprecated
Exceptions
AuthenticationException:
if authorization string cannot be generated due to an authentication failure
authenticateback to summary
public Header authenticate(final Credentials credentials, final HttpRequest request, final HttpContext context) throws AuthenticationException

Overrides org.apache.http.impl.auth.AuthSchemeBase.authenticate.

Implements org.apache.http.auth.ContextAwareAuthScheme.authenticate.

Produces a digest authorization string for the given set of Credentials, method name and URI.

Parameters
credentials:Credentials

A set of credentials to be used for athentication

request:HttpRequest

The request being authenticated

context:HttpContext

Doc from org.apache.http.auth.ContextAwareAuthScheme.authenticate.

HTTP context

Returns:Header

a digest authorization string

Annotations
@Override
Exceptions
AuthenticationException:
if authorization string cannot be generated due to an authentication failure
InvalidCredentialsException:
if authentication credentials are not valid or not applicable for this authentication scheme
createCnonceback to summary
public static String createCnonce()

Creates a random cnonce value based on the current time.

Returns:String

The cnonce value as String.

createDigestHeaderback to summary
private Header createDigestHeader(final Credentials credentials, final HttpRequest request) throws AuthenticationException

Creates digest-response header as defined in RFC2617.

Parameters
credentials:Credentials

User credentials

Returns:Header

The digest-response as String.

createMessageDigestback to summary
private static MessageDigest createMessageDigest(final String digAlg) throws UnsupportedDigestAlgorithmException
encodeback to summary
pack-priv static String encode(final byte[] binaryData)

Encodes the 128 bit (16 bytes) MD5 digest into a 32 characters long String according to RFC 2617.

Parameters
binaryData:byte[]

array containing the digest

Returns:String

encoded MD5, or null if encoding failed

getA1back to summary
pack-priv String getA1()
getA2back to summary
pack-priv String getA2()
getCnonceback to summary
pack-priv String getCnonce()
getSchemeNameback to summary
public String getSchemeName()

Implements org.apache.http.auth.AuthScheme.getSchemeName.

Returns textual designation of the digest authentication scheme.

Returns:String

digest

Annotations
@Override
isCompleteback to summary
public boolean isComplete()

Implements org.apache.http.auth.AuthScheme.isComplete.

Tests if the Digest authentication process has been completed.

Returns:boolean

true if Digest authorization has been processed, false otherwise.

Annotations
@Override
isConnectionBasedback to summary
public boolean isConnectionBased()

Implements org.apache.http.auth.AuthScheme.isConnectionBased.

Returns false. Digest authentication scheme is request based.

Returns:boolean

false.

Annotations
@Override
overrideParamterback to summary
public void overrideParamter(final String name, final String value)
processChallengeback to summary
public void processChallenge(final Header header) throws MalformedChallengeException

Overrides org.apache.http.impl.auth.AuthSchemeBase.processChallenge.

Implements org.apache.http.auth.AuthScheme.processChallenge.

Processes the Digest challenge.

Parameters
header:Header

the challenge header

Annotations
@Override
Exceptions
MalformedChallengeException:
is thrown if the authentication challenge is malformed
toStringback to summary
public String toString()

Overrides org.apache.http.impl.auth.AuthSchemeBase.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override