Top Description Fields Constructors Methods
org.apache.catalina.realm

public Class JAASRealm

extends RealmBase
Class Inheritance
Imports
java.lang.reflect.Constructor, .InvocationTargetException, java.net.URI, .URISyntaxException, .URL, java.security.Principal, java.util.ArrayList, .List, javax.security.auth.Subject, javax.security.auth.callback.CallbackHandler, javax.security.auth.login.AccountExpiredException, .Configuration, .CredentialExpiredException, .FailedLoginException, .LoginContext, .LoginException, jakarta.servlet.http.HttpServletRequest, org.apache.catalina.Container, .LifecycleException, org.apache.juli.logging.Log, .LogFactory, org.apache.tomcat.util.ExceptionUtils

Implementation of Realm that authenticates users via the Java Authentication and Authorization Service (JAAS). JAAS support requires either JDK 1.4 (which includes it as part of the standard platform) or JDK 1.3 (with the plug-in jaas.jar file).

The value configured for the appName property is passed to the javax.security.auth.login.LoginContext constructor, to specify the application name used to select the set of relevant LoginModules required.

The JAAS Specification describes the result of a successful login as a javax.security.auth.Subject instance, which can contain zero or more java.security.Principal objects in the return value of the Subject.getPrincipals() method. However, it provides no guidance on how to distinguish Principals that describe the individual user (and are thus appropriate to return as the value of request.getUserPrincipal() in a web application) from the Principal(s) that describe the authorized roles for this user. To maintain as much independence as possible from the underlying LoginMethod implementation executed by JAAS, the following policy is implemented by this Realm:

Authors
Craig R. McClanahan, Yoav Shapira

Field Summary

Modifier and TypeField and Description
protected String
appName

The application name passed to the JAAS LoginContext, which uses it to select the set of relevant LoginModules.

protected String
configFile

Path to find a JAAS configuration file, if not set global JVM JAAS configuration will be used.

private volatile boolean
invocationSuccess

Keeps track if JAAS invocation of login modules was successful or not.

protected volatile Configuration
protected volatile boolean
private static final Log
protected final List<String>
roleClasses

The list of role class names, split out for easy processing.

protected String
roleClassNames

Comma-delimited list of java.security.Principal classes that represent security roles.

protected boolean
useContextClassLoader

Whether to use context ClassLoader or default ClassLoader.

protected final List<String>
userClasses

The set of user class names, split out for easy processing.

protected String
userClassNames

Comma-delimited list of java.security.Principal classes that represent individual users.

Inherited from org.apache.catalina.realm.RealmBase:
allRolesModecontainercontainerLogrealmPathsmstripRealmForGsssupportUSER_ATTRIBUTES_DELIMITERUSER_ATTRIBUTES_WILDCARDuserAttributesuserAttributesListvalidatex509UsernameRetrieverx509UsernameRetrieverClassName

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Principal
authenticate(String
Username of the Principal to look up
username
,
String
Password or other credentials to use in authenticating this username
credentials
)

Overrides org.apache.catalina.realm.RealmBase.authenticate.

Implements org.apache.catalina.Realm.authenticate.

Try to authenticate using the specified username and credentials.

public Principal
authenticate(String
Username of the Principal to look up
username
,
String
Digest which has been submitted by the client
clientDigest
,
String
Unique (or supposedly unique) token which has been used for this request
nonce
,
String
the nonce counter
nc
,
String
the client chosen nonce
cnonce
,
String
the "quality of protection" (nc and cnonce will only be used, if qop is not null).
qop
,
String
Realm name
realmName
,
String
Second digest calculated as digest(Method + ":" + uri)
digestA2
,
String
The message digest algorithm to use
algorithm
)

Overrides org.apache.catalina.realm.RealmBase.authenticate.

Overrides default org.apache.catalina.Realm.authenticate.

Try to authenticate with the specified username, which matches the digest calculated using the given parameters using the method described in RFC 7616.

protected Principal

Returns:

the associated principal, or null if there is none.
authenticate
(String
The user name
username
,
CallbackHandler
The callback handler
callbackHandler
)

