Package org.apache.catalina.realm
Class JDBCRealm
java.lang.Object
org.apache.catalina.util.LifecycleBase
org.apache.catalina.util.LifecycleMBeanBase
org.apache.catalina.realm.RealmBase
org.apache.catalina.realm.JDBCRealm
- All Implemented Interfaces:
- MBeanRegistration,- Contained,- JmxEnabled,- Lifecycle,- Realm
Deprecated.
Will be removed in Tomcat 10 onwards. Use the DataSourceRealm instead.
Implementation of Realm that works with any JDBC supported database. See the JDBCRealm.howto for more details
 on how to set up the database and for configuration options.
 
 For a Realm implementation that supports connection pooling and doesn't require synchronisation of
 authenticate(), getPassword(), roles() and getPrincipal() or the
 ugly connection logic use the DataSourceRealm.
 
- Author:
- Craig R. McClanahan, Carson McDonald, Ignacio Ortega
- 
Nested Class SummaryNested classes/interfaces inherited from class org.apache.catalina.realm.RealmBaseRealmBase.AllRolesModeNested classes/interfaces inherited from interface org.apache.catalina.LifecycleLifecycle.SingleUse
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected StringDeprecated.The connection username to use when trying to connect to the database.protected StringDeprecated.The connection URL to use when trying to connect to the database.protected StringDeprecated.The connection URL to use when trying to connect to the database.protected ConnectionDeprecated.The connection to the database.protected DriverDeprecated.Instance of the JDBC Driver class we use as a connection factory.protected StringDeprecated.The JDBC driver to use.protected PreparedStatementDeprecated.The PreparedStatement to use for authenticating users.protected PreparedStatementDeprecated.The PreparedStatement to use for identifying the roles for a specified user.protected StringDeprecated.The column in the user role table that names a roleprotected StringDeprecated.The column in the user table that holds the user's credentialsprotected StringDeprecated.The column in the user table that holds the user's nameprotected StringDeprecated.The table that holds the relation between user's and rolesprotected StringDeprecated.The table that holds user data.Fields inherited from class org.apache.catalina.realm.RealmBaseallRolesMode, container, containerLog, realmPath, sm, stripRealmForGss, support, USER_ATTRIBUTES_DELIMITER, USER_ATTRIBUTES_WILDCARD, userAttributes, userAttributesList, validate, x509UsernameRetriever, x509UsernameRetrieverClassNameFields inherited from class org.apache.catalina.util.LifecycleMBeanBasemserverFields inherited from interface org.apache.catalina.LifecycleAFTER_DESTROY_EVENT, AFTER_INIT_EVENT, AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_DESTROY_EVENT, BEFORE_INIT_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, CONFIGURE_START_EVENT, CONFIGURE_STOP_EVENT, PERIODIC_EVENT, START_EVENT, STOP_EVENT
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionauthenticate(String username, String credentials) Deprecated.Return the Principal associated with the specified username and credentials, if there is one; otherwise returnnull.authenticate(Connection dbConnection, String username, String credentials) Deprecated.Attempt to authenticate the user with the provided credentials.protected voidclose(Connection dbConnection) Deprecated.Close the specified database connection.protected PreparedStatementcredentials(Connection dbConnection, String username) Deprecated.Return a PreparedStatement configured to perform the SELECT required to retrieve user credentials for the specified username.Deprecated.Deprecated.Deprecated.Deprecated.protected StringgetPassword(String username) Deprecated.Get the password for the specified user.protected PrincipalgetPrincipal(String username) Deprecated.Get the principal associated with the specified user.Deprecated.Deprecated.Return the roles associated with the given user name.Deprecated.Deprecated.Deprecated.Deprecated.booleanDeprecated.Return the availability of the realm for authentication.protected Connectionopen()Deprecated.Open (if necessary) and return a database connection for use by this Realm.protected PreparedStatementroles(Connection dbConnection, String username) Deprecated.Return a PreparedStatement configured to perform the SELECT required to retrieve user roles for the specified username.voidsetConnectionName(String connectionName) Deprecated.Set the username to use to connect to the database.voidsetConnectionPassword(String connectionPassword) Deprecated.Set the password to use to connect to the database.voidsetConnectionURL(String connectionURL) Deprecated.Set the URL to use to connect to the database.voidsetDriverName(String driverName) Deprecated.Set the JDBC driver that will be used.voidsetRoleNameCol(String roleNameCol) Deprecated.Set the column in the user role table that names a role.voidsetUserCredCol(String userCredCol) Deprecated.Set the column in the user table that holds the user's credentials.voidsetUserNameCol(String userNameCol) Deprecated.Set the column in the user table that holds the user's name.voidsetUserRoleTable(String userRoleTable) Deprecated.Set the table that holds the relation between user's and roles.voidsetUserTable(String userTable) Deprecated.Set the table that holds user data.protected voidDeprecated.Prepare for the beginning of active use of the public methods of this component and implement the requirements ofLifecycleBase.startInternal().protected voidDeprecated.Gracefully terminate the active use of the public methods of this component and implement the requirements ofLifecycleBase.stopInternal().Methods inherited from class org.apache.catalina.realm.RealmBaseaddPropertyChangeListener, authenticate, authenticate, authenticate, authenticate, authenticate, authenticate, backgroundProcess, findSecurityConstraints, getAllRolesMode, getContainer, getCredentialHandler, getDigest, getDigest, getDomainInternal, getObjectNameKeyProperties, getPrincipal, getPrincipal, getPrincipal, getPrincipal, getRealmPath, getRealmSuffix, getRoles, getServer, getTransportGuaranteeRedirectStatus, getUserAttributes, getValidate, getX509UsernameRetrieverClassName, hasMessageDigest, hasResourcePermission, hasRole, hasRoleInternal, hasUserDataPermission, initInternal, isStripRealmForGss, main, parseUserAttributes, removePropertyChangeListener, setAllRolesMode, setContainer, setCredentialHandler, setRealmPath, setStripRealmForGss, setTransportGuaranteeRedirectStatus, setUserAttributes, setValidate, setX509UsernameRetrieverClassName, toStringMethods inherited from class org.apache.catalina.util.LifecycleMBeanBasedestroyInternal, getDomain, getObjectName, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister, unregisterMethods inherited from class org.apache.catalina.util.LifecycleBaseaddLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, getThrowOnFailure, init, removeLifecycleListener, setState, setState, setThrowOnFailure, start, stop
- 
Field Details- 
connectionNameDeprecated.The connection username to use when trying to connect to the database.
- 
connectionPasswordDeprecated.The connection URL to use when trying to connect to the database.
- 
connectionURLDeprecated.The connection URL to use when trying to connect to the database.
- 
dbConnectionDeprecated.The connection to the database.
- 
driverDeprecated.Instance of the JDBC Driver class we use as a connection factory.
- 
driverNameDeprecated.The JDBC driver to use.
- 
preparedCredentialsDeprecated.The PreparedStatement to use for authenticating users.
- 
preparedRolesDeprecated.The PreparedStatement to use for identifying the roles for a specified user.
- 
roleNameColDeprecated.The column in the user role table that names a role
- 
userCredColDeprecated.The column in the user table that holds the user's credentials
- 
userNameColDeprecated.The column in the user table that holds the user's name
- 
userRoleTableDeprecated.The table that holds the relation between user's and roles
- 
userTableDeprecated.The table that holds user data.
 
