Top Description Inners Fields Constructors Methods
org.apache.hc.client5.http.impl.auth

public Class DigestScheme

extends Object
implements AuthScheme, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.apache.hc.client5.http.auth.AuthScheme
Imports
java.io.IOException, .ObjectInputStream, .ObjectOutputStream, .Serializable, java.nio.charset.Charset, .StandardCharsets, java.security.MessageDigest, .Principal, .SecureRandom, java.util.ArrayList, .Formatter, .HashMap, .HashSet, .List, .Locale, .Map, .Set, .StringTokenizer, org.apache.hc.client5.http.auth.AuthChallenge, .AuthScheme, .AuthScope, .AuthenticationException, .Credentials, .CredentialsProvider, .MalformedChallengeException, .StandardAuthScheme, .UsernamePasswordCredentials, org.apache.hc.client5.http.protocol.HttpClientContext, org.apache.hc.client5.http.utils.ByteArrayBuilder, org.apache.hc.core5.annotation.Internal, org.apache.hc.core5.http.ClassicHttpRequest, .HttpEntity, .HttpHost, .HttpRequest, .NameValuePair, org.apache.hc.core5.http.message.BasicHeaderValueFormatter, .BasicNameValuePair, org.apache.hc.core5.http.protocol.HttpContext, org.apache.hc.core5.util.Args, .CharArrayBuffer, org.slf4j.Logger, .LoggerFactory

Digest authentication scheme. 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

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum
DigestScheme.QualityOfProtection

Represent the possible values of quality of protection.

Field Summary

Modifier and TypeField and Description
private byte[]
private byte[]
private transient ByteArrayBuilder
private String
private boolean
private UsernamePasswordCredentials
private transient Charset
private static final char[]
HEXADECIMAL

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

private String
private static final Logger
private long
private final Map<String, String>
private static final long

Constructor Summary

AccessConstructor and Description
public
public
DigestScheme(final Charset charset)

Method Summary

Modifier and TypeMethod and Description
pack-priv static byte[]

Returns:

The cnonce value as String.
createCnonce
()

Creates a random cnonce value based on the current time.

private String
private static MessageDigest
pack-priv static String

Returns:

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

Encodes the 128 bit (16 bytes) MD5 digest into a 32 characters long string.

public String
generateAuthResponse(final HttpHost host, final HttpRequest
The request being authenticated
request
,
final HttpContext
HTTP context
context
)

Implements org.apache.hc.client5.http.auth.AuthScheme.generateAuthResponse.

Generates an authorization response based on the current state.
pack-priv String
pack-priv String
public String
public String
getName()

Implements org.apache.hc.client5.http.auth.AuthScheme.getName.

Returns textual designation of the given authentication scheme.
public String
public long
public Principal
getPrincipal()

Implements org.apache.hc.client5.http.auth.AuthScheme.getPrincipal.

Returns Principal whose credentials are used to generate an authentication response.
public String
getRealm()

Implements org.apache.hc.client5.http.auth.AuthScheme.getRealm.

Returns authentication realm.
public void
initPreemptive(final Credentials credentials, final String cnonce, final String realm)

public boolean
isChallengeComplete()

Implements org.apache.hc.client5.http.auth.AuthScheme.isChallengeComplete.

Authentication process may involve a series of challenge-response exchanges.
public boolean
isConnectionBased()

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

Determines if the authentication scheme is expected to provide an authorization response on a per connection basis instead of the standard per request basis
public boolean
isResponseReady(final HttpHost host, final CredentialsProvider
The credentials to be used for authentication
credentialsProvider
,
final HttpContext
HTTP context
context
)

Implements org.apache.hc.client5.http.auth.AuthScheme.isResponseReady.

Determines whether or not an authorization response can be generated based on the actual authentication state.
public void
processChallenge(final AuthChallenge
the auth challenge
authChallenge
,
final HttpContext
HTTP context
context
)

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

Processes the given auth challenge.
private void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

a1back to summary
private byte[] a1
a2back to summary
private byte[] a2
bufferback to summary
private transient ByteArrayBuilder buffer
cnonceback to summary
private String cnonce
completeback to summary
private boolean complete
credentialsback to summary
private UsernamePasswordCredentials credentials
defaultCharsetback to summary
private transient Charset defaultCharset
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
formatHex(byte[])
lastNonceback to summary
private String lastNonce
LOGback to summary
private static final Logger LOG
nounceCountback to summary
private long nounceCount
paramMapback to summary
private final Map<String, String> paramMap
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

DigestSchemeback to summary
public DigestScheme()
DigestSchemeback to summary
public DigestScheme(final Charset charset)

Method Detail

createCnonceback to summary
pack-priv static byte[] createCnonce()

Creates a random cnonce value based on the current time.

Returns:byte[]

The cnonce value as String.

createDigestResponseback to summary
private String createDigestResponse(final HttpRequest request) throws AuthenticationException
createMessageDigestback to summary
private static MessageDigest createMessageDigest(final String digAlg) throws UnsupportedDigestAlgorithmException
formatHexback to summary
pack-priv static String formatHex(final byte[] binaryData)

Encodes the 128 bit (16 bytes) MD5 digest into a 32 characters long string.

Parameters
binaryData:byte[]

array containing the digest

Returns:String

encoded MD5, or null if encoding failed

generateAuthResponseback to summary
public String generateAuthResponse(final HttpHost host, final HttpRequest request, final HttpContext context) throws AuthenticationException

Implements org.apache.hc.client5.http.auth.AuthScheme.generateAuthResponse.

