org.apache.catalina.realm

Class DataSourceRealm

Implemented Interfaces:
Lifecycle, MBeanRegistration, Realm

public class DataSourceRealm
extends RealmBase

Implmentation of Realm that works with any JDBC JNDI DataSource. See the JDBCRealm.howto for more details on how to set up the database and for configuration options.

Version:
$Revision: 1.8.2.1 $

Authors:
Glenn L. Nielsen
Craig R. McClanahan
Carson McDonald
Ignacio Ortega

Field Summary

protected String
dataSourceName
The name of the JNDI JDBC DataSource
protected static String
info
Descriptive information about this Realm implementation.
protected boolean
localDataSource
Context local datasource.
protected static String
name
Descriptive information about this Realm implementation.
protected String
roleNameCol
The column in the user role table that names a role
protected static StringManager
sm
The string manager for this package.
protected String
userCredCol
The column in the user table that holds the user's credintials
protected String
userNameCol
The column in the user table that holds the user's name
protected String
userRoleTable
The table that holds the relation between user's and roles
protected String
userTable
The table that holds user data.

Fields inherited from class org.apache.catalina.realm.RealmBase

container, controller, debug, digest, digestEncoding, domain, host, info, initialized, lifecycle, md, md5Encoder, md5Helper, mserver, oname, path, sm, started, support, type, validate

Fields inherited from interface org.apache.catalina.Lifecycle

AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, START_EVENT, STOP_EVENT

Method Summary

protected Principal
authenticate(Connection dbConnection, String username, String credentials)
Return the Principal associated with the specified username and credentials, if there is one; otherwise return null.
Principal
authenticate(String username, String credentials)
Return the Principal associated with the specified username and credentials, if there is one; otherwise return null.
protected void
close(Connection dbConnection)
Close the specified database connection.
String
getDataSourceName()
Return the name of the JNDI JDBC DataSource.
boolean
getLocalDataSource()
Return if the datasource will be looked up in the webapp JNDI Context.
protected String
getName()
Return a short name for this Realm implementation.
protected String
getPassword(String username)
Return the password associated with the given principal's user name.
protected Principal
getPrincipal(String username)
Return the Principal associated with the given user name.
String
getRoleNameCol()
Return the column in the user role table that names a role.
String
getUserCredCol()
Return the column in the user table that holds the user's credentials.
String
getUserNameCol()
Return the column in the user table that holds the user's name.
String
getUserRoleTable()
Return the table that holds the relation between user's and roles.
String
getUserTable()
Return the table that holds user data..
protected Connection
open()
Open the specified database connection.
void
setDataSourceName(String dataSourceName)
Set the name of the JNDI JDBC DataSource.
void
setLocalDataSource(boolean localDataSource)
Set to true to cause the datasource to be looked up in the webapp JNDI Context.
void
setRoleNameCol(String roleNameCol)
Set the column in the user role table that names a role.
void
setUserCredCol(String userCredCol)
Set the column in the user table that holds the user's credentials.
void
setUserNameCol(String userNameCol)
Set the column in the user table that holds the user's name.
void
setUserRoleTable(String userRoleTable)
Set the table that holds the relation between user's and roles.
void
setUserTable(String userTable)
Set the table that holds user data.
void
start()
Prepare for active use of the public methods of this Component.
void
stop()
Gracefully shut down active use of the public methods of this Component.

Methods inherited from class org.apache.catalina.realm.RealmBase

Digest, addLifecycleListener, addPropertyChangeListener, authenticate, authenticate, authenticate, authenticate, destroy, digest, findLifecycleListeners, findSecurityConstraints, getContainer, getController, getDebug, getDigest, getDigest, getDigestEncoding, getDomain, getInfo, getName, getObjectName, getPassword, getPrincipal, getType, getValidate, hasMessageDigest, hasResourcePermission, hasRole, hasUserDataPermission, init, log, log, main, postDeregister, postRegister, preDeregister, preRegister, removeLifecycleListener, removePropertyChangeListener, setContainer, setController, setDebug, setDigest, setDigestEncoding, setValidate, start, stop

Field Details

dataSourceName

protected String dataSourceName
The name of the JNDI JDBC DataSource


info

protected static final String info
Descriptive information about this Realm implementation.


localDataSource

protected boolean localDataSource
Context local datasource.


name

protected static final String name
Descriptive information about this Realm implementation.


roleNameCol

protected String roleNameCol
The column in the user role table that names a role


sm

protected static final StringManager sm
The string manager for this package.


userCredCol

protected String userCredCol
The column in the user table that holds the user's credintials


userNameCol

protected String userNameCol
The column in the user table that holds the user's name


userRoleTable

protected String userRoleTable
The table that holds the relation between user's and roles


userTable

protected String userTable
The table that holds user data.

Method Details

authenticate

protected Principal authenticate(Connection dbConnection,
                                 String username,
                                 String credentials)
            throws SQLException
Return the Principal associated with the specified username and credentials, if there is one; otherwise return null.

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


authenticate

public Principal authenticate(String username,
                              String credentials)
Return the Principal associated with the specified username and credentials, if there is one; otherwise return null. 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:
authenticate in interface Realm
Overrides:
authenticate in interface RealmBase

Parameters:
username - Username of the Principal to look up
credentials - Password or other credentials to use in authenticating this username


close

protected void close(Connection dbConnection)
Close the specified database connection.

Parameters:
dbConnection - The connection to be closed


getDataSourceName

public String getDataSourceName()
Return the name of the JNDI JDBC DataSource.


getLocalDataSource

public boolean getLocalDataSource()
Return if the datasource will be looked up in the webapp JNDI Context.


getName

protected String getName()
Return a short name for this Realm implementation.
Overrides:
getName in interface RealmBase


getPassword

protected String getPassword(String username)
Return the password associated with the given principal's user name.
Overrides:
getPassword in interface RealmBase


getPrincipal

protected Principal getPrincipal(String username)
Return the Principal associated with the given user name.
Overrides:
getPrincipal in interface RealmBase


getRoleNameCol

public String getRoleNameCol()
Return the column in the user role table that names a role.


getUserCredCol

public String getUserCredCol()
Return the column in the user table that holds the user's credentials.


getUserNameCol

public String getUserNameCol()
Return the column in the user table that holds the user's name.


getUserRoleTable

public String getUserRoleTable()
Return the table that holds the relation between user's and roles.


getUserTable

public String getUserTable()
Return the table that holds user data..


open

protected Connection open()
Open the specified database connection.

Returns:
Connection to the database


setDataSourceName

public void setDataSourceName(String dataSourceName)
Set the name of the JNDI JDBC DataSource.

Parameters:
dataSourceName - the name of the JNDI JDBC DataSource


setLocalDataSource

public 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


setRoleNameCol

public void setRoleNameCol(String roleNameCol)
Set the column in the user role table that names a role.

Parameters:
roleNameCol - The column name


setUserCredCol

public void setUserCredCol(String userCredCol)
Set the column in the user table that holds the user's credentials.

Parameters:
userCredCol - The column name


setUserNameCol

public void setUserNameCol(String userNameCol)
Set the column in the user table that holds the user's name.

Parameters:
userNameCol - The column name


setUserRoleTable

public void setUserRoleTable(String userRoleTable)
Set the table that holds the relation between user's and roles.

Parameters:
userRoleTable - The table name


setUserTable

public void setUserTable(String userTable)
Set the table that holds user data.

Parameters:
userTable - The table name


start

public void start()
            throws LifecycleException
Prepare for active use of the public methods of this Component.
Specified by:
start in interface Lifecycle
Overrides:
start in interface RealmBase

Throws:
LifecycleException - if this component detects a fatal error that prevents it from being started


stop

public void stop()
            throws LifecycleException
Gracefully shut down active use of the public methods of this Component.
Specified by:
stop in interface Lifecycle
Overrides:
stop in interface RealmBase

Throws:
LifecycleException - if this component detects a fatal error that needs to be reported


Copyright B) 2000-2003 Apache Software Foundation. All Rights Reserved.