

The purpose of the JDBCRealm implementation is to
provide a mechanism by which Tomcat can acquire information needed
to authenticate web application users, and define their security roles,
from a relational database accessed via JDBC APIs. For integration
with Catalina, the resulting class(es) must implement the
org.apache.catalina.Realm interface.
This specification reflects a combination of functionality that is
already present in the org.apache.catalina.realm.JDBCRealm
class, as well as requirements for enhancements that have been
discussed. Where appropriate, requirements statements are marked
[Current] and [Requested] to distinguish them.
The current status of this functional specification is PROPOSED. It has not yet been discussed and agreed to on the TOMCAT-DEV mailing list.
The implementation of this functionality depends on the following external specifications:
The implementation of this functionality shall conform to the following requirements:
org.apache.catalina.Realm interface.
[Current]org.apache.catalina.Lifecycle
interface. [Current]org.apache.catalina.realm.RealmBase
base class.org.apache.catalina.realm package.
[Current]getContainer().log() method. [Current]The following environmental dependencies must be met in order for JDBCRealm to operate correctly:
$CATALINA_BASE/conf/server.xml, in a
<Realm> element that is nested inside a
corresponding <Engine>, <Host>,
or <Context> element.Correct operation of JDBCRealm depends on the following specific features of the surrounding container:
JDBCRealm will be initiated by
the appropriate Authenticator implementation, based
on the login method that is selected.JDBCRealm must have the JDBC standard API classes
available to it. For a JDK 1.2 or later container, these APIs
are included in the standard platform.JDBCRealm
must have the JDBC Optional Package (version 2.0 or later) APIs
available to it. This library is available as a separate
download (and will be included in Tomcat binary distributions).The main purpose of JDBCRealm is to allow Catalina to
authenticate users, and look up the corresponding security roles, from
the information found in a relational database accessed via JDBC APIs.
For maximum flexibility, the details of how this is done (for example,
the names of the required tables and columns) should be configurable.
Each time that Catalina needs to authenticate a user, it will call
the authenticate() method of this Realm implementation,
passing the username and password that were specified by the user. If
we find the user in the database (and match on the password), we accumulate
all of the security roles that are defined for this user, and create a
new GenericPrincipal object to be returned. If the user
is not authenticated, we return null instead. The
GenericUser object caches the set of security roles that
were owned by this user at the time of authentication, so that calls to
isUserInRole() can be answered without going back to the
database every time.
The implementation shall support the following properties that can be configured with JavaBeans property setters:
The following processing must be performed when the start()
method is called:
The following processing must be performed when the stop()
method is called:
When authenticate() is called, the following processing
is required:
null.null.List of the security roles assigned to the
authenticated user by selecting from the roles table.org.apache.catalina.realm.GenericPrincipal, passing as
constructor arguments: this realm instance, the authenticated
username, and a List of the security roles associated
with this user.GenericPrincipal objects for a particular user, because
the information in the directory server might have changed since the
last time this user was authenticated.GenericPrincipal.When hasRole() is called, the following processing
is required:
principal that is passed as an argument SHOULD
be one that we returned (instanceof class
org.apache.catalina.realm.GenericPrincipal, with a
realm property that is equal to our instance.principal meets these criteria, check
the specified role against the list returned by
getRoles(), and return true if the
specified role is included; otherwise, return false.principal does not meet these criteria,
return false.In addition to the assertions implied by the functionality requirements
listed above, the following additional assertions shall be tested to
validate the behavior of JDBCRealm: