org.apache.catalina.users
Class MemoryUserDatabase

java.lang.Object
  extended byorg.apache.catalina.users.MemoryUserDatabase
All Implemented Interfaces:
UserDatabase

public class MemoryUserDatabase
extends java.lang.Object
implements UserDatabase

Concrete implementation of UserDatabase that loads all defined users, groups, and roles into an in-memory data structure, and uses a specified XML file for its persistent storage.

Since:
4.1
Version:
$Id: MemoryUserDatabase.java 1140072 2011-06-27 09:28:44Z markt $
Author:
Craig R. McClanahan

Field Summary
protected  java.util.HashMap groups
          The set of Groups defined in this database, keyed by group name.
protected  java.lang.String id
          The unique global identifier of this user database.
protected  java.lang.String pathname
          The relative (to catalina.base) or absolute pathname to the XML file in which we will save our persistent information.
protected  java.lang.String pathnameNew
          The relative or absolute pathname ot the file in which we write our new information prior to renaming.
protected  java.lang.String pathnameOld
          The relative or absolute pathname to the file in which our old information is stored while renaming is in progress.
protected  boolean readonly
          A flag, indicating if the user database is read only.
protected  java.util.HashMap roles
          The set of Roles defined in this database, keyed by role name.
protected  java.util.HashMap users
          The set of Users defined in this database, keyed by user name.
 
Constructor Summary
MemoryUserDatabase()
          Create a new instance with default values.
MemoryUserDatabase(java.lang.String id)
          Create a new instance with the specified values.
 
Method Summary
 void close()
          Finalize access to this user database.
 Group createGroup(java.lang.String groupname, java.lang.String description)
          Create and return a new Group defined in this user database.
 Role createRole(java.lang.String rolename, java.lang.String description)
          Create and return a new Role defined in this user database.
 User createUser(java.lang.String username, java.lang.String password, java.lang.String fullName)
          Create and return a new User defined in this user database.
 Group findGroup(java.lang.String groupname)
          Return the Group with the specified group name, if any; otherwise return null.
 Role findRole(java.lang.String rolename)
          Return the Role with the specified role name, if any; otherwise return null.
 User findUser(java.lang.String username)
          Return the User with the specified user name, if any; otherwise return null.
 java.util.Iterator getGroups()
          Return the set of Groups defined in this user database.
 java.lang.String getId()
          Return the unique global identifier of this user database.
 java.lang.String getPathname()
          Return the relative or absolute pathname to the persistent storage file.
 boolean getReadonly()
          Returning the readonly status of the user database
 java.util.Iterator getRoles()
          Return the set of Roles defined in this user database.
 java.util.Iterator getUsers()
          Return the set of Users defined in this user database.
 boolean isWriteable()
          Check for permissions to save this user database to persistent storage location
 void open()
          Initialize access to this user database.
 void removeGroup(Group group)
          Remove the specified Group from this user database.
 void removeRole(Role role)
          Remove the specified Role from this user database.
 void removeUser(User user)
          Remove the specified User from this user database.
 void save()
          Save any updated information to the persistent storage location for this user database.
 void setPathname(java.lang.String pathname)
          Set the relative or absolute pathname to the persistent storage file.
 void setReadonly(boolean readonly)
          Setting the readonly status of the user database
 java.lang.String toString()
          Return a String representation of this UserDatabase.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

groups

protected java.util.HashMap groups
The set of Groups defined in this database, keyed by group name.


id

protected java.lang.String id
The unique global identifier of this user database.


pathname

protected java.lang.String pathname
The relative (to catalina.base) or absolute pathname to the XML file in which we will save our persistent information.


pathnameOld

protected java.lang.String pathnameOld
The relative or absolute pathname to the file in which our old information is stored while renaming is in progress.


pathnameNew

protected java.lang.String pathnameNew
The relative or absolute pathname ot the file in which we write our new information prior to renaming.


readonly

protected boolean readonly
A flag, indicating if the user database is read only.


roles

protected java.util.HashMap roles
The set of Roles defined in this database, keyed by role name.


users