- 
- 
Constructor Details- 
JDBCRealmpublic JDBCRealm()Deprecated.
 
- 
- 
Method Details- 
getConnectionNameDeprecated.- Returns:
- the username to use to connect to the database.
 
- 
setConnectionNameDeprecated.Set the username to use to connect to the database.- Parameters:
- connectionName- Username
 
- 
getConnectionPasswordDeprecated.- Returns:
- the password to use to connect to the database.
 
- 
setConnectionPasswordDeprecated.Set the password to use to connect to the database.- Parameters:
- connectionPassword- User password
 
- 
getConnectionURLDeprecated.- Returns:
- the URL to use to connect to the database.
 
- 
setConnectionURLDeprecated.Set the URL to use to connect to the database.- Parameters:
- connectionURL- The new connection URL
 
- 
getDriverNameDeprecated.- Returns:
- the JDBC driver that will be used.
 
- 
setDriverNameDeprecated.Set the JDBC driver that will be used.- Parameters:
- driverName- The driver name
 
- 
getRoleNameColDeprecated.- Returns:
- the column in the user role table that names a role.
 
- 
setRoleNameColDeprecated.Set the column in the user role table that names a role.- Parameters:
- roleNameCol- The column name
 
- 
getUserCredColDeprecated.- Returns:
- the column in the user table that holds the user's credentials.
 
