org.mortbay.http

Class JDBCUserRealm

Implemented Interfaces:
Externalizable, SSORealm, UserRealm

public class JDBCUserRealm
extends HashUserRealm

HashMapped User Realm with JDBC as data source. JDBCUserRealm extends HashUserRealm and adds a method to fetch user information from database. The authenticate() method checks the inherited HashMap for the user. If the user is not found, it will fetch details from the database and populate the inherited HashMap. It then calls the HashUserRealm authenticate() method to perform the actual authentication. Periodically (controlled by configuration parameter), internal hashes are cleared. Caching can be disabled by setting cache refresh interval to zero. Uses one database connection that is initialized at startup. Reconnect on failures. authenticate() is 'synchronized'. An example properties file for configuration is in $JETTY_HOME/etc/jdbcRealm.properties
Version:
$Id: JDBCUserRealm.java,v 1.19 2005/08/13 00:01:24 gregwilkins Exp $
Authors:
Arkadi Shishlov (arkadi)
Fredrik Borgh
Greg Wilkins (gregw)
Ben Alex

Field Summary

Fields inherited from class org.mortbay.http.HashUserRealm

__SSO, _roles

Constructor Summary

JDBCUserRealm(String name)
Constructor.
JDBCUserRealm(String name, String config)
Constructor.

Method Summary

Principal
authenticate(String username, Object credentials, HttpRequest request)
Principal
authenticate(String username, String credentials, HttpRequest request)
void
connectDatabase()
(re)Connect to database with parameters setup by loadConfig()
void
loadConfig(String config)
Load JDBC connection configuration from properties file.
void
logout(Principal user)

Methods inherited from class org.mortbay.http.HashUserRealm

addUserToRole, authenticate, clearSingleSignOn, disassociate, dump, getName, getPrincipal, getSSORealm, getSingleSignOn, isUserInRole, load, logout, popRole, pushRole, put, readExternal, reauthenticate, setName, setSSORealm, setSingleSignOn, toString, writeExternal

Constructor Details

JDBCUserRealm

public JDBCUserRealm(String name)
Constructor.
Parameters:
name -

JDBCUserRealm

public JDBCUserRealm(String name,
                     String config)
            throws IOException,
                   ClassNotFoundException,
                   InstantiationException,
                   IllegalAccessException
Constructor.
Parameters:
name - Realm name
config - Filename or url of JDBC connection properties file.

Method Details

authenticate

public Principal authenticate(String username,
                              Object credentials,
                              HttpRequest request)
Specified by:
authenticate in interface UserRealm
Overrides:
authenticate in interface HashUserRealm

authenticate

public Principal authenticate(String username,
                              String credentials,
                              HttpRequest request)

connectDatabase

public void connectDatabase()
(re)Connect to database with parameters setup by loadConfig()

loadConfig

public void loadConfig(String config)
            throws IOException
Load JDBC connection configuration from properties file.
Parameters:
config - Filename or url of user properties file.

logout

public void logout(Principal user)
Specified by:
logout in interface UserRealm
Overrides:
logout in interface HashUserRealm

Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.