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:
LoginModule is assumed to return a Subject with at least one
Principal instance representing the user himself or herself, and zero or more separate
Principals representing the security roles authorized for this user.Principal representing the user, the Principal name is an appropriate value to return via the
Servlet API method HttpServletRequest.getRemoteUser().Principals representing the security roles, the name is the name of the authorized security
role.java.security.Principal - one that identifies class(es) representing a user, and one that identifies
class(es) representing a security role.Principals returned by Subject.getPrincipals(), it will
identify the first Principal that matches the "user classes" list as the Principal for this
user.Principals returned by Subject.getPrincipals(), it will
accumulate the set of all Principals matching the "role classes" list as identifying the security roles
for this user.Subject without a
Principal that matches the "user classes" list.
Catalina {
org.foobar.auth.DatabaseLoginModule REQUIRED
JNDI_RESOURCE=jdbc/AuthDB
USER_TABLE=users
USER_ID_COLUMN=id
USER_NAME_COLUMN=name
USER_CREDENTIAL_COLUMN=password
ROLE_TABLE=roles
ROLE_NAME_COLUMN=name
PRINCIPAL_FACTORY=org.foobar.auth.impl.SimplePrincipalFactory;
};
CATALINA_OPTS environment variable similar to
the following:
CATALINA_OPTS="-Djava.security.auth.login.config=$CATALINA_HOME/conf/jaas.config"
CallbackHandler, called (unsurprisingly)
JAASCallbackHandler. This handler supplies the HTTP requests's username and credentials to the
user-supplied LoginModuleRealm implementations, digested passwords are supported if the
<Realm> element in server.xml contains a digest attribute;
JAASCallbackHandler will digest the password prior to passing it back to the
LoginModule| Modifier and Type | Field and Description |
|---|---|
| protected String | appName
The application name passed to the JAAS |
| 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 | roleClasses
The list of role class names, split out for easy processing. |
| protected String | roleClassNames
Comma-delimited list of |
| protected boolean | useContextClassLoader
Whether to use context ClassLoader or default ClassLoader. |
| protected final List | userClasses
The set of user class names, split out for easy processing. |
| protected String | userClassNames
Comma-delimited list of |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method 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. Implements org. 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" ( qop, String nc and cnonce
will only be used, if qop is not null).Realm name realmName, String Second digest calculated as digest(Method + ":" + uri) digestA2, String The message digest algorithm to use algorithm)Overrides org. Overrides default org. 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, ornull if there is none.The user name username, CallbackHandler The callback handler callbackHandler)Perform the actual JAAS authentication. |
| protected Principal | Returns: the principal objectThe associated user name username, Subject The subject, LoginContext Subject representing the logged-in userAssociated with the Principal so loginContext)LoginContext#logout() can be called laterIdentify and return a |
| public String | |
| protected Configuration | |
| public String | |
| 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.The user name username)Implements abstract org. Get the password for the specified user. |
| protected Principal | Returns: thePrincipal associated with the given user name.The user name username)Implements abstract org. Get the principal associated with the specified user. |
| public String | |
| public String | |
| public boolean | isAvailable()
Overrides default org. Return the availability of the realm for authentication. |
| public boolean | Returns: The value of useContextClassLoaderReturns whether to use the context or default ClassLoader. |
| protected String | Returns: A string that's a valid JAAS realm nameThe 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 name)LoginModulesSet the JAAS |
| public void | |
| public void | setContainer(Container
The Container instance with which this instance is to
be associated, or container)null to disassociate this instance
from any ContainerOverrides org. Implements org. Set the |
| 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. Prepare for the beginning of active use of the public methods of this component and implement the requirements of
|
| appName | back to summary |
|---|---|
| protected String appName The application name passed to the JAAS | |
| configFile | back to summary |
|---|---|
| protected String configFile Path to find a JAAS configuration file, if not set global JVM JAAS configuration will be used. | |
| invocationSuccess | back 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 | |
| jaasConfiguration | back to summary |
|---|---|
| protected volatile Configuration jaasConfiguration | |
| jaasConfigurationLoaded | back to summary |
|---|---|
| protected volatile boolean jaasConfigurationLoaded | |
| log | back to summary |
|---|---|
| private static final Log log | |
| roleClasses | back to summary |
|---|---|
| protected final List<String> roleClasses The list of role class names, split out for easy processing. | |
| roleClassNames | back to summary |
|---|---|
| protected String roleClassNames Comma-delimited list of | |
| useContextClassLoader | back to summary |
|---|---|
| protected boolean useContextClassLoader Whether to use context ClassLoader or default ClassLoader. True means use context ClassLoader, and True is the default value. | |
| userClasses | back to summary |
|---|---|
| protected final List<String> userClasses The set of user class names, split out for easy processing. | |
| userClassNames | back to summary |
|---|---|
| protected String userClassNames Comma-delimited list of | |
| JAASRealm | back to summary |
|---|---|
| public JAASRealm() | |
| authenticate | back to summary |
|---|---|
| public Principal authenticate(String username, String credentials) Overrides org. Implements org. Doc from org. Try to authenticate using the specified username and credentials. | |
| authenticate | back 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. Overrides default org. Doc from org. 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 Implementations are expected to override the default implementation and take account of the algorithm parameter.
| |
| authenticate | back to summary |
|---|---|
| protected Principal authenticate(String username, CallbackHandler callbackHandler) Perform the actual JAAS authentication.
| |
| createPrincipal | back to summary |
|---|---|
| protected Principal createPrincipal(String username, Subject subject, LoginContext loginContext) Identify and return a
| |
| getAppName | back to summary |
|---|---|
public String getAppName()
| |
| getConfig | back to summary |
|---|---|
| protected Configuration getConfig() Load custom JAAS Configuration.
| |
| getConfigFile | back to summary |
|---|---|
public String getConfigFile()
| |
| getPassword | back to summary |
|---|---|
| protected String getPassword(String username) Implements abstract org. Doc from org. Get the password for the specified user. | |
| getPrincipal | back to summary |
|---|---|
| protected Principal getPrincipal(String username) Implements abstract org. Doc from org. Get the principal associated with the specified user. | |
| getRoleClassNames | back to summary |
|---|---|
| public String getRoleClassNames() | |
| getUserClassNames | back to summary |
|---|---|
| public String getUserClassNames() | |
| isAvailable | back to summary |
|---|---|
| public boolean isAvailable() Overrides default org. Doc from org. Return the availability of the realm for authentication.
| |
| isUseContextClassLoader | back to summary |
|---|---|
| public boolean isUseContextClassLoader() Returns whether to use the context or default ClassLoader. True means to use the context ClassLoader.
| |
| makeLegalForJAAS | back 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. | |
| parseClassNames | back 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 | |
| setAppName | back to summary |
|---|---|
| public void setAppName(String name) Set the JAAS
| |
| setConfigFile | back to summary |
|---|---|
| public void setConfigFile(String configFile) Set the JAAS configuration file.
| |
| setContainer | back to summary |
|---|---|
| public void setContainer(Container container) Overrides org. Implements org. Doc from org. Set the | |
| setRoleClassNames | back to summary |
|---|---|
| public void setRoleClassNames(String roleClassNames) Sets the list of comma-delimited classes that represent roles. The classes in the list must implement
| |
| setUseContextClassLoader | back to summary |
|---|---|
| public void setUseContextClassLoader(boolean useContext) Sets whether to use the context or default ClassLoader. True means use context ClassLoader.
| |
| setUserClassNames | back 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
| |
| startInternal | back to summary |
|---|---|
| protected void startInternal() throws LifecycleException Overrides org. Doc from org. Prepare for the beginning of active use of the public methods of this component and implement the requirements of
| |