protected java.util.HashMap users
The set of Users defined in this database, keyed by user name.

Constructor Detail

MemoryUserDatabase

public MemoryUserDatabase()
Create a new instance with default values.


MemoryUserDatabase

public MemoryUserDatabase(java.lang.String id)
Create a new instance with the specified values.

Parameters:
id - Unique global identifier of this user database
Method Detail

getGroups

public java.util.Iterator getGroups()
Return the set of Groups defined in this user database.

Specified by:
getGroups in interface UserDatabase

getId

public java.lang.String getId()
Return the unique global identifier of this user database.

Specified by:
getId in interface UserDatabase

getPathname

public java.lang.String getPathname()
Return the relative or absolute pathname to the persistent storage file.


setPathname

public void setPathname(java.lang.String pathname)
Set the relative or absolute pathname to the persistent storage file.

Parameters:
pathname - The new pathname

getReadonly

public boolean getReadonly()
Returning the readonly status of the user database


setReadonly

public void setReadonly(boolean readonly)
Setting the readonly status of the user database

Parameters:
readonly - The new readonly status

getRoles

public java.util.Iterator getRoles()
Return the set of Roles defined in this user database.

Specified by:
getRoles in interface UserDatabase

getUsers

public java.util.Iterator getUsers()
Return the set of Users defined in this user database.

Specified by:
getUsers in interface UserDatabase

close

public void close()
           throws java.lang.Exception
Finalize access to this user database.

Specified by:
close in interface UserDatabase
Throws:
java.lang.Exception - if any exception is thrown during closing

createGroup

public Group createGroup(java.lang.String groupname,
                         java.lang.String description)
Create and return a new Group defined in this user database.

Specified by:
createGroup in interface UserDatabase
Parameters:
groupname - The group name of the new group (must be unique)
description - The description of this group

createRole

public Role createRole(java.lang.String rolename,
                       java.lang.String description)
Create and return a new Role defined in this user database.

Specified by:
createRole in interface UserDatabase
Parameters:
rolename - The role name of the new group (must be unique)
description - The description of this group

createUser

public User createUser(java.lang.String username,
                       java.lang.String password,
                       java.lang.String fullName)
Create and return a new User defined in this user database.

Specified by:
createUser in interface UserDatabase
Parameters:
username - The logon username of the new user (must be unique)
password - The logon password of the new user
fullName - The full name of the new user

findGroup

public Group findGroup(java.lang.String groupname)
Return the Group with the specified group name, if any; otherwise return null.

Specified by:
findGroup in interface UserDatabase
Parameters:
groupname - Name of the group to return

findRole

public Role findRole(java.lang.String rolename)
Return the Role with the specified role name, if any; otherwise return null.

Specified by:
findRole in interface UserDatabase
Parameters:
rolename - Name of the role to return

findUser

public User findUser(java.lang.String username)
Return the User with the specified user name, if any; otherwise return null.

Specified by:
findUser in interface UserDatabase
Parameters:
username - Name of the user to return

open

public void open()
          throws java.lang.Exception
Initialize access to this user database.

Specified by:
open in interface UserDatabase
Throws:
java.lang.Exception - if any exception is thrown during opening

removeGroup

public void removeGroup(Group group)
Remove the specified Group from this user database.

Specified by:
removeGroup in interface UserDatabase
Parameters:
group - The group to be removed

removeRole

public void removeRole(Role role)
Remove the specified Role from this user database.

Specified by:
removeRole in interface UserDatabase
Parameters:
role - The role to be removed

removeUser

public void removeUser(User user)
Remove the specified User from this user database.

Specified by:
removeUser in interface UserDatabase
Parameters:
user - The user to be removed

isWriteable

public boolean isWriteable()
Check for permissions to save this user database to persistent storage location


save

public void save()
          throws java.lang.Exception
Save any updated information to the persistent storage location for this user database.

Specified by:
save in interface UserDatabase
Throws:
java.lang.Exception - if any exception is thrown during saving

toString

public java.lang.String toString()
Return a String representation of this UserDatabase.



Copyright © 2000-2012 Apache Software Foundation. All Rights Reserved.