Top Description Inners Fields Constructors Methods
org.apache.catalina.authenticator

public Class DigestAuthenticator

extends AuthenticatorBase
Class Inheritance
Imports
java.io.IOException, .StringReader, java.nio.charset.StandardCharsets, java.security.NoSuchAlgorithmException, .Principal, java.util.ArrayList, .Arrays, .HashMap, .Iterator, .LinkedHashMap, .List, .Map, jakarta.servlet.http.HttpServletRequest, .HttpServletResponse, org.apache.catalina.LifecycleException, .Realm, org.apache.catalina.connector.Request, org.apache.juli.logging.Log, .LogFactory, org.apache.tomcat.util.buf.HexUtils, .MessageBytes, .StringUtils, org.apache.tomcat.util.http.parser.Authorization, org.apache.tomcat.util.security.ConcurrentMessageDigest

An Authenticator and Valve implementation of HTTP DIGEST Authentication, as outlined in RFC 7616: "HTTP Digest Authentication"
Authors
Craig R. McClanahan, Remy Maucherat

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
DigestAuthenticator.AuthDigest

This enum exists because RFC 7616 and Java use different names for some digests.

public static class
public static class

Field Summary

Modifier and TypeField and Description
private List<DigestAuthenticator.AuthDigest>
algorithms

Algorithms to use for WWW-Authenticate challenges.

private static final DigestAuthenticator.AuthDigest
protected String
key

Private key.

protected long
lastTimestamp

The last timestamp used to generate a nonce.

protected final Object
private final Log
private static final String
protected int
nonceCacheSize

Maximum number of server nonces to keep in the cache.

protected int
nonceCountWindowSize

The window size to use to track seen nonce count values for a given nonce.

protected Map<String, DigestAuthenticator.NonceInfo>
nonces

List of server nonce values currently being tracked

protected long
nonceValidity

How long server nonces are valid for in milliseconds.

protected String
opaque

Opaque string.

private static final Map<String, DigestAuthenticator.AuthDigest>
protected static final String
QOP

Tomcat's DIGEST implementation only supports auth quality of protection.

protected boolean
validateUri

Should the URI be validated as required by RFC2617?

Inherited from org.apache.catalina.authenticator.AuthenticatorBase:
alwaysUseSessionAUTH_HEADER_NAMEcachechangeSessionIdOnAuthenticationcontextdisableProxyCachingjaspicCallbackHandlerClassREALM_NAMEsecurePagesWithPragmasecureRandomAlgorithmsecureRandomClasssecureRandomProvidersendAuthInfoResponseHeaderssessionIdGeneratorsmsso

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected boolean
doAuthenticate(Request
Request we are processing
request
,
HttpServletResponse
Response we are creating
response
)

Implements abstract org.apache.catalina.authenticator.AuthenticatorBase.doAuthenticate.

Authenticate the user making this request, based on the specified login configuration.

protected String

Returns:

The generated nonce
generateNonce
(Request
HTTP Servlet request
request
)

Generate a unique token.

public String
protected String
getAuthMethod()

Implements abstract org.apache.catalina.authenticator.AuthenticatorBase.getAuthMethod.

Return the authentication method, which is vendor-specific and not defined by HttpServletRequest.

public String
public int
public int
public long
public String
private void
protected boolean
isPreemptiveAuthPossible(Request
The request to check for credentials
request
)

Overrides org.apache.catalina.authenticator.AuthenticatorBase.isPreemptiveAuthPossible.

Can the authenticator perform preemptive authentication for the given request?

public boolean
protected static String

Returns:

The unquoted string
removeQuotes
(String
The quoted string
quotedString
,
boolean
true if quotes were required
quotesRequired
)

Removes the quotes on a string.

protected static String

Returns:

The unquoted string
removeQuotes
(String
The quoted string
quotedString
)

Removes the quotes on a string.

public void
setAlgorithms(String algorithmsString)

protected void
setAuthenticateHeader(HttpServletRequest
HTTP Servlet request
request
,
HttpServletResponse
HTTP Servlet response
response
,
String
nonce token
nonce
,
boolean
true to add a stale parameter
isNonceStale
)

