|
Apache Tomcat 6.0.53 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.catalina.realm.RealmBase org.apache.catalina.realm.JDBCRealm
public class JDBCRealm
Implmentation 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
.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class org.apache.catalina.realm.RealmBase |
---|
RealmBase.AllRolesMode |
Field Summary | |
---|---|
protected java.lang.String |
connectionName
The connection username to use when trying to connect to the database. |
protected java.lang.String |
connectionPassword
The connection URL to use when trying to connect to the database. |
protected java.lang.String |
connectionURL
The connection URL to use when trying to connect to the database. |
protected java.sql.Connection |
dbConnection
The connection to the database. |
protected java.sql.Driver |
driver
Instance of the JDBC Driver class we use as a connection factory. |
protected java.lang.String |
driverName
The JDBC driver to use. |
protected static java.lang.String |
info
Descriptive information about this Realm implementation. |
protected static java.lang.String |
name
Descriptive information about this Realm implementation. |
protected java.sql.PreparedStatement |
preparedCredentials
The PreparedStatement to use for authenticating users. |
protected java.sql.PreparedStatement |
preparedRoles
The PreparedStatement to use for identifying the roles for a specified user. |
protected java.lang.String |
roleNameCol
The column in the user role table that names a role |
protected static StringManager |
sm
The string manager for this package. |
protected java.lang.String |
userCredCol
The column in the user table that holds the user's credintials |
protected java.lang.String |
userNameCol
The column in the user table that holds the user's name |
protected java.lang.String |
userRoleTable
The table that holds the relation between user's and roles |
protected java.lang.String |
userTable
The table that holds user data. |
Fields inherited from class org.apache.catalina.realm.RealmBase |
---|
allRolesMode, container, containerLog, controller, digest, digestEncoding, domain, host, initialized, lifecycle, md, md5Encoder, md5Helper, mserver, oname, path, realmPath, started, support, type, validate, x509UsernameRetriever, x509UsernameRetrieverClassName |
Fields inherited from interface org.apache.catalina.Lifecycle |
---|
AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, DESTROY_EVENT, INIT_EVENT, PERIODIC_EVENT, START_EVENT, STOP_EVENT |
Constructor Summary | |
---|---|
JDBCRealm()
|
Method Summary | |
---|---|
java.security.Principal |
authenticate(java.sql.Connection dbConnection,
java.lang.String username,
java.lang.String credentials)
Return the Principal associated with the specified username and credentials, if there is one; otherwise return null . |
java.security.Principal |
authenticate(java.lang.String username,
java.lang.String credentials)
Return the Principal associated with the specified username and credentials, if there is one; otherwise return null . |
protected void |
close(java.sql.Connection dbConnection)
Close the specified database connection. |
protected java.sql.PreparedStatement |
credentials(java.sql.Connection dbConnection,
java.lang.String username)
Return a PreparedStatement configured to perform the SELECT required to retrieve user credentials for the specified username. |
java.lang.String |
getConnectionName()
Return the username to use to connect to the database. |
java.lang.String |
getConnectionPassword()
Return the password to use to connect to the database. |
java.lang.String |
getConnectionURL()
Return the URL to use to connect to the database. |
java.lang.String |
getDriverName()
Return the JDBC driver that will be used. |
java.lang.String |
getInfo()
Return descriptive information about this Realm implementation and the corresponding version number, in the format <description>/<version> . |
protected java.lang.String |
getName()
Return a short name for this Realm implementation. |
protected java.lang.String |
getPassword(java.lang.String username)
Return the password associated with the given principal's user name. |
protected java.security.Principal |
getPrincipal(java.lang.String username)
Return the Principal associated with the given user name. |
java.lang.String |
getRoleNameCol()
Return the column in the user role table that names a role. |
protected java.util.ArrayList<java.lang.String> |
getRoles(java.lang.String username)
Return the roles associated with the gven user name. |
java.lang.String |
getUserCredCol()
Return the column in the user table that holds the user's credentials. |
java.lang.String |
getUserNameCol()
Return the column in the user table that holds the user's name. |
java.lang.String |
getUserRoleTable()
Return the table that holds the relation between user's and roles. |
java.lang.String |
getUserTable()
Return the table that holds user data.. |
protected java.sql.Connection |
open()
Open (if necessary) and return a database connection for use by this Realm. |
protected void |
release(java.sql.Connection dbConnection)
Release our use of this connection so that it can be recycled. |
protected java.sql.PreparedStatement |
roles(java.sql.Connection dbConnection,
java.lang.String username)
Return a PreparedStatement configured to perform the SELECT required to retrieve user roles for the specified username. |
void |
setConnectionName(java.lang.String connectionName)
Set the username to use to connect to the database. |
void |
setConnectionPassword(java.lang.String connectionPassword)
Set the password to use to connect to the database. |
void |
setConnectionURL(java.lang.String connectionURL)
Set the URL to use to connect to the database. |
void |
setDriverName(java.lang.String driverName)
Set the JDBC driver that will be used. |
void |
setRoleNameCol(java.lang.String roleNameCol)
Set the column in the user role table that names a role. |
void |
setUserCredCol(java.lang.String userCredCol)
Set the column in the user table that holds the user's credentials. |
void |
setUserNameCol(java.lang.String userNameCol)
Set the column in the user table that holds the user's name. |
void |
setUserRoleTable(java.lang.String userRoleTable)
Set the table that holds the relation between user's and roles. |
void |
setUserTable(java.lang.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 java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.lang.String connectionName
protected java.lang.String connectionPassword
protected java.lang.String connectionURL
protected java.sql.Connection dbConnection
protected java.sql.Driver driver
protected java.lang.String driverName
protected static final java.lang.String info
protected static final java.lang.String name
protected java.sql.PreparedStatement preparedCredentials
protected java.sql.PreparedStatement preparedRoles
protected java.lang.String roleNameCol
protected static final StringManager sm
protected java.lang.String userCredCol
protected java.lang.String userNameCol
protected java.lang.String userRoleTable
protected java.lang.String userTable
Constructor Detail |
---|
public JDBCRealm()
Method Detail |
---|
public java.lang.String getConnectionName()
public void setConnectionName(java.lang.String connectionName)
connectionName
- Usernamepublic java.lang.String getConnectionPassword()
public void setConnectionPassword(java.lang.String connectionPassword)
connectionPassword
- User passwordpublic java.lang.String getConnectionURL()
public void setConnectionURL(java.lang.String connectionURL)
connectionURL
- The new connection URLpublic java.lang.String getDriverName()
public void setDriverName(java.lang.String driverName)
driverName
- The driver namepublic java.lang.String getRoleNameCol()
public void setRoleNameCol(java.lang.String roleNameCol)
roleNameCol
- The column namepublic java.lang.String getUserCredCol()
public void setUserCredCol(java.lang.String userCredCol)
userCredCol
- The column namepublic java.lang.String getUserNameCol()
public void setUserNameCol(java.lang.String userNameCol)
userNameCol
- The column namepublic java.lang.String getUserRoleTable()
public void setUserRoleTable(java.lang.String userRoleTable)
userRoleTable
- The table namepublic java.lang.String getUserTable()
public void setUserTable(java.lang.String userTable)
userTable
- The table namepublic java.lang.String getInfo()
<description>/<version>
.
getInfo
in interface Realm
getInfo
in class RealmBase
public java.security.Principal authenticate(java.lang.String username, java.lang.String credentials)
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.
authenticate
in interface Realm
authenticate
in class RealmBase
username
- Username of the Principal to look upcredentials
- Password or other credentials to use in
authenticating this usernamepublic java.security.Principal authenticate(java.sql.Connection dbConnection, java.lang.String username, java.lang.String credentials)
null
.
dbConnection
- The database connection to be usedusername
- Username of the Principal to look upcredentials
- Password or other credentials to use in
authenticating this usernameprotected void close(java.sql.Connection dbConnection)
dbConnection
- The connection to be closedprotected java.sql.PreparedStatement credentials(java.sql.Connection dbConnection, java.lang.String username) throws java.sql.SQLException
dbConnection
- The database connection to be usedusername
- Username for which credentials should be retrieved
java.sql.SQLException
- if a database error occursprotected java.lang.String getName()
getName
in class RealmBase
protected java.lang.String getPassword(java.lang.String username)
getPassword
in class RealmBase
protected java.security.Principal getPrincipal(java.lang.String username)
getPrincipal
in class RealmBase
protected java.util.ArrayList<java.lang.String> getRoles(java.lang.String username)
protected java.sql.Connection open() throws java.sql.SQLException
java.sql.SQLException
- if a database error occursprotected void release(java.sql.Connection dbConnection)
dbConnection
- The connection to be releasedprotected java.sql.PreparedStatement roles(java.sql.Connection dbConnection, java.lang.String username) throws java.sql.SQLException
dbConnection
- The database connection to be usedusername
- Username for which roles should be retrieved
java.sql.SQLException
- if a database error occurspublic void start() throws LifecycleException
start
in interface Lifecycle
start
in class RealmBase
LifecycleException
- if this component detects a fatal error
that prevents it from being startedpublic void stop() throws LifecycleException
stop
in interface Lifecycle
stop
in class RealmBase
LifecycleException
- if this component detects a fatal error
that needs to be reported
|
Apache Tomcat 6.0.53 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |