org.apache.catalina.realm
Class MemoryRealm

java.lang.Object
  |
  +--org.apache.catalina.realm.RealmBase
        |
        +--org.apache.catalina.realm.MemoryRealm
All Implemented Interfaces:
Lifecycle, Realm

public final 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.1 $ $Date: 2000/08/11 22:45:17 $
Author:
Craig R. McClanahan

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
MemoryRealm()
           
 
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.
 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 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.
 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 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 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

MemoryRealm

public MemoryRealm()
Method Detail

getContainer

public Container getContainer()
Return the Container with which this Realm has been associated.
Overrides:
getContainer in class RealmBase

setContainer

public void setContainer(Container container)
Set the Container with which this Realm has been associated.
Overrides:
setContainer in class RealmBase
Parameters:
container - The associated Container

getDebug

public int getDebug()
Return the debugging detail level for this component.
Overrides:
getDebug in class RealmBase

setDebug

public void setDebug(int debug)
Set the debugging detail level for this component.
Overrides:
setDebug in class RealmBase
Parameters:
debug - The new debugging detail level

getInfo

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

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a property change listener to this component.
Overrides:
addPropertyChangeListener in class RealmBase
Parameters:
listener - The listener to add

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.
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.lang.String username,
                                            byte[] credentials)
Return the Principal associated with the specified username and credentials, if there is one; otherwise return null.
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

hasRole

public 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.
Overrides:
hasRole in class RealmBase
Parameters:
principal - Principal for whom the role is to be checked
role - Security role to be checked

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a property change listener from this component.
Overrides:
removePropertyChangeListener in class RealmBase
Parameters:
listener - The listener to remove

getPassword

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

getPrincipal

protected java.security.Principal getPrincipal(java.lang.String username)
Return the Principal associated with the given user name.
Overrides:
getPrincipal in class RealmBase

addLifecycleListener

public void addLifecycleListener(LifecycleListener listener)
Add a lifecycle event listener to this component.
Overrides:
addLifecycleListener in class RealmBase
Parameters:
listener - The listener to add

removeLifecycleListener

public void removeLifecycleListener(LifecycleListener listener)
Remove a lifecycle event listener from this component.
Overrides:
removeLifecycleListener in class RealmBase
Parameters:
listener - The listener to remove

start

public void start()
           throws LifecycleException
Prepare for active use of the public methods of this Component.
Overrides:
start in class RealmBase
Throws:
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.
Overrides:
stop in class RealmBase
Throws:
IllegalStateException - if this component has not been started
LifecycleException - if this component detects a fatal error that needs to be reported


Copyright © 2000 Apache Software Foundation. All Rights Reserved.