org.apache.catalina.realm

Class MemoryRealm

Implemented Interfaces:
Lifecycle, MBeanRegistration, Realm
Known Direct Subclasses:
JAASMemoryLoginModule

public class MemoryRealm
extends RealmBase

Simple implementation of Realm that reads an XML file to configure the valid users, passwords, and roles. The file format (and default file location) are identical to those currently supported by Tomcat 3.X.

IMPLEMENTATION NOTE: It is assumed that the in-memory collection representing our defined users (and their roles) is initialized at application startup and never modified again. Therefore, no thread synchronization is performed around accesses to the principals collection.

Version:
$Revision: 1.4.2.1 $ $Date: 2004/11/17 17:07:20 $

Author:
Craig R. McClanahan

Field Summary

protected String
info
Descriptive information about this Realm implementation.
protected static String
name
Descriptive information about this Realm implementation.

Fields inherited from class org.apache.catalina.realm.RealmBase

container, controller, debug, digest, digestEncoding, domain, host, info, initialized, lifecycle, md, md5Encoder, md5Helper, mserver, oname, path, sm, started, support, type, validate

Fields inherited from interface org.apache.catalina.Lifecycle

AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, START_EVENT, STOP_EVENT

Method Summary

Principal
authenticate(String username, String credentials)
Return the Principal associated with the specified username and credentials, if there is one; otherwise return null.
protected Digester
getDigester()
Return a configured Digester to use for processing the XML input file, creating a new one if necessary.
String
getInfo()
Return descriptive information about this Realm implementation and the corresponding version number, in the format <description>/<version>.
protected String
getName()
Return a short name for this Realm implementation.
protected String
getPassword(String username)
Return the password associated with the given principal's user name.
String
getPathname()
Return the pathname of our XML file containing user definitions.
protected Principal
getPrincipal(String username)
Return the Principal associated with the given user name.
protected Map
getPrincipals()
Returns the collection of valid principals for this realm.
void
setPathname(String pathname)
Set the pathname of our XML file containing user definitions.
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

Digest, addLifecycleListener, addPropertyChangeListener, authenticate, authenticate, authenticate, authenticate, destroy, digest, findLifecycleListeners, findSecurityConstraints, getContainer, getController, getDebug, getDigest, getDigest, getDigestEncoding, getDomain, getInfo, getName, getObjectName, getPassword, getPrincipal, getType, getValidate, hasMessageDigest, hasResourcePermission, hasRole, hasUserDataPermission, init, log, log, main, postDeregister, postRegister, preDeregister, preRegister, removeLifecycleListener, removePropertyChangeListener, setContainer, setController, setDebug, setDigest, setDigestEncoding, setValidate, start, stop

Field Details

info

protected final String info
Descriptive information about this Realm implementation.


name

protected static final String name
Descriptive information about this Realm implementation.

Method Details

authenticate

public Principal authenticate(String username,
                              String credentials)
Return the Principal associated with the specified username and credentials, if there is one; otherwise return null.
Specified by:
authenticate in interface Realm
Overrides:
authenticate in interface RealmBase

Parameters:
username - Username of the Principal to look up
credentials - Password or other credentials to use in authenticating this username


getDigester

protected Digester getDigester()
Return a configured Digester to use for processing the XML input file, creating a new one if necessary.


getInfo

public String getInfo()
Return descriptive information about this Realm implementation and the corresponding version number, in the format <description>/<version>.
Specified by:
getInfo in interface Realm
Overrides:
getInfo in interface RealmBase


getName

protected String getName()
Return a short name for this Realm implementation.
Overrides:
getName in interface RealmBase


getPassword

protected String getPassword(String username)
Return the password associated with the given principal's user name.
Overrides:
getPassword in interface RealmBase


getPathname

public String getPathname()
Return the pathname of our XML file containing user definitions.


getPrincipal

protected Principal getPrincipal(String username)
Return the Principal associated with the given user name.
Overrides:
getPrincipal in interface RealmBase


getPrincipals

protected Map getPrincipals()
Returns the collection of valid principals for this realm. The keys to the map are Strings, the user names.

Returns:
The principals


setPathname

public void setPathname(String pathname)
Set the pathname of our XML file containing user definitions. If a relative pathname is specified, it is resolved against "catalina.base".

Parameters:
pathname - The new pathname


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 interface RealmBase

Throws:
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 interface RealmBase

Throws:
LifecycleException - if this component detects a fatal error that needs to be reported


Copyright B) 2000-2003 Apache Software Foundation. All Rights Reserved.