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

## org.apache.tomcat.modules.aaa
Class JDBCRealm

    java.lang.Object
      org.apache.tomcat.core.BaseInterceptor
          org.apache.tomcat.modules.aaa.RealmBase
              org.apache.tomcat.modules.aaa.JDBCRealm

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.

Author:
  Craig R. McClanahan, Carson McDonald, Ignacio J. Ortega, Bip Thelin

Nested Class Summary
`static class` | `JDBCRealm.JdbcPrincipal`

Field Summary
`protected java.lang.String` | `connectionName` The connection URL to use when trying to connect to the databse
`protected java.lang.String` | `connectionPassword` The connection URL to use when trying to connect to the databse
`protected java.lang.String` | `connectionURL` The connection URL to use when trying to connect to the databse
`protected java.lang.String` | `driverName` The JDBC driver to use.
`protected boolean` | `JDBCStarted` Has the JDBC connection been started?
`protected java.lang.String` | `roleNameCol` The column in the user role table that names a role
`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.tomcat.modules.aaa.RealmBase
`digest, sm`

Fields inherited from class org.apache.tomcat.core.BaseInterceptor
`cm, ct, ctx, debug, DECLINED, loghelper, OK`

Constructor Summary
`JDBCRealm()`

Method Summary
`void` | `contextInit(Context ctx)` Notify when a context is initialized.
`void` | `contextShutdown(Context ctx)` Called when a context is stoped, before removeContext.
`java.lang.String` | `getCredentials(java.lang.String username)` If there are any errors with the JDBC connection, executing the query or anything we return false (don't authenticate).
`protected java.sql.PreparedStatement` | `getPreparedAuthenticate(java.sql.Connection conn)`
`protected java.sql.PreparedStatement` | `getPreparedRoles(java.sql.Connection conn)`
`protected java.security.Principal` | `getPrincipal(java.lang.String username)` getPrincipal
`java.lang.String[]` | `getUserRoles(java.lang.String username)` returns all the roles for a given user.
`boolean` | `isConnectionNameSet()` Return status of connectionName
`boolean` | `isConnectionPasswordSet()` Return status of connectionPassword
`void` | `setConnectionName(java.lang.String connectionName)` Set the name 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` | `setConnectOnInit(boolean b)` When connectOnInit is true the JDBC connection is started at tomcat init if false the connection is started the first times it is needed.
`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 credintials
`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.

Methods inherited from class org.apache.tomcat.modules.aaa.RealmBase
`authenticate, digest, engineInit, getDigest, main, setDigest`

Methods inherited from class org.apache.tomcat.core.BaseInterceptor
`addContainer, addContext, addHandler, addInterceptor, addSecurityConstraint, afterBody, authorize, beforeBody, beforeCommit, contextMap, contextState, copyContext, engineShutdown, engineStart, engineState, engineStop, findSession, getContext, getContextManager, getDebug, getInfo, getLog, getNote, getNote, handleError, log, log, log, log, postInitCheck, postReadRequest, postRequest, postService, postServletDestroy, postServletInit, preInitCheck, preService, preServletDestroy, preServletInit, registerHooks, reload, removeContainer, removeContext, removeHandler, removeInterceptor, requestMap, sessionState, setContext, setContextManager, setDebug, setInfo, setNote, setNote`

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

Field Detail

### connectionURL

    protected java.lang.String connectionURL

  The connection URL to use when trying to connect to the databse

### connectionName

    protected java.lang.String connectionName

  The connection URL to use when trying to connect to the databse

### connectionPassword

    protected java.lang.String connectionPassword

  The connection URL to use when trying to connect to the databse

### userTable

    protected java.lang.String userTable

  The table that holds user data.

### userNameCol

    protected java.lang.String userNameCol

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

### userCredCol

    protected java.lang.String userCredCol

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

### userRoleTable

    protected java.lang.String userRoleTable

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

### roleNameCol

    protected java.lang.String roleNameCol

  The column in the user role table that names a role

### driverName

    protected java.lang.String driverName

  The JDBC driver to use.

### JDBCStarted

    protected boolean JDBCStarted

  Has the JDBC connection been started?

Constructor Detail

### JDBCRealm

    public JDBCRealm()

Method Detail

### setDriverName

    public void setDriverName(java.lang.String driverName)

  Set the JDBC driver that will be used.

  Parameters:
    `driverName` - The driver name

### setConnectionURL

    public void setConnectionURL(java.lang.String connectionURL)

  Set the URL to use to connect to the database.

  Parameters:
    `connectionURL` - The new connection URL

### setConnectionName

    public void setConnectionName(java.lang.String connectionName)

  Set the name to use to connect to the database.

  Parameters:
    `connectionName` - User name

### isConnectionNameSet

    public boolean isConnectionNameSet()

  Return status of connectionName

### setConnectionPassword

    public void setConnectionPassword(java.lang.String connectionPassword)

  Set the password to use to connect to the database.

  Parameters:
    `connectionPassword` - User password

### isConnectionPasswordSet

    public boolean isConnectionPasswordSet()

  Return status of connectionPassword

### setUserTable

    public void setUserTable(java.lang.String userTable)

  Set the table that holds user data.

  Parameters:
    `userTable` - The table 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

### setUserCredCol

    public void setUserCredCol(java.lang.String userCredCol)

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

  Parameters:
    `userCredCol` - 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

### 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

### setConnectOnInit

    public void setConnectOnInit(boolean b)

  When connectOnInit is true the JDBC connection is started at tomcat init if false the connection is started the first times it is needed.

  Parameters:
    `b` -

### getCredentials

    public java.lang.String getCredentials(java.lang.String username)

  If there are any errors with the JDBC connection, executing the query or anything we return false (don't authenticate). This event is also logged. If there is some SQL exception the connection is set to null. This will allow a retry on the next auth attempt. This might not be the best thing to do but it will keep tomcat from needing a restart if the database goes down.

  Specified by:
    `getCredentials` in class `RealmBase`
  Parameters:
    `username` - Username of the Principal to look up

### getPreparedAuthenticate

    protected java.sql.PreparedStatement getPreparedAuthenticate(java.sql.Connection conn)
                                                          throws java.sql.SQLException

  Throws:
    `java.sql.SQLException`

### getPreparedRoles

    protected java.sql.PreparedStatement getPreparedRoles(java.sql.Connection conn)
                                                   throws java.sql.SQLException

  Throws:
    `java.sql.SQLException`

### getUserRoles

    public java.lang.String[] getUserRoles(java.lang.String username)

  returns all the roles for a given user.

  Specified by:
    `getUserRoles` in class `RealmBase`
  Parameters:
    `username` - the user name
  Returns:
    the roles array

### contextShutdown

    public void contextShutdown(Context ctx)
                         throws TomcatException

  Description copied from class: `BaseInterceptor`
  Called when a context is stoped, before removeContext. You must free all resources associated with this context.

  Overrides:
    `contextShutdown` in class `BaseInterceptor`
  Throws:
    `TomcatException`

### contextInit

    public void contextInit(Context ctx)
                     throws TomcatException

  Description copied from class: `BaseInterceptor`
  Notify when a context is initialized. The first interceptor in the chain for contextInit must read web.xml and set the context. When this method is called you can expect the context to be filled in with all the informations from web.xml.

  Overrides:
    `contextInit` in class `BaseInterceptor`
  Throws:
    `TomcatException`

### getPrincipal

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

  getPrincipal

  Specified by:
    `getPrincipal` in class `RealmBase`
  Parameters:
    `username` -
  Returns:
    java.security.Principal

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

Copyright © 2001 Apache Software Foundation. All Rights Reserved.