- 
setUserCredColDeprecated.Set the column in the user table that holds the user's credentials.- Parameters:
- userCredCol- The column name
 
- 
getUserNameColDeprecated.- Returns:
- the column in the user table that holds the user's name.
 
- 
setUserNameColDeprecated.Set the column in the user table that holds the user's name.- Parameters:
- userNameCol- The column name
 
- 
getUserRoleTableDeprecated.- Returns:
- the table that holds the relation between user's and roles.
 
- 
setUserRoleTableDeprecated.Set the table that holds the relation between user's and roles.- Parameters:
- userRoleTable- The table name
 
- 
getUserTableDeprecated.- Returns:
- the table that holds user data..
 
- 
setUserTableDeprecated.Set the table that holds user data.- Parameters:
- userTable- The table name
 
- 
authenticateDeprecated.Return the Principal associated with the specified username and credentials, if there is one; otherwise returnnull. If there are any errors with the JDBC connection, executing the query or anything we return null (don't authenticate). This event is also logged, and the connection will be closed so that a subsequent request will automatically re-open it.- Specified by:
- authenticatein interface- Realm
- Overrides:
- authenticatein class- RealmBase
- Parameters:
- username- Username of the Principal to look up
- credentials- Password or other credentials to use in authenticating this username
- Returns:
- the associated principal, or nullif there is none.
 
- 
authenticateDeprecated.Attempt to authenticate the user with the provided credentials.- Parameters:
- dbConnection- The database connection to be used
- username- Username of the Principal to look up
- credentials- Password or other credentials to use in authenticating this username
- Returns:
- Return the Principal associated with the specified username and credentials, if there is one; otherwise
             return null.
 
- 
isAvailablepublic boolean isAvailable()Deprecated.Description copied from interface:RealmReturn the availability of the realm for authentication.- Returns:
- trueif the realm is able to perform authentication
 
- 
closeDeprecated.Close the specified database connection.- Parameters:
- dbConnection- The connection to be closed
 
- 
credentialsprotected PreparedStatement credentials(Connection dbConnection, String username) throws SQLException Deprecated.Return a PreparedStatement configured to perform the SELECT required to retrieve user credentials for the specified username.- Parameters:
- dbConnection- The database connection to be used
- username- Username for which credentials should be retrieved
- Returns:
- the prepared statement
- Throws:
- SQLException- if a database error occurs
 
- 
getPasswordDeprecated.Get the password for the specified user.- Specified by:
- getPasswordin class- RealmBase
- Parameters:
- username- The user name
- Returns:
- the password associated with the given principal's user name.
 
- 
getPrincipalDeprecated.Get the principal associated with the specified user.- Specified by:
- getPrincipalin class- RealmBase
- Parameters:
- username- The user name
- Returns:
- the Principal associated with the given user name.
 
- 
getRolesDeprecated.Return the roles associated with the given user name.- Parameters:
- username- The user name
- Returns:
- an array list of the role names
 
- 
openDeprecated.Open (if necessary) and return a database connection for use by this Realm.- Returns:
- the opened connection
- Throws:
- SQLException- if a database error occurs
 
- 
rolesDeprecated.Return a PreparedStatement configured to perform the SELECT required to retrieve user roles for the specified username.- Parameters:
- dbConnection- The database connection to be used
- username- Username for which roles should be retrieved
- Returns:
- the prepared statement
- Throws:
- SQLException- if a database error occurs
 
- 
startInternalDeprecated.Prepare for the beginning of active use of the public methods of this component and implement the requirements ofLifecycleBase.startInternal().- Overrides:
- startInternalin class- RealmBase
- Throws:
- LifecycleException- if this component detects a fatal error that prevents this component from being used
 
- 
stopInternalDeprecated.Gracefully terminate the active use of the public methods of this component and implement the requirements ofLifecycleBase.stopInternal().- Overrides:
- stopInternalin class- RealmBase
- Throws:
- LifecycleException- if this component detects a fatal error that needs to be reported
 
 
-