Class DigestScheme
- java.lang.Object
-
- org.apache.hc.client5.http.impl.auth.DigestScheme
-
- All Implemented Interfaces:
java.io.Serializable,AuthScheme
public class DigestScheme extends java.lang.Object implements AuthScheme, java.io.Serializable
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
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description DigestScheme()DigestScheme(java.nio.charset.Charset charset)Deprecated.This constructor is deprecated to enforce the use ofStandardCharsets.UTF_8encoding in compliance with RFC 7616 for HTTP Digest Access Authentication.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgenerateAuthResponse(org.apache.hc.core5.http.HttpHost host, org.apache.hc.core5.http.HttpRequest request, org.apache.hc.core5.http.protocol.HttpContext context)Generates an authorization response based on the current state.java.lang.StringgetCnonce()java.lang.StringgetName()Returns textual designation of the given authentication scheme.java.lang.StringgetNonce()longgetNounceCount()java.security.PrincipalgetPrincipal()ReturnsPrincipalwhose credentials are used to generate an authentication response.java.lang.StringgetRealm()Returns authentication realm.voidinitPreemptive(Credentials credentials, java.lang.String cnonce, java.lang.String realm)booleanisChallengeComplete()Authentication process may involve a series of challenge-response exchanges.booleanisConnectionBased()Determines if the authentication scheme is expected to provide an authorization response on a per connection basis instead of the standard per request basisbooleanisResponseReady(org.apache.hc.core5.http.HttpHost host, CredentialsProvider credentialsProvider, org.apache.hc.core5.http.protocol.HttpContext context)Determines whether or not an authorization response can be generated based on the actual authentication state.voidprocessChallenge(AuthChallenge authChallenge, org.apache.hc.core5.http.protocol.HttpContext context)Processes the given auth challenge.java.lang.StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.hc.client5.http.auth.AuthScheme
isChallengeExpected, processChallenge
-
-
-
-
Constructor Detail
-
DigestScheme
public DigestScheme()
-
DigestScheme
@Deprecated public DigestScheme(java.nio.charset.Charset charset)
Deprecated.This constructor is deprecated to enforce the use ofStandardCharsets.UTF_8encoding in compliance with RFC 7616 for HTTP Digest Access Authentication. Use the default constructorDigestScheme()instead.- Parameters:
charset- theCharsetset to be used for encoding credentials. This parameter is ignored as UTF-8 is always used.
-
-
Method Detail
-
initPreemptive
public void initPreemptive(Credentials credentials, java.lang.String cnonce, java.lang.String realm)
-
getName
public java.lang.String getName()
Description copied from interface:AuthSchemeReturns textual designation of the given authentication scheme.- Specified by:
getNamein interfaceAuthScheme- Returns:
- the name of the given authentication scheme
-
isConnectionBased
public boolean isConnectionBased()
Description copied from interface:AuthSchemeDetermines if the authentication scheme is expected to provide an authorization response on a per connection basis instead of the standard per request basis- Specified by:
isConnectionBasedin interfaceAuthScheme- Returns:
trueif the scheme is connection based,falseif the scheme is request based.
-
getRealm
public java.lang.String getRealm()
Description copied from interface:AuthSchemeReturns authentication realm. If the concept of an authentication realm is not applicable to the given authentication scheme, returnsnull.- Specified by:
getRealmin interfaceAuthScheme- Returns:
- the authentication realm
-
processChallenge
public void processChallenge(AuthChallenge authChallenge, org.apache.hc.core5.http.protocol.HttpContext context) throws MalformedChallengeException
Description copied from interface:AuthSchemeProcesses 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 challengesPlease note auth schemes that perform mutual authentication must implement
AuthScheme.processChallenge(HttpHost, boolean, AuthChallenge, HttpContext)andAuthScheme.isChallengeExpected()instead.- Specified by:
processChallengein interfaceAuthScheme- Parameters:
authChallenge- the auth challengecontext- HTTP context- Throws:
MalformedChallengeException- in case the auth challenge is incomplete, malformed or otherwise invalid.- See Also:
AuthScheme.processChallenge(HttpHost, boolean, AuthChallenge, HttpContext)
-
isChallengeComplete
public boolean isChallengeComplete()
Description copied from interface:AuthSchemeAuthentication 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.Please note if the scheme returns
truefrom this method in response to a challenge, it effectively implies a failure to respond to this challenge and termination of the authentication process.- Specified by:
isChallengeCompletein interfaceAuthScheme- Returns:
trueif the authentication process has been completed,falseotherwise.
-
isResponseReady
public boolean isResponseReady(org.apache.hc.core5.http.HttpHost host, CredentialsProvider credentialsProvider, org.apache.hc.core5.http.protocol.HttpContext context) throws AuthenticationExceptionDescription copied from interface:AuthSchemeDetermines 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.- Specified by:
isResponseReadyin interfaceAuthSchemecredentialsProvider- The credentials to be used for authenticationcontext- HTTP context- Returns:
trueif an authorization response can be generated and the authentication handshake can proceed,falseotherwise.- Throws:
AuthenticationException- if authorization string cannot be generated due to an authentication failure
-
getPrincipal
public java.security.Principal getPrincipal()
Description copied from interface:AuthSchemeReturnsPrincipalwhose credentials are used to generate an authentication response. Connection based schemes are required to return a userPrincipalif authorization applies to for the entire life span of connection.- Specified by:
getPrincipalin interfaceAuthScheme- Returns:
- user principal
- See Also:
AuthScheme.isConnectionBased()
-
generateAuthResponse
public java.lang.String generateAuthResponse(org.apache.hc.core5.http.HttpHost host, org.apache.hc.core5.http.HttpRequest request, org.apache.hc.core5.http.protocol.HttpContext context) throws AuthenticationExceptionDescription copied from interface:AuthSchemeGenerates an authorization response based on the current state. Some authentication schemes may need to load user credentials required to generate an authorization response from aCredentialsProviderprior to this method call.- Specified by:
generateAuthResponsein interfaceAuthSchemerequest- The request being authenticatedcontext- HTTP context- Returns:
- authorization header
- Throws:
AuthenticationException- if authorization string cannot be generated due to an authentication failure- See Also:
AuthScheme.isResponseReady(HttpHost, CredentialsProvider, HttpContext)
-
getNonce
@Internal public java.lang.String getNonce()
-
getNounceCount
@Internal public long getNounceCount()
-
getCnonce
@Internal public java.lang.String getCnonce()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-