Generates the WWW-Authenticate header(s) as per RFC 7616.

public void
public void
setNonceCacheSize(int nonceCacheSize)

public void
setNonceCountWindowSize(int nonceCountWindowSize)

public void
setNonceValidity(long nonceValidity)

public void
setOpaque(String opaque)

public void
setValidateUri(boolean validateUri)

protected void
Inherited from org.apache.catalina.authenticator.AuthenticatorBase:
allowCorsPreflightBypassassociateauthenticatechangeSessionIDcheckForCachedAuthenticationdoLogingetAllowCorsPreflightgetAlwaysUseSessiongetCachegetChangeSessionIdOnAuthenticationgetContainergetDisableProxyCachinggetJaspicCallbackHandlerClassgetRealmNamegetSecurePagesWithPragmagetSecureRandomAlgorithmgetSecureRandomClassgetSecureRandomProviderinvokeisContinuationRequiredisSendAuthInfoResponseHeadersloginlogoutnotifyreauthenticateFromSSOregisterregistersetAllowCorsPreflightsetAlwaysUseSessionsetCachesetChangeSessionIdOnAuthenticationsetContainersetDisableProxyCachingsetJaspicCallbackHandlerClasssetSecurePagesWithPragmasetSecureRandomAlgorithmsetSecureRandomClasssetSecureRandomProvidersetSendAuthInfoResponseHeadersstopInternal

Field Detail

algorithmsback to summary
private List<DigestAuthenticator.AuthDigest> algorithms

Algorithms to use for WWW-Authenticate challenges.

FALLBACK_DIGESTback to summary
private static final DigestAuthenticator.AuthDigest FALLBACK_DIGEST
keyback to summary
protected String key

Private key.

lastTimestampback to summary
protected long lastTimestamp

The last timestamp used to generate a nonce. Each nonce should get a unique timestamp.

lastTimestampLockback to summary
protected final Object lastTimestampLock
logback to summary
private final Log log

Hides org.apache.catalina.authenticator.AuthenticatorBase.log.

NONCE_DIGESTback to summary
private static final String NONCE_DIGEST
nonceCacheSizeback to summary
protected int nonceCacheSize

Maximum number of server nonces to keep in the cache. If not specified, the default value of 1000 is used.

nonceCountWindowSizeback to summary
protected int nonceCountWindowSize

The window size to use to track seen nonce count values for a given nonce. If not specified, the default of 100 is used.

noncesback to summary
protected Map<String, DigestAuthenticator.NonceInfo> nonces

List of server nonce values currently being tracked

nonceValidityback to summary
protected long nonceValidity

How long server nonces are valid for in milliseconds. Defaults to 5 minutes.

opaqueback to summary
protected String opaque

Opaque string.

PERMITTED_ALGORITHMSback to summary
private static final Map<String, DigestAuthenticator.AuthDigest> PERMITTED_ALGORITHMS
QOPback to summary
protected static final String QOP

Tomcat's DIGEST implementation only supports auth quality of protection.

validateUriback to summary
protected boolean validateUri

Should the URI be validated as required by RFC2617? Can be disabled in reverse proxies where the proxy has modified the URI.

Constructor Detail

DigestAuthenticatorback to summary
public DigestAuthenticator()

Method Detail

doAuthenticateback to summary
protected boolean doAuthenticate(Request request, HttpServletResponse response) throws IOException

Implements abstract org.apache.catalina.authenticator.AuthenticatorBase.doAuthenticate.

Authenticate the user making this request, based on the specified login configuration. Return true if any specified constraint has been satisfied, or false if we have created a response challenge already.

Parameters
request:Request

Request we are processing

response:HttpServletResponse

Response we are creating

Returns:boolean

Doc from org.apache.catalina.authenticator.AuthenticatorBase.doAuthenticate.

true if the the user was authenticated, otherwise false, in which case an authentication challenge will have been written to the response

Annotations
@Override
Exceptions
IOException:
if an input/output error occurs
generateNonceback to summary
protected String generateNonce(Request request)

