Package org.apache.catalina.realm
Class DataSourceRealm
java.lang.Object
org.apache.catalina.util.LifecycleBase
org.apache.catalina.util.LifecycleMBeanBase
org.apache.catalina.realm.RealmBase
org.apache.catalina.realm.DataSourceRealm
- All Implemented Interfaces:
- MBeanRegistration,- Contained,- JmxEnabled,- Lifecycle,- Realm
Implementation of Realm that works with any JDBC JNDI DataSource. See the Realm How-To for more details on how
 to set up the database and for configuration options.
- Author:
- Glenn L. Nielsen, 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 StringThe name of the JNDI JDBC DataSourceprotected booleanContext local datasource.protected StringThe column in the user role table that names a roleprotected StringThe column in the user table that holds the user's credentialsprotected StringThe column in the user table that holds the user's nameprotected StringThe table that holds the relation between user's and rolesprotected StringThe 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 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) Try to authenticate using the specified username and credentials.protected Principalauthenticate(Connection dbConnection, String username, String credentials) Return the Principal associated with the specified username and credentials, if there is one; otherwise returnnull.protected voidclose(Connection dbConnection) Close the specified database connection.booleanprotected StringgetPassword(String username) Get the password for the specified user.protected StringgetPassword(Connection dbConnection, String username) Return the password associated with the given principal's user name.protected PrincipalgetPrincipal(String username) Return the Principal associated with the given user name.Return the roles associated with the given user name.getRoles(Connection dbConnection, String username) Return the roles associated with the given user name.booleanReturn the availability of the realm for authentication.protected Connectionopen()Open the specified database connection.voidsetDataSourceName(String dataSourceName) Set the name of the JNDI JDBC DataSource.voidsetLocalDataSource(boolean localDataSource) Set to true to cause the datasource to be looked up in the webapp JNDI Context.voidsetRoleNameCol(String roleNameCol) Set the column in the user role table that names a role.voidsetUserCredCol(String userCredCol) Set the column in the user table that holds the user's credentials.voidsetUserNameCol(String userNameCol) Set the column in the user table that holds the user's name.voidsetUserRoleTable(String userRoleTable) Set the table that holds the relation between user's and roles.voidsetUserTable(String userTable) Set the table that holds user data.protected voidPrepare for the beginning of active use of the public methods of this component and implement the requirements ofLifecycleBase.startInternal().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, getRealmPath, getRealmSuffix, getServer, getTransportGuaranteeRedirectStatus, getUserAttributes, getValidate, getX509UsernameRetrieverClassName, hasMessageDigest, hasResourcePermission, hasRole, hasRoleInternal, hasUserDataPermission, initInternal, isStripRealmForGss, main, parseUserAttributes, removePropertyChangeListener, setAllRolesMode, setContainer, setCredentialHandler, setRealmPath, setStripRealmForGss, setTransportGuaranteeRedirectStatus, setUserAttributes, setValidate, setX509UsernameRetrieverClassName, stopInternal, 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- 
dataSourceNameThe name of the JNDI JDBC DataSource
- 
localDataSourceprotected boolean localDataSourceContext local datasource.
- 
roleNameColThe column in the user role table that names a role
- 
userCredColThe column in the user table that holds the user's credentials
- 
userNameColThe column in the user table that holds the user's name
- 
userRoleTableThe table that holds the relation between user's and roles
- 
userTableThe table that holds user data.
 
- 
- 
Constructor Details- 
DataSourceRealmpublic DataSourceRealm()
 
- 
- 
Method Details- 
getDataSourceName- Returns:
- the name of the JNDI JDBC DataSource.
 
- 
setDataSourceNameSet the name of the JNDI JDBC DataSource.- Parameters:
- dataSourceName- the name of the JNDI JDBC DataSource
 
- 
getLocalDataSourcepublic boolean getLocalDataSource()- Returns:
- if the datasource will be looked up in the webapp JNDI Context.
 
- 
setLocalDataSourcepublic void setLocalDataSource(boolean localDataSource) Set to true to cause the datasource to be looked up in the webapp JNDI Context.- Parameters:
- localDataSource- the new flag value
 
- 
getRoleNameCol- Returns:
- the column in the user role table that names a role.
 
- 
setRoleNameColSet the column in the user role table that names a role.- Parameters:
- roleNameCol- The column name
 
- 
getUserCredCol- Returns:
- the column in the user table that holds the user's credentials.
 
- 
setUserCredColSet the column in the user table that holds the user's credentials.- Parameters:
- userCredCol- The column name
 
- 
getUserNameCol- Returns:
- the column in the user table that holds the user's name.
 
- 
setUserNameColSet the column in the user table that holds the user's name.- Parameters:
- userNameCol- The column name
 
- 
getUserRoleTable- Returns:
- the table that holds the relation between user's and roles.
 
- 
setUserRoleTableSet the table that holds the relation between user's and roles.- Parameters:
- userRoleTable- The table name
 
- 
getUserTable- Returns:
- the table that holds user data..
 
- 
setUserTableSet the table that holds user data.- Parameters:
- userTable- The table name
 
- 
authenticateTry to authenticate using the specified username and credentials.If there are any errors with the JDBC connection, executing the query or anything this method returns null (doesn'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
 
- 
isAvailablepublic boolean isAvailable()Description copied from interface:RealmReturn the availability of the realm for authentication.- Returns:
- trueif the realm is able to perform authentication
 
- 
authenticateReturn the Principal associated with the specified username and credentials, if there is one; otherwise returnnull.- 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:
- the associated principal, or nullif there is none.
 
- 
closeClose the specified database connection.- Parameters:
- dbConnection- The connection to be closed
 
- 
openOpen the specified database connection.- Returns:
- Connection to the database
 
- 
getPasswordDescription copied from class:RealmBaseGet 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.
 
- 
getPasswordReturn the password associated with the given principal's user name.- Parameters:
- dbConnection- The database connection to be used
- username- Username for which password should be retrieved
- Returns:
- the password for the specified user
 
- 
getPrincipalReturn the Principal associated with the given user name.- Specified by:
- getPrincipalin class- RealmBase
- Parameters:
- username- the user name
- Returns:
- the principal object
 
- 
getRolesReturn the roles associated with the given user name.- Parameters:
- username- User name for which roles should be retrieved
- Returns:
- an array list of the role names
 
- 
getRolesReturn the roles associated with the given user name.- Parameters:
- dbConnection- The database connection to be used
- username- User name for which roles should be retrieved
- Returns:
- an array list of the role names
 
- 
startInternalDescription copied from class:RealmBasePrepare 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
 
 
-