org.apache.catalina.users

Class MemoryUserDatabase

public class MemoryUserDatabase extends 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: $Revision: 777556 $ $Date: 2009-05-22 16:59:34 +0200 (Fri, 22 May 2009) $

Author: Craig R. McClanahan

Field Summary
protected HashMapgroups
The set of Groups defined in this database, keyed by group name.
protected Stringid
The unique global identifier of this user database.
protected Stringpathname
The relative (to catalina.base) or absolute pathname to the XML file in which we will save our persistent information.
protected StringpathnameNew
The relative or absolute pathname ot the file in which we write our new information prior to renaming.
protected StringpathnameOld
The relative or absolute pathname to the file in which our old information is stored while renaming is in progress.
protected booleanreadonly
A flag, indicating if the user database is read only.
protected HashMaproles
The set of Roles defined in this database, keyed by role name.
protected HashMapusers
The set of Users defined in this database, keyed by user name.
Constructor Summary
MemoryUserDatabase()
Create a new instance with default values.
MemoryUserDatabase(String id)
Create a new instance with the specified values.
Method Summary
voidclose()
Finalize access to this user database.
GroupcreateGroup(String groupname, String description)
Create and return a new Group defined in this user database.
RolecreateRole(String rolename, String description)
Create and return a new Role defined in this user database.
UsercreateUser(String username, String password, String fullName)
Create and return a new User defined in this user database.
GroupfindGroup(String groupname)
Return the Group with the specified group name, if any; otherwise return null.
RolefindRole(String rolename)
Return the Role with the specified role name, if any; otherwise return null.
UserfindUser(String username)
Return the User with the specified user name, if any; otherwise return null.
IteratorgetGroups()
Return the set of Groups defined in this user database.
StringgetId()
Return the unique global identifier of this user database.
StringgetPathname()
Return the relative or absolute pathname to the persistent storage file.
booleangetReadonly()
Returning the readonly status of the user database
IteratorgetRoles()
Return the set of Roles defined in this user database.
IteratorgetUsers()
Return the set of Users defined in this user database.
booleanisWriteable()
Check for permissions to save this user database to persistent storage location
voidopen()
Initialize access to this user database.
voidremoveGroup(Group group)
Remove the specified Group from this user database.
voidremoveRole(Role role)
Remove the specified Role from this user database.
voidremoveUser(User user)
Remove the specified User from this user database.
voidsave()
Save any updated information to the persistent storage location for this user database.
voidsetPathname(String pathname)
Set the relative or absolute pathname to the persistent storage file.
voidsetReadonly(boolean readonly)
Setting the readonly status of the user database
StringtoString()
Return a String representation of this UserDatabase.

Field Detail

groups

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

id

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

pathname

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

pathnameNew

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

pathnameOld

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

readonly

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

roles

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

users

protected 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(String id)
Create a new instance with the specified values.

Parameters: id Unique global identifier of this user database

Method Detail

close

public void close()
Finalize access to this user database.

Throws: Exception if any exception is thrown during closing

createGroup

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

Parameters: groupname The group name of the new group (must be unique) description The description of this group

createRole

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

Parameters: rolename The role name of the new group (must be unique) description The description of this group

createUser

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

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(String groupname)
Return the Group with the specified group name, if any; otherwise return null.

Parameters: groupname Name of the group to return

findRole

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

Parameters: rolename Name of the role to return

findUser

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

Parameters: username Name of the user to return

getGroups

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

getId

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

getPathname

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

getReadonly

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

getRoles

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

getUsers

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

isWriteable

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

open

public void open()
Initialize access to this user database.

Throws: Exception if any exception is thrown during opening

removeGroup

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

Parameters: group The group to be removed

removeRole

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

Parameters: role The role to be removed

removeUser

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

Parameters: user The user to be removed

save

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

Throws: Exception if any exception is thrown during saving

setPathname

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

Parameters: pathname The new pathname

setReadonly

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

Parameters: pathname The new pathname

toString

public String toString()
Return a String representation of this UserDatabase.
Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.