|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.catalina.realm.RealmBase | +--org.apache.catalina.realm.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. TODO: - Work on authentication with non-plaintext passwords - Make sure no bad chars can get in and trick the auth and hasrole
Fields inherited from class org.apache.catalina.realm.RealmBase |
container, debug, info, lifecycle, md5Encoder, md5Helper, sm, started, support |
Fields inherited from interface org.apache.catalina.Lifecycle |
START_EVENT, STOP_EVENT |
Constructor Summary | |
JDBCRealm()
|
Method Summary | |
void |
addLifecycleListener(LifecycleListener listener)
Add a lifecycle event listener to this component. |
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a property change listener to this component. |
java.security.Principal |
authenticate(java.lang.String username,
byte[] 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 . |
static java.lang.String |
Digest(java.lang.String credentials,
java.lang.String algorithm)
Digest password using the algorithm especificied and convert the result to a corresponding hex string. |
Container |
getContainer()
Return the Container with which this Realm has been associated. |
int |
getDebug()
Return the debugging detail level for this component. |
java.lang.String |
getDigest()
Gets the digest algorithm used for credentials in the database could be the same that MessageDigest accepts vor algorithm and "No" that is the Default |
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 |
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. |
boolean |
hasRole(java.security.Principal principal,
java.lang.String role)
Return true if the specified Principal has the specified
security role, within the context of this Realm; otherwise return
false . |
static void |
main(java.lang.String[] args)
|
void |
removeLifecycleListener(LifecycleListener listener)
Remove a lifecycle event listener from this component. |
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a property change listener from this component. |
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 |
setContainer(Container container)
Set the Container with which this Realm has been associated. |
void |
setDebug(int debug)
Set the debugging detail level for this component. |
void |
setDigest(java.lang.String algorithm)
Gets the digest algorithm used for credentials in the database could be the same that MessageDigest accepts vor algorithm and "No" that is the Default |
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. |
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 |
authenticate, getDigest |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public JDBCRealm()
Method Detail |
public void setConnectionURL(java.lang.String connectionURL)
connectionURL
- The new connection URLpublic Container getContainer()
getContainer
in class RealmBase
public void setContainer(Container container)
setContainer
in class RealmBase
container
- The associated Containerpublic int getDebug()
getDebug
in class RealmBase
public void setDebug(int debug)
setDebug
in class RealmBase
debug
- The new debugging detail levelpublic void setDriverName(java.lang.String driverName)
driverName
- The driver namepublic java.lang.String getInfo()
<description>/<version>
.getInfo
in class RealmBase
public void setRoleNameCol(java.lang.String roleNameCol)
userRoleNameCol
- The column namepublic void setUserCredCol(java.lang.String userCredCol)
userCredCol
- The column namepublic void setUserNameCol(java.lang.String userNameCol)
userNameCol
- The column namepublic void setUserRoleTable(java.lang.String userRoleTable)
userRoleTable
- The table namepublic void setUserTable(java.lang.String userTable)
userTable
- The table namepublic void setConnectionName(java.lang.String connectionName)
connectionName
- User namepublic void setConnectionPassword(java.lang.String connectionPassword)
connectionPassword
- User passwordpublic java.lang.String getDigest()
public void setDigest(java.lang.String algorithm)
algorithm
- the Encode typepublic void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
addPropertyChangeListener
in class RealmBase
listener
- The listener to addpublic 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.
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 Catalina from needing a
restart if the database goes down.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.lang.String username, byte[] credentials)
null
.
See other authenticate for more details.authenticate
in class RealmBase
username
- Username of the Principal to look upcredentials
- Password or other credentials to use in
authenticating this usernamepublic boolean hasRole(java.security.Principal principal, java.lang.String role)
true
if the specified Principal has the specified
security role, within the context of this Realm; otherwise return
false
.
If there are any errors with the JDBC connection, executing
the query or anything we return false (not in role set). 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 Catalina from needing a
restart if the database goes down.hasRole
in class RealmBase
principal
- Principal for whom the role is to be checkedrole
- Security role to be checkedpublic void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
removePropertyChangeListener
in class RealmBase
listener
- The listener to removeprotected 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
public void addLifecycleListener(LifecycleListener listener)
addLifecycleListener
in class RealmBase
listener
- The listener to addpublic void removeLifecycleListener(LifecycleListener listener)
removeLifecycleListener
in class RealmBase
listener
- The listener to removepublic void start() throws LifecycleException
start
in class RealmBase
IllegalStateException
- if this component has already been
startedLifecycleException
- if this component detects a fatal error
that prevents it from being startedpublic void stop() throws LifecycleException
stop
in class RealmBase
IllegalStateException
- if this component has not been startedLifecycleException
- if this component detects a fatal error
that needs to be reportedpublic static final java.lang.String Digest(java.lang.String credentials, java.lang.String algorithm)
credentials
- Password or other credentials to use in
authenticating this usernamealgorithm
- Algorithm used to do th digestpublic static void main(java.lang.String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |