org.apache.catalina.realm
public class JDBCRealm extends RealmBase
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
.
Version: $Revision: 892553 $ $Date: 2009-12-20 03:32:53 +0100 (Sun, 20 Dec 2009) $
Field Summary | |
---|---|
protected String | connectionName
The connection username to use when trying to connect to the database. |
protected String | connectionPassword
The connection URL to use when trying to connect to the database. |
protected String | connectionURL
The connection URL to use when trying to connect to the database. |
protected Connection | dbConnection
The connection to the database. |
protected Driver | driver
Instance of the JDBC Driver class we use as a connection factory. |
protected String | driverName
The JDBC driver to use. |
protected static String | info
Descriptive information about this Realm implementation. |
protected static String | name
Descriptive information about this Realm implementation. |
protected PreparedStatement | preparedCredentials
The PreparedStatement to use for authenticating users. |
protected PreparedStatement | preparedRoles
The PreparedStatement to use for identifying the roles for
a specified user. |
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. |
Method Summary | |
---|---|
Principal | authenticate(String username, String credentials)
Return the Principal associated with the specified username and
credentials, if there is one; otherwise return null .
|
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 .
|
protected void | close(Connection dbConnection)
Close the specified database connection.
|
protected PreparedStatement | credentials(Connection dbConnection, String username)
Return a PreparedStatement configured to perform the SELECT required
to retrieve user credentials for the specified username.
|
String | getConnectionName()
Return the username to use to connect to the database.
|
String | getConnectionPassword()
Return the password to use to connect to the database.
|
String | getConnectionURL()
Return the URL to use to connect to the database.
|
String | getDriverName()
Return the JDBC driver that will be used.
|
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.
|
protected ArrayList<String> | getRoles(String username)
Return the roles associated with the gven user name. |
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 (if necessary) and return a database connection for use by
this Realm.
|
protected void | release(Connection dbConnection)
Release our use of this connection so that it can be recycled.
|
protected PreparedStatement | roles(Connection dbConnection, String username)
Return a PreparedStatement configured to perform the SELECT required
to retrieve user roles for the specified username.
|
void | setConnectionName(String connectionName)
Set the username to use to connect to the database.
|
void | setConnectionPassword(String connectionPassword)
Set the password to use to connect to the database.
|
void | setConnectionURL(String connectionURL)
Set the URL to use to connect to the database.
|
void | setDriverName(String driverName)
Set the JDBC driver that will be used.
|
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.
|
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.
Parameters: username Username of the Principal to look up credentials Password or other credentials to use in authenticating this username
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
Parameters: dbConnection The connection to be closed
Parameters: dbConnection The database connection to be used username Username for which credentials should be retrieved
Throws: SQLException if a database error occurs
Throws: SQLException if a database error occurs
Parameters: dbConnection The connection to be released
Parameters: dbConnection The database connection to be used username Username for which roles should be retrieved
Throws: SQLException if a database error occurs
Parameters: connectionName Username
Parameters: connectionPassword User password
Parameters: connectionURL The new connection URL
Parameters: driverName The driver name
Parameters: roleNameCol The column name
Parameters: userCredCol The column name
Parameters: userNameCol The column name
Parameters: userRoleTable The table name
Parameters: userTable The table name
Throws: LifecycleException if this component detects a fatal error that prevents it from being started
Throws: LifecycleException if this component detects a fatal error that needs to be reported