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

public Class BasicAuthenticator

extends AuthenticatorBase
Class Inheritance
Imports
java.io.IOException, java.nio.charset.Charset, .StandardCharsets, java.security.Principal, jakarta.servlet.http.HttpServletRequest, .HttpServletResponse, org.apache.catalina.connector.Request, org.apache.juli.logging.Log, .LogFactory, org.apache.tomcat.util.buf.ByteChunk, .MessageBytes, org.apache.tomcat.util.codec.binary.Base64

An Authenticator and Valve implementation of HTTP BASIC Authentication, as outlined in RFC 7617: "The 'Basic' HTTP Authentication Scheme"
Author
Craig R. McClanahan

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
BasicAuthenticator.BasicCredentials

Parser for an HTTP Authorization header for BASIC authentication as per RFC 2617 section 2, and the Base64 encoded credentials as per RFC 2045 section 6.8.

Field Summary

Modifier and TypeField and Description
private Charset
private String
private final Log
private boolean
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
The request that triggered the authentication
request
,
HttpServletResponse
The response associated with the request
response
)

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

Provided for sub-classes to implement their specific authentication mechanism.

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 boolean
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 void
setCharset(String charsetString)

public void
setTrimCredentials(boolean trimCredentials)

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

Field Detail

charsetback to summary
private Charset charset
charsetStringback to summary
private String charsetString
logback to summary
private final Log log

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

trimCredentialsback to summary
private boolean trimCredentials

Constructor Detail

BasicAuthenticatorback to summary
public BasicAuthenticator()

Method Detail

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

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

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

Provided for sub-classes to implement their specific authentication mechanism.

Parameters
request:Request

The request that triggered the authentication

response:HttpServletResponse

The response associated with the request

Returns:boolean

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 I/O problem occurred during the authentication process
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
getCharsetback to summary
public String getCharset()
getTrimCredentialsback to summary
public boolean getTrimCredentials()
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
setCharsetback to summary
public void setCharset(String charsetString)
setTrimCredentialsback to summary
public void setTrimCredentials(boolean trimCredentials)
org.apache.catalina.authenticator back to summary

public Class BasicAuthenticator.BasicCredentials

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.catalina.authenticator.BasicAuthenticator.BasicCredentials

Parser for an HTTP Authorization header for BASIC authentication as per RFC 2617 section 2, and the Base64 encoded credentials as per RFC 2045 section 6.8.

Field Summary

Modifier and TypeField and Description
private final ByteChunk
private int
private int
private final Charset
private final int
private static final String
private String
private final boolean
private String

Constructor Summary

AccessConstructor and Description
public
BasicCredentials(ByteChunk
The header value to parse in-place
input
,
Charset
The character set to use to convert the bytes to a string
charset
,
boolean
Should leading and trailing whitespace be removed from the parsed credentials
trimCredentials
)

Parse the HTTP Authorization header for BASIC authentication as per RFC 2617 section 2, and the Base64 encoded credentials as per RFC 2045 section 6.8.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the decoded password token as a String, or null if no password was found in the credentials.
getPassword
()

Trivial accessor.

public String

Returns:

the decoded username token as a String, which is never be null, but can be empty.
getUsername
()

Trivial accessor.

private byte[]
private void
parseCredentials(byte[] decoded)

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

authorizationback to summary
private final ByteChunk authorization
base64blobLengthback to summary
private int base64blobLength
base64blobOffsetback to summary
private int base64blobOffset
charsetback to summary
private final Charset charset
initialOffsetback to summary
private final int initialOffset
METHODback to summary
private static final String METHOD
passwordback to summary
private String password
trimCredentialsback to summary
private final boolean trimCredentials
usernameback to summary
private String username

Constructor Detail

BasicCredentialsback to summary
public BasicCredentials(ByteChunk input, Charset charset, boolean trimCredentials) throws IllegalArgumentException

Parse the HTTP Authorization header for BASIC authentication as per RFC 2617 section 2, and the Base64 encoded credentials as per RFC 2045 section 6.8.

Parameters
input:ByteChunk

The header value to parse in-place

charset:Charset

The character set to use to convert the bytes to a string

trimCredentials:boolean

Should leading and trailing whitespace be removed from the parsed credentials

Exceptions
IllegalArgumentException:
If the header does not conform to RFC 2617

Method Detail

getPasswordback to summary
public String getPassword()

Trivial accessor.

Returns:String

the decoded password token as a String, or null if no password was found in the credentials.

getUsernameback to summary
public String getUsername()

Trivial accessor.

Returns:String

the decoded username token as a String, which is never be null, but can be empty.

parseBase64back to summary
private byte[] parseBase64() throws IllegalArgumentException
parseCredentialsback to summary
private void parseCredentials(byte[] decoded) throws IllegalArgumentException
parseMethodback to summary
private void parseMethod() throws IllegalArgumentException