Save This Page
Home » apache-tomcat-6.0.16-src » org.apache » catalina » realm » [javadoc | source]
org.apache.catalina.realm
public class: JDBCRealm [javadoc | source]
java.lang.Object
   org.apache.catalina.realm.RealmBase
      org.apache.catalina.realm.JDBCRealm

All Implemented Interfaces:
    Realm, MBeanRegistration, Lifecycle

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.

TODO - Support connection pooling (including message format objects) so that authenticate(), getPassword() and authenticate() do not have to be synchronized and would fix the ugly connection logic.

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 final  String info    Descriptive information about this Realm implementation. 
protected static final  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 final  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 org.apache.catalina.realm.RealmBase:
container,  containerLog,  digest,  digestEncoding,  info,  lifecycle,  md,  md5Encoder,  md5Helper,  sm,  started,  support,  validate,  allRolesMode,  type,  domain,  host,  path,  oname,  controller,  mserver,  initialized
Method from org.apache.catalina.realm.JDBCRealm Summary:
authenticate,   authenticate,   close,   credentials,   getConnectionName,   getConnectionPassword,   getConnectionURL,   getDriverName,   getName,   getPassword,   getPrincipal,   getRoleNameCol,   getRoles,   getUserCredCol,   getUserNameCol,   getUserRoleTable,   getUserTable,   open,   release,   roles,   setConnectionName,   setConnectionPassword,   setConnectionURL,   setDriverName,   setRoleNameCol,   setUserCredCol,   setUserNameCol,   setUserRoleTable,   setUserTable,   start,   stop
Methods from org.apache.catalina.realm.RealmBase:
Digest,   addLifecycleListener,   addPropertyChangeListener,   authenticate,   authenticate,   authenticate,   authenticate,   backgroundProcess,   destroy,   digest,   findLifecycleListeners,   findSecurityConstraints,   getAllRolesMode,   getContainer,   getController,   getDigest,   getDigest,   getDigestEncoding,   getDomain,   getInfo,   getName,   getObjectName,   getPassword,   getPrincipal,   getPrincipal,   getType,   getValidate,   hasMessageDigest,   hasResourcePermission,   hasRole,   hasUserDataPermission,   init,   main,   postDeregister,   postRegister,   preDeregister,   preRegister,   removeLifecycleListener,   removePropertyChangeListener,   setAllRolesMode,   setContainer,   setController,   setDigest,   setDigestEncoding,   setValidate,   start,   stop
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.catalina.realm.JDBCRealm Detail:
 public synchronized 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.
 public synchronized 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) throws SQLException 
    Return a PreparedStatement configured to perform the SELECT required to retrieve user credentials for the specified username.
 public String getConnectionName() 
    Return the username to use to connect to the database.
 public String getConnectionPassword() 
    Return the password to use to connect to the database.
 public String getConnectionURL() 
    Return the URL to use to connect to the database.
 public String getDriverName() 
    Return the JDBC driver that will be used.
 protected String getName() 
    Return a short name for this Realm implementation.
 protected synchronized 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.
 public String getRoleNameCol() 
    Return the column in the user role table that names a role.
 protected ArrayList getRoles(String username) 
    Return the roles associated with the gven user name.
 public String getUserCredCol() 
    Return the column in the user table that holds the user's credentials.
 public String getUserNameCol() 
    Return the column in the user table that holds the user's name.
 public String getUserRoleTable() 
    Return the table that holds the relation between user's and roles.
 public String getUserTable() 
    Return the table that holds user data..
 protected Connection open() throws SQLException 
    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 synchronized PreparedStatement roles(Connection dbConnection,
    String username) throws SQLException 
    Return a PreparedStatement configured to perform the SELECT required to retrieve user roles for the specified username.
 public  void setConnectionName(String connectionName) 
    Set the username to use to connect to the database.
 public  void setConnectionPassword(String connectionPassword) 
    Set the password to use to connect to the database.
 public  void setConnectionURL(String connectionURL) 
    Set the URL to use to connect to the database.
 public  void setDriverName(String driverName) 
    Set the JDBC driver that will be used.
 public  void setRoleNameCol(String roleNameCol) 
    Set the column in the user role table that names a role.
 public  void setUserCredCol(String userCredCol) 
    Set the column in the user table that holds the user's credentials.
 public  void setUserNameCol(String userNameCol) 
    Set the column in the user table that holds the user's name.
 public  void setUserRoleTable(String userRoleTable) 
    Set the table that holds the relation between user's and roles.
 public  void setUserTable(String userTable) 
    Set the table that holds user data.
 public  void start() throws LifecycleException 
    Prepare for active use of the public methods of this Component.
 public  void stop() throws LifecycleException 
    Gracefully shut down active use of the public methods of this Component.