Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.catalina.realm
Class JDBCRealm

    java.lang.Object
      |
      +--org.apache.catalina.realm.RealmBase
            |
            +--org.apache.catalina.realm.JDBCRealm

All Implemented Interfaces:
  Lifecycle, Realm

public class JDBCRealm
extends RealmBase

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()` does not have to be synchronized.

Version:
  $Revision: 1.19 $ $Date: 2001/09/07 20:45:12 $
Author:
  Craig R. McClanahan, Carson McDonald, Ignacio Ortega

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
`container, debug, digest, lifecycle, md, md5Encoder, md5Helper, started, support, validate`

Fields inherited from interface org.apache.catalina.Lifecycle
`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.
`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.
`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 org.apache.catalina.realm.RealmBase
`addLifecycleListener, addPropertyChangeListener, authenticate, authenticate, authenticate, digest, Digest, getContainer, getDebug, getDigest, getDigest, getInfo, getValidate, hasMessageDigest, hasRole, log, log, main, removeLifecycleListener, removePropertyChangeListener, setContainer, setDebug, setDigest, setValidate`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### connectionName

    protected java.lang.String connectionName

  The connection username to use when trying to connect to the database.

### connectionPassword

    protected java.lang.String connectionPassword

  The connection URL to use when trying to connect to the database.

### connectionURL

    protected java.lang.String connectionURL

  The connection URL to use when trying to connect to the database.

### dbConnection

    protected java.sql.Connection dbConnection

  The connection to the database.

### driver

    protected java.sql.Driver driver

  Instance of the JDBC Driver class we use as a connection factory.

### driverName

    protected java.lang.String driverName

  The JDBC driver to use.

### info

    protected static final java.lang.String info

  Descriptive information about this Realm implementation.

  See Also:
    Constant Field Values

### name

    protected static final java.lang.String name

  Descriptive information about this Realm implementation.

  See Also:
    Constant Field Values

### preparedCredentials

    protected java.sql.PreparedStatement preparedCredentials

  The PreparedStatement to use for authenticating users.

### preparedRoles

    protected java.sql.PreparedStatement preparedRoles

  The PreparedStatement to use for identifying the roles for a specified user.

### roleNameCol

    protected java.lang.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 java.lang.String userCredCol

  The column in the user table that holds the user's credintials

### userNameCol

    protected java.lang.String userNameCol

  The column in the user table that holds the user's name

### userRoleTable

    protected java.lang.String userRoleTable

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

### userTable

    protected java.lang.String userTable

  The table that holds user data.

Constructor Detail

### JDBCRealm

    public JDBCRealm()

Method Detail

### setConnectionName

    public void setConnectionName(java.lang.String connectionName)

  Set the username to use to connect to the database.

  Parameters:
    `connectionName` - Username

### setConnectionPassword

    public void setConnectionPassword(java.lang.String connectionPassword)

  Set the password to use to connect to the database.

  Parameters:
    `connectionPassword` - User password

### setConnectionURL

    public void setConnectionURL(java.lang.String connectionURL)

  Set the URL to use to connect to the database.

  Parameters:
    `connectionURL` - The new connection URL

### setDriverName

    public void setDriverName(java.lang.String driverName)

  Set the JDBC driver that will be used.

  Parameters:
    `driverName` - The driver name

### setRoleNameCol

    public void setRoleNameCol(java.lang.String roleNameCol)

  Set the column in the user role table that names a role.

  Parameters:
    `roleNameCol` - The column name

### setUserCredCol

    public void setUserCredCol(java.lang.String userCredCol)

  Set the column in the user table that holds the user's credentials.

  Parameters:
    `userCredCol` - The column name

### setUserNameCol

    public void setUserNameCol(java.lang.String userNameCol)

  Set the column in the user table that holds the user's name.

  Parameters:
    `userNameCol` - The column name

### setUserRoleTable

    public void setUserRoleTable(java.lang.String userRoleTable)

  Set the table that holds the relation between user's and roles.

  Parameters:
    `userRoleTable` - The table name

### setUserTable

    public void setUserTable(java.lang.String userTable)

  Set the table that holds user data.

  Parameters:
    `userTable` - The table name

### authenticate

    public 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`. 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 class `RealmBase`
  Parameters:
    `username` - Username of the Principal to look up
    `credentials` - Password or other credentials to use in authenticating this username

### authenticate

    public java.security.Principal authenticate(java.sql.Connection dbConnection,
                                                java.lang.String username,
                                                java.lang.String credentials)
                                         throws java.sql.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
  Throws:
    `java.sql.SQLException` - if a database error occurs

### close

    protected void close(java.sql.Connection dbConnection)

  Close the specified database connection.

  Parameters:
    `dbConnection` - The connection to be closed

### credentials

    protected java.sql.PreparedStatement credentials(java.sql.Connection dbConnection,
                                                     java.lang.String username)
                                              throws java.sql.SQLException

  Return a PreparedStatement configured to perform the SELECT required to retrieve user credentials for the specified username.

  Parameters:
    `dbConnection` - The database connection to be used
    `username` - Username for which credentials should be retrieved
  Throws:
    `java.sql.SQLException` - if a database error occurs

### getName

    protected java.lang.String getName()

  Return a short name for this Realm implementation.

  Specified by:
    `getName` in class `RealmBase`

### getPassword

    protected java.lang.String getPassword(java.lang.String username)

  Return the password associated with the given principal's user name.

  Specified by:
    `getPassword` in class `RealmBase`

### getPrincipal

    protected java.security.Principal getPrincipal(java.lang.String username)

  Return the Principal associated with the given user name.

  Specified by:
    `getPrincipal` in class `RealmBase`

### open

    protected java.sql.Connection open()
                                throws java.sql.SQLException

  Open (if necessary) and return a database connection for use by this Realm.

  Throws:
    `java.sql.SQLException` - if a database error occurs

### release

    protected void release(java.sql.Connection dbConnection)

  Release our use of this connection so that it can be recycled.

### roles

    protected java.sql.PreparedStatement roles(java.sql.Connection dbConnection,
                                               java.lang.String username)
                                        throws java.sql.SQLException

  Return a PreparedStatement configured to perform the SELECT required to retrieve user roles for the specified username.

  Parameters:
    `dbConnection` - The database connection to be used
    `username` - Username for which roles should be retrieved
  Throws:
    `java.sql.SQLException` - if a database error occurs

### 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 class `RealmBase`
  Throws:
    `java.lang.IllegalStateException` - if this component has already been started
    `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 class `RealmBase`
  Throws:
    `java.lang.IllegalStateException` - if this component has not been started
    `LifecycleException` - if this component detects a fatal error that needs to be reported

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000-2001 Apache Software Foundation. All Rights Reserved.