Generate a unique token. The token is generated according to the following pattern. NOnceToken = Base64 ( NONCE_DIGEST ( client-IP ":" time-stamp ":" private-key ) ).

Parameters
request:Request

HTTP Servlet request

Returns:String

The generated nonce

getAlgorithmsback to summary
public String getAlgorithms()
getAuthMethodback to summary
protected String getAuthMethod()

Implements abstract org.apache.catalina.authenticator.AuthenticatorBase.getAuthMethod.

Doc from org.apache.catalina.authenticator.AuthenticatorBase.getAuthMethod.

Return the authentication method, which is vendor-specific and not defined by HttpServletRequest.

Returns:String

the authentication method, which is vendor-specific and not defined by HttpServletRequest.

Annotations
@Override
getKeyback to summary
public String getKey()
getNonceCacheSizeback to summary
public int getNonceCacheSize()
getNonceCountWindowSizeback to summary
public int getNonceCountWindowSize()
getNonceValidityback to summary
public long getNonceValidity()
getOpaqueback to summary
public String getOpaque()
initAlgorithmsback to summary
private void initAlgorithms(List<DigestAuthenticator.AuthDigest> algorithms)
isPreemptiveAuthPossibleback to summary
protected boolean isPreemptiveAuthPossible(Request request)

Overrides org.apache.catalina.authenticator.AuthenticatorBase.isPreemptiveAuthPossible.

Doc from org.apache.catalina.authenticator.AuthenticatorBase.isPreemptiveAuthPossible.

Can the authenticator perform preemptive authentication for the given request?

Parameters
request:Request

The request to check for credentials

Returns:boolean

true if preemptive authentication is possible, otherwise false

Annotations
@Override
isValidateUriback to summary
public boolean isValidateUri()
removeQuotesback to summary
protected static String removeQuotes(String quotedString, boolean quotesRequired)

Removes the quotes on a string. RFC2617 states quotes are optional for all parameters except realm.

Parameters
quotedString:String

The quoted string

quotesRequired:boolean

true if quotes were required

Returns:String

The unquoted string

removeQuotesback to summary
protected static String removeQuotes(String quotedString)

Removes the quotes on a string.

Parameters
quotedString:String

The quoted string

Returns:String

The unquoted string

setAlgorithmsback to summary
public void setAlgorithms(String algorithmsString)
setAuthenticateHeaderback to summary
protected void setAuthenticateHeader(HttpServletRequest request, HttpServletResponse response, String nonce, boolean isNonceStale)

Generates the WWW-Authenticate header(s) as per RFC 7616.

Parameters
request:HttpServletRequest

HTTP Servlet request

response:HttpServletResponse

HTTP Servlet response

nonce:String

nonce token

isNonceStale:boolean

true to add a stale parameter

setKeyback to summary
public void setKey(String key)
setNonceCacheSizeback to summary
public void setNonceCacheSize(int nonceCacheSize)
setNonceCountWindowSizeback to summary
public void setNonceCountWindowSize(int nonceCountWindowSize)
setNonceValidityback to summary
public void setNonceValidity(long nonceValidity)
setOpaqueback to summary
public void setOpaque(String opaque)
setValidateUriback to summary
public void setValidateUri(boolean validateUri)
startInternalback to summary
protected void startInternal() throws LifecycleException

Overrides org.apache.catalina.authenticator.AuthenticatorBase.startInternal.

Doc from org.apache.catalina.valves.ValveBase.startInternal.

Start this component and implement the requirements of org.apache.catalina.util.LifecycleBase#startInternal().

Annotations
@Override
Exceptions
LifecycleException:
if this component detects a fatal error that prevents this component from being used
org.apache.catalina.authenticator back to summary

public final Enum DigestAuthenticator.AuthDigest

extends Enum<DigestAuthenticator.AuthDigest>
Class Inheritance

This enum exists because RFC 7616 and Java use different names for some digests.

Field Summary

Modifier and TypeField and Description
private final String
public static final DigestAuthenticator.AuthDigest
private final String
public static final DigestAuthenticator.AuthDigest
public static final DigestAuthenticator.AuthDigest

Constructor Summary

AccessConstructor and Description
private
AuthDigest(String javaName, String rfcName)

Method Summary

Modifier and TypeMethod and Description
public String
public String
public static DigestAuthenticator.AuthDigest
public static DigestAuthenticator.AuthDigest[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

javaNameback to summary
private final String javaName
MD5back to summary
public static final DigestAuthenticator.AuthDigest MD5
rfcNameback to summary
private final String rfcName
SHA_256back to summary
public static final DigestAuthenticator.AuthDigest SHA_256
SHA_512_256back to summary
public static final DigestAuthenticator.AuthDigest SHA_512_256

Constructor Detail

AuthDigestback to summary
private AuthDigest(String javaName, String rfcName)

Method Detail

getJavaNameback to summary
public String getJavaName()
getRfcNameback to summary
public String getRfcName()
valueOfback to summary
public static DigestAuthenticator.AuthDigest valueOf(String name)
valuesback to summary
public static DigestAuthenticator.AuthDigest[] values()
org.apache.catalina.authenticator back to summary

public Class DigestAuthenticator.DigestInfo

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.catalina.authenticator.DigestAuthenticator.DigestInfo

Field Summary

Modifier and TypeField and Description
private DigestAuthenticator.AuthDigest
private String
private final String
private String
private String
private String
private final Map<String, DigestAuthenticator.NonceInfo>
private boolean
private final long
private final String
private String
private String
private String
private String
private String
private String
private boolean

Constructor Summary

AccessConstructor and Description
public
DigestInfo(String opaque, long nonceValidity, String key, Map<String, DigestAuthenticator.NonceInfo> nonces, boolean validateUri)

Method Summary

Modifier and TypeMethod and Description
public Principal
public String
public boolean
public boolean
parse(Request request, String authorization)

public boolean
validate(Request request)
Deprecated

public boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

algorithmback to summary
private DigestAuthenticator.AuthDigest algorithm
cnonceback to summary
private String cnonce
keyback to summary
private final String key
methodback to summary
private String method
ncback to summary
private String nc
nonceback to summary
private String nonce
noncesback to summary
private final Map<String, DigestAuthenticator.NonceInfo> nonces
nonceStaleback to summary
private boolean nonceStale
nonceValidityback to summary
private final long nonceValidity
opaqueback to summary
private final String opaque
opaqueReceivedback to summary
private String opaqueReceived
qopback to summary
private String qop
realmNameback to summary
private String realmName
responseback to summary
private String response
uriback to summary
private String uri
userNameback to summary
private String userName
validateUriback to summary
private boolean validateUri

Constructor Detail

DigestInfoback to summary
public DigestInfo(String opaque, long nonceValidity, String key, Map<String, DigestAuthenticator.NonceInfo> nonces, boolean validateUri)

Method Detail

authenticateback to summary
public Principal authenticate(Realm realm)
getUsernameback to summary
public String getUsername()
isNonceStaleback to summary
public boolean isNonceStale()
parseback to summary
public boolean parse(Request request, String authorization)
validateback to summary
public boolean validate(Request request)

Deprecated

Annotations
@Deprecated
validateback to summary
public boolean validate(Request request, List<DigestAuthenticator.AuthDigest> algorithms)
org.apache.catalina.authenticator back to summary

public Class DigestAuthenticator.NonceInfo

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.catalina.authenticator.DigestAuthenticator.NonceInfo

Field Summary

Modifier and TypeField and Description
private int
private final int
private final boolean[]
private final long

Constructor Summary

AccessConstructor and Description
public
NonceInfo(long currentTime, int seenWindowSize)

Method Summary

Modifier and TypeMethod and Description
public long
public synchronized boolean
nonceCountValid(long nonceCount)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

countback to summary
private int count
offsetback to summary
private final int offset
seenback to summary
private final boolean[] seen
timestampback to summary
private final long timestamp

Constructor Detail

NonceInfoback to summary
public NonceInfo(long currentTime, int seenWindowSize)

Method Detail

getTimestampback to summary
public long getTimestamp()
nonceCountValidback to summary
public synchronized boolean nonceCountValid(long nonceCount)