Package org.apache.catalina.users
Class MemoryUserDatabase
java.lang.Object
org.apache.catalina.users.MemoryUserDatabase
- All Implemented Interfaces:
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.
This class is thread-safe.
This class does not enforce what, in an RDBMS, would be called referential integrity. Concurrent modifications may result in inconsistent data such as a User retaining a reference to a Role that has been removed from the database.
- Since:
- 4.1
- Author:
- Craig R. McClanahan
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe set ofGroups defined in this database, keyed by group name.protected final StringThe unique global identifier of this user database.protected StringThe relative (tocatalina.base) or absolute pathname to the XML file in which we will save our persistent information.protected StringThe relative or absolute pathname of the file in which we write our new information prior to renaming.protected StringThe relative or absolute pathname to the file in which our old information is stored while renaming is in progress.protected booleanA flag, indicating if the user database is read only.The set ofRoles defined in this database, keyed by role name.The set ofUsers defined in this database, keyed by user name. -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new instance with default values.Create a new instance with the specified values. -
Method Summary
Modifier and TypeMethodDescriptionvoidPerform any background processing (e.g. checking for changes in persisted storage) required for the user database.voidclose()Finalize access to this user database.createGroup(String groupname, String description) Create and return a newGroupdefined in this user database.createRole(String rolename, String description) Create and return a newRoledefined in this user database.createUser(String username, String password, String fullName) Create and return a newUserdefined in this user database.getId()booleangetRoles()getUsers()booleanbooleanCheck for permissions to save this user database to persistent storage location.voidopen()Initialize access to this user database.voidremoveGroup(Group group) Remove the specifiedGroupfrom this user database.voidremoveRole(Role role) Remove the specifiedRolefrom this user database.voidremoveUser(User user) Remove the specifiedUserfrom 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 databasevoidsetWatchSource(boolean watchSource) toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.catalina.UserDatabase
isAvailable, isSparse, modifiedGroup, modifiedRole, modifiedUser
-
Field Details
-
groups
-
id
The unique global identifier of this user database. -
pathname
The relative (tocatalina.base) or absolute pathname to the XML file in which we will save our persistent information. -
pathnameOld
The relative or absolute pathname to the file in which our old information is stored while renaming is in progress. -
pathnameNew
The relative or absolute pathname of the file in which we write our new information prior to renaming. -
readonly
protected boolean readonlyA flag, indicating if the user database is read only. -
roles
-
users
-
-
Constructor Details
-
MemoryUserDatabase
public MemoryUserDatabase()Create a new instance with default values. -
MemoryUserDatabase
Create a new instance with the specified values.- Parameters:
id- Unique global identifier of this user database
-
-
Method Details
-
getGroups
- Specified by:
getGroupsin interfaceUserDatabase- Returns:
- the set of
Groups defined in this user database.
-
getId
- Specified by:
getIdin interfaceUserDatabase- Returns:
- the unique global identifier of this user database.
-
getPathname
- Returns:
- the relative or absolute pathname to the persistent storage file.
-
setPathname
Set the relative or absolute pathname to the persistent storage file.- Parameters:
pathname- The new pathname
-
getReadonly
public boolean getReadonly()- Returns:
- 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 status
-
getWatchSource
public boolean getWatchSource() -
setWatchSource
public void setWatchSource(boolean watchSource) -
getRoles
- Specified by:
getRolesin interfaceUserDatabase- Returns:
- the set of
Roles defined in this user database.
-
getUsers
- Specified by:
getUsersin interfaceUserDatabase- Returns:
- the set of
Users defined in this user database.
-
close
Description copied from interface:UserDatabaseFinalize access to this user database.- Specified by:
closein interfaceUserDatabase- Throws:
Exception- if any exception is thrown during closing
-
createGroup
Description copied from interface:UserDatabaseCreate and return a newGroupdefined in this user database.- Specified by:
createGroupin interfaceUserDatabase- Parameters:
groupname- The group name of the new group (must be unique)description- The description of this group- Returns:
- The new group
-
createRole
Description copied from interface:UserDatabaseCreate and return a newRoledefined in this user database.- Specified by:
createRolein interfaceUserDatabase- Parameters:
rolename- The role name of the new role (must be unique)description- The description of this role- Returns:
- The new role
-
createUser
Description copied from interface:UserDatabaseCreate and return a newUserdefined in this user database.- Specified by:
createUserin interfaceUserDatabase- Parameters:
username- The logon username of the new user (must be unique)password- The logon password of the new userfullName- The full name of the new user- Returns:
- The new user
-
findGroup
- Specified by:
findGroupin interfaceUserDatabase- Parameters:
groupname- Name of the group to return- Returns:
- the
Groupwith the specified group name, if any; otherwise returnnull.
-
findRole
- Specified by:
findRolein interfaceUserDatabase- Parameters:
rolename- Name of the role to return- Returns:
- the
Rolewith the specified role name, if any; otherwise returnnull.
-
findUser
- Specified by:
findUserin interfaceUserDatabase- Parameters:
username- Name of the user to return- Returns:
- the
Userwith the specified user name, if any; otherwise returnnull.
-
open
Description copied from interface:UserDatabaseInitialize access to this user database.- Specified by:
openin interfaceUserDatabase- Throws:
Exception- if any exception is thrown during opening
-
removeGroup
Description copied from interface:UserDatabaseRemove the specifiedGroupfrom this user database.- Specified by:
removeGroupin interfaceUserDatabase- Parameters:
group- The group to be removed
-
removeRole
Description copied from interface:UserDatabaseRemove the specifiedRolefrom this user database.- Specified by:
removeRolein interfaceUserDatabase- Parameters:
role- The role to be removed
-
removeUser
Description copied from interface:UserDatabaseRemove the specifiedUserfrom this user database.- Specified by:
removeUserin interfaceUserDatabase- Parameters:
user- The user to be removed
-
isWritable
public boolean isWritable()Check for permissions to save this user database to persistent storage location.- Returns:
trueif the database is writable
-
save
Description copied from interface:UserDatabaseSave any updated information to the persistent storage location for this user database.- Specified by:
savein interfaceUserDatabase- Throws:
Exception- if any exception is thrown during saving
-
backgroundProcess
public void backgroundProcess()Description copied from interface:UserDatabasePerform any background processing (e.g. checking for changes in persisted storage) required for the user database.- Specified by:
backgroundProcessin interfaceUserDatabase
-
toString
-