Doc from org.apache.hc.client5.http.auth.AuthScheme.generateAuthResponse.

Generates an authorization response based on the current state. Some authentication schemes may need to load user credentials required to generate an authorization response from a CredentialsProvider prior to this method call.

Parameters
request:HttpRequest

The request being authenticated

context:HttpContext

HTTP context

Returns:String

authorization header

Annotations
@Override
Exceptions
AuthenticationException:
if authorization string cannot be generated due to an authentication failure
getA1back to summary
pack-priv String getA1()
getA2back to summary
pack-priv String getA2()
getCnonceback to summary
public String getCnonce()
Annotations
@Internal
getNameback to summary
public String getName()

Implements org.apache.hc.client5.http.auth.AuthScheme.getName.

Doc from org.apache.hc.client5.http.auth.AuthScheme.getName.

Returns textual designation of the given authentication scheme.

Returns:String

the name of the given authentication scheme

Annotations
@Override
getNonceback to summary
public String getNonce()
Annotations
@Internal
getNounceCountback to summary
public long getNounceCount()
Annotations
@Internal
getPrincipalback to summary
public Principal getPrincipal()

Implements org.apache.hc.client5.http.auth.AuthScheme.getPrincipal.

Doc from org.apache.hc.client5.http.auth.AuthScheme.getPrincipal.

Returns Principal whose credentials are used to generate an authentication response. Connection based schemes are required to return a user Principal if authorization applies to for the entire life span of connection.

Returns:Principal

user principal

Annotations
@Override
getRealmback to summary
public String getRealm()

Implements org.apache.hc.client5.http.auth.AuthScheme.getRealm.

Doc from org.apache.hc.client5.http.auth.AuthScheme.getRealm.

Returns authentication realm. If the concept of an authentication realm is not applicable to the given authentication scheme, returns null.

Returns:String

the authentication realm

Annotations
@Override
initPreemptiveback to summary
public void initPreemptive(final Credentials credentials, final String cnonce, final String realm)
isChallengeCompleteback to summary
public boolean isChallengeComplete()

Implements org.apache.hc.client5.http.auth.AuthScheme.isChallengeComplete.

Doc from org.apache.hc.client5.http.auth.AuthScheme.isChallengeComplete.

Authentication process may involve a series of challenge-response exchanges. This method tests if the authorization process has been fully completed (either successfully or unsuccessfully), that is, all the required authorization challenges have been processed in their entirety.

Returns:boolean

true if the authentication process has been completed, false otherwise.

Annotations
@Override
isConnectionBasedback to summary
public boolean isConnectionBased()

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

Doc from org.apache.hc.client5.http.auth.AuthScheme.isConnectionBased.

Determines if the authentication scheme is expected to provide an authorization response on a per connection basis instead of the standard per request basis

Returns:boolean

true if the scheme is connection based, false if the scheme is request based.

Annotations
@Override
isResponseReadyback to summary
public boolean isResponseReady(final HttpHost host, final CredentialsProvider credentialsProvider, final HttpContext context) throws AuthenticationException

Implements org.apache.hc.client5.http.auth.AuthScheme.isResponseReady.

Doc from org.apache.hc.client5.http.auth.AuthScheme.isResponseReady.

Determines whether or not an authorization response can be generated based on the actual authentication state. Generally the outcome of this method will depend upon availability of user credentials necessary to produce an authorization response.

Parameters
credentialsProvider:CredentialsProvider

The credentials to be used for authentication

context:HttpContext

HTTP context

Returns:boolean

true if an authorization response can be generated and the authentication handshake can proceed, false otherwise.

Annotations
@Override
Exceptions
AuthenticationException:
if authorization string cannot be generated due to an authentication failure
processChallengeback to summary
public void processChallenge(final AuthChallenge authChallenge, final HttpContext context) throws MalformedChallengeException

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

Doc from org.apache.hc.client5.http.auth.AuthScheme.processChallenge.

Processes the given auth challenge. Some authentication schemes may involve multiple challenge-response exchanges. Such schemes must be able to maintain internal state when dealing with sequential challenges

Parameters
authChallenge:AuthChallenge

the auth challenge

context:HttpContext

HTTP context

Annotations
@Override
Exceptions
MalformedChallengeException:
in case the auth challenge is incomplete, malformed or otherwise invalid.
readObjectback to summary
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
writeObjectback to summary
private void writeObject(final ObjectOutputStream out) throws IOException
org.apache.hc.client5.http.impl.auth back to summary

private final Enum DigestScheme.QualityOfProtection

extends Enum<DigestScheme.QualityOfProtection>
Class Inheritance

Represent the possible values of quality of protection.

Field Summary

Modifier and TypeField and Description
public static final DigestScheme.QualityOfProtection
public static final DigestScheme.QualityOfProtection
public static final DigestScheme.QualityOfProtection
public static final DigestScheme.QualityOfProtection

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static DigestScheme.QualityOfProtection
public static DigestScheme.QualityOfProtection[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

AUTHback to summary
public static final DigestScheme.QualityOfProtection AUTH
AUTH_INTback to summary
public static final DigestScheme.QualityOfProtection AUTH_INT
MISSINGback to summary
public static final DigestScheme.QualityOfProtection MISSING
UNKNOWNback to summary
public static final DigestScheme.QualityOfProtection UNKNOWN

Constructor Detail

QualityOfProtectionback to summary
private QualityOfProtection()

Method Detail

valueOfback to summary
public static DigestScheme.QualityOfProtection valueOf(String name)
valuesback to summary
public static DigestScheme.QualityOfProtection[] values()