Perform the actual JAAS authentication.

protected Principal

Returns:

the principal object
createPrincipal
(String
The associated user name
username
,
Subject
The Subject representing the logged-in user
subject
,
LoginContext
Associated with the Principal so LoginContext#logout() can be called later
loginContext
)

Identify and return a java.security.Principal instance representing the authenticated user for the specified Subject.

public String

Returns:

the application name.
getAppName
()

protected Configuration

Returns:

the loaded configuration
getConfig
()

Load custom JAAS Configuration.

public String

Returns:

the path of the JAAS configuration file.
getConfigFile
()

protected String

Returns:

the password associated with the given principal's user name. This always returns null as the JAASRealm has no way of obtaining this information.
getPassword
(String
The user name
username
)

Implements abstract org.apache.catalina.realm.RealmBase.getPassword.

Get the password for the specified user.

protected Principal

Returns:

the Principal associated with the given user name.
getPrincipal
(String
The user name
username
)

Implements abstract org.apache.catalina.realm.RealmBase.getPrincipal.

Get the principal associated with the specified user.

public String
public String
public boolean
isAvailable()

Overrides default org.apache.catalina.Realm.isAvailable.

Return the availability of the realm for authentication.

public boolean

Returns:

The value of useContextClassLoader
isUseContextClassLoader
()

Returns whether to use the context or default ClassLoader.

protected String

Returns:

A string that's a valid JAAS realm name
makeLegalForJAAS
(final String
The name to validate
src
)

Ensure the given name is legal for JAAS configuration.

protected void
parseClassNames(String
a comma-delimited list of fully qualified class names.
classNamesString
,
List<String>
the list in which the class names will be stored. The list is cleared before being populated.
classNamesList
)

Parses a comma-delimited list of class names, and store the class names in the provided List.

public void
setAppName(String
The application name that will be used to retrieve the set of relevant LoginModules
name
)

Set the JAAS LoginContext app name.

public void
setConfigFile(String
The JAAS configuration file
configFile
)

Set the JAAS configuration file.

public void
setContainer(Container
The Container instance with which this instance is to be associated, or null to disassociate this instance from any Container
container
)

Overrides org.apache.catalina.realm.RealmBase.setContainer.

Implements org.apache.catalina.Contained.setContainer.

Set the Container with which this instance is associated.

public void
setRoleClassNames(String
The class names list
roleClassNames
)

Sets the list of comma-delimited classes that represent roles.

public void
setUseContextClassLoader(boolean
True means use context ClassLoader
useContext
)

Sets whether to use the context or default ClassLoader.

public void
setUserClassNames(String
The class names list
userClassNames
)

Sets the list of comma-delimited classes that represent individual users.

protected void
startInternal()

Overrides org.apache.catalina.realm.RealmBase.startInternal.

Prepare for the beginning of active use of the public methods of this component and implement the requirements of org.apache.catalina.util.LifecycleBase#startInternal().

Inherited from org.apache.catalina.realm.RealmBase:
addPropertyChangeListenerauthenticateauthenticateauthenticateauthenticateauthenticatebackgroundProcessfindSecurityConstraintsgetAllRolesModegetContainergetCredentialHandlergetDigestgetDigestgetDomainInternalgetObjectNameKeyPropertiesgetPrincipalgetPrincipalgetRealmPathgetRealmSuffixgetServergetTransportGuaranteeRedirectStatusgetUserAttributesgetValidategetX509UsernameRetrieverClassNamehasMessageDigesthasResourcePermissionhasRolehasRoleInternalhasUserDataPermissioninitInternalisStripRealmForGssmainparseUserAttributesremovePropertyChangeListenersetAllRolesModesetCredentialHandlersetRealmPathsetStripRealmForGsssetTransportGuaranteeRedirectStatussetUserAttributessetValidatesetX509UsernameRetrieverClassNamestopInternaltoString

Field Detail

appNameback to summary
protected String appName

The application name passed to the JAAS LoginContext, which uses it to select the set of relevant LoginModules.

configFileback to summary
protected String configFile

Path to find a JAAS configuration file, if not set global JVM JAAS configuration will be used.

invocationSuccessback to summary
private volatile boolean invocationSuccess

Keeps track if JAAS invocation of login modules was successful or not. By default it is true unless we detect JAAS login module can't perform the login. This will be used for realm's isAvailable() status so that LockOutRealm will not lock the user out if JAAS login modules are unavailable to perform the actual login.

jaasConfigurationback to summary
protected volatile Configuration jaasConfiguration
jaasConfigurationLoadedback to summary
protected volatile boolean jaasConfigurationLoaded
logback to summary
private static final Log log

Hides org.apache.catalina.realm.RealmBase.log.

roleClassesback to summary
protected final List<String> roleClasses

The list of role class names, split out for easy processing.

roleClassNamesback to summary
protected String roleClassNames

Comma-delimited list of java.security.Principal classes that represent security roles.

useContextClassLoaderback to summary
protected boolean useContextClassLoader

Whether to use context ClassLoader or default ClassLoader. True means use context ClassLoader, and True is the default value.

userClassesback to summary
protected final List<String> userClasses

The set of user class names, split out for easy processing.

userClassNamesback to summary
protected String userClassNames

Comma-delimited list of java.security.Principal classes that represent individual users.

Constructor Detail

JAASRealmback to summary
public JAASRealm()

Method Detail

authenticateback to summary
public Principal authenticate(String username, String credentials)

Overrides org.apache.catalina.realm.RealmBase.authenticate.

Implements org.apache.catalina.Realm.authenticate.

Doc from org.apache.catalina.Realm.authenticate.

Try to authenticate using the specified username and credentials.

Parameters
username:String

Username of the Principal to look up

credentials:String

Password or other credentials to use in authenticating this username

Returns:Principal

the associated principal, or null if there is none

Annotations
@Override
authenticateback to summary
public Principal authenticate(String username, String clientDigest, String nonce, String nc, String cnonce, String qop, String realmName, String digestA2, String algorithm)

Overrides org.apache.catalina.realm.RealmBase.authenticate.

Overrides default org.apache.catalina.Realm.authenticate.

Doc from org.apache.catalina.Realm.authenticate.

Try to authenticate with the specified username, which matches the digest calculated using the given parameters using the method described in RFC 7616.

The default implementation calls authenticate(String, String, String, String, String, String, String, String) for backwards compatibility which effectively forces the use of MD5 regardless of the algorithm specified in the call to this method.

Implementations are expected to override the default implementation and take account of the algorithm parameter.

Parameters
username:String

Username of the Principal to look up

clientDigest:String

Digest which has been submitted by the client

nonce:String

Unique (or supposedly unique) token which has been used for this request

nc:String

the nonce counter

cnonce:String

the client chosen nonce

qop:String

the "quality of protection" (nc and cnonce will only be used, if qop is not null).

realmName:String

Realm name

digestA2:String

Second digest calculated as digest(Method + ":" + uri)

algorithm:String

The message digest algorithm to use

Returns:Principal

the associated principal, or null if there is none.

Annotations
@Override
authenticateback to summary
protected Principal authenticate(String username, CallbackHandler callbackHandler)

Perform the actual JAAS authentication.

Parameters
username:String

The user name

callbackHandler:CallbackHandler

The callback handler

Returns:Principal

the associated principal, or null if there is none.

createPrincipalback to summary
protected Principal createPrincipal(String username, Subject subject, LoginContext loginContext)

Identify and return a java.security.Principal instance representing the authenticated user for the specified Subject. The Principal is constructed by scanning the list of Principals returned by the JAASLoginModule. The first Principal object that matches one of the class names supplied as a "user class" is the user Principal. This object is returned to the caller. Any remaining principal objects returned by the LoginModules are mapped to roles, but only if their respective classes match one of the "role class" classes. If a user Principal cannot be constructed, return null.

Parameters
username:String

The associated user name

subject:Subject

The Subject representing the logged-in user

loginContext:LoginContext

Associated with the Principal so LoginContext#logout() can be called later

Returns:Principal

the principal object

getAppNameback to summary
public String getAppName()
Returns:String

the application name.

getConfigback to summary
protected Configuration getConfig()

Load custom JAAS Configuration.

Returns:Configuration

the loaded configuration

getConfigFileback to summary
public String getConfigFile()
Returns:String

the path of the JAAS configuration file.

getPasswordback to summary
protected String getPassword(String username)

Implements abstract org.apache.catalina.realm.RealmBase.getPassword.

Doc from org.apache.catalina.realm.RealmBase.getPassword.

Get the password for the specified user.

Parameters
username:String

The user name

Returns:String

the password associated with the given principal's user name. This always returns null as the JAASRealm has no way of obtaining this information.

Annotations
@Override
getPrincipalback to summary
protected Principal getPrincipal(String username)

Implements abstract org.apache.catalina.realm.RealmBase.getPrincipal.

Doc from org.apache.catalina.realm.RealmBase.getPrincipal.

Get the principal associated with the specified user.

Parameters
username:String

The user name

Returns:Principal

the Principal associated with the given user name.

Annotations
@Override
getRoleClassNamesback to summary
public String getRoleClassNames()
getUserClassNamesback to summary
public String getUserClassNames()
isAvailableback to summary
public boolean isAvailable()

Overrides default org.apache.catalina.Realm.isAvailable.

Doc from org.apache.catalina.Realm.isAvailable.

Return the availability of the realm for authentication.

Returns:boolean

true if the realm is able to perform authentication

Annotations
@Override
isUseContextClassLoaderback to summary
public boolean isUseContextClassLoader()

Returns whether to use the context or default ClassLoader. True means to use the context ClassLoader.

Returns:boolean

The value of useContextClassLoader

makeLegalForJAASback to summary
protected String makeLegalForJAAS(final String src)

Ensure the given name is legal for JAAS configuration. Added for Bugzilla 30869, made protected for easy customization in case my implementation is insufficient, which I think is very likely.

Parameters
src:String

The name to validate

Returns:String

A string that's a valid JAAS realm name

parseClassNamesback to summary
protected void parseClassNames(String classNamesString, List<String> classNamesList)

Parses a comma-delimited list of class names, and store the class names in the provided List. Each class must implement java.security.Principal.

Parameters
classNamesString:String

a comma-delimited list of fully qualified class names.

classNamesList:List<String>

the list in which the class names will be stored. The list is cleared before being populated.

setAppNameback to summary
public void setAppName(String name)

Set the JAAS LoginContext app name.

Parameters
name:String

The application name that will be used to retrieve the set of relevant LoginModules

setConfigFileback to summary
public void setConfigFile(String configFile)

Set the JAAS configuration file.

Parameters
configFile:String

The JAAS configuration file

setContainerback to summary
public void setContainer(Container container)

Overrides org.apache.catalina.realm.RealmBase.setContainer.

Implements org.apache.catalina.Contained.setContainer.

Doc from org.apache.catalina.Contained.setContainer.

Set the Container with which this instance is associated.

Parameters
container:Container

The Container instance with which this instance is to be associated, or null to disassociate this instance from any Container

Annotations
@Override
setRoleClassNamesback to summary
public void setRoleClassNames(String roleClassNames)

Sets the list of comma-delimited classes that represent roles. The classes in the list must implement java.security.Principal. The supplied list of classes will be parsed when start() is called.

Parameters
roleClassNames:String

The class names list

setUseContextClassLoaderback to summary
public void setUseContextClassLoader(boolean useContext)

Sets whether to use the context or default ClassLoader. True means use context ClassLoader.

Parameters
useContext:boolean

True means use context ClassLoader

setUserClassNamesback to summary
public void setUserClassNames(String userClassNames)

Sets the list of comma-delimited classes that represent individual users. The classes in the list must implement java.security.Principal. The supplied list of classes will be parsed when start() is called.

Parameters
userClassNames:String

The class names list

startInternalback to summary
protected void startInternal() throws LifecycleException

Overrides org.apache.catalina.realm.RealmBase.startInternal.

Doc from org.apache.catalina.realm.RealmBase.startInternal.

Prepare for the beginning of active use of the public methods of 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