Package org.apache.catalina.users
Class MemoryUserDatabase
- java.lang.Object
- 
- org.apache.catalina.users.MemoryUserDatabase
 
- 
- All Implemented Interfaces:
- UserDatabase
 
 public class MemoryUserDatabase extends java.lang.Object implements UserDatabase Concrete implementation ofUserDatabasethat 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 SummaryFields Modifier and Type Field Description protected java.util.Map<java.lang.String,Group>groupsThe set ofGroups defined in this database, keyed by group name.protected java.lang.StringidThe unique global identifier of this user database.protected java.lang.StringpathnameThe relative (tocatalina.base) or absolute pathname to the XML file in which we will save our persistent information.protected java.lang.StringpathnameNewThe relative or absolute pathname of the file in which we write our new information prior to renaming.protected java.lang.StringpathnameOldThe relative or absolute pathname to the file in which our old information is stored while renaming is in progress.protected booleanreadonlyA flag, indicating if the user database is read only.protected java.util.Map<java.lang.String,Role>rolesThe set ofRoles defined in this database, keyed by role name.protected java.util.Map<java.lang.String,User>usersThe set ofUsers defined in this database, keyed by user name.
 - 
Constructor SummaryConstructors Constructor Description MemoryUserDatabase()Create a new instance with default values.MemoryUserDatabase(java.lang.String id)Create a new instance with the specified values.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidbackgroundProcess()voidclose()Finalize access to this user database.GroupcreateGroup(java.lang.String groupname, java.lang.String description)Create and return a newGroupdefined in this user database.RolecreateRole(java.lang.String rolename, java.lang.String description)Create and return a newRoledefined in this user database.UsercreateUser(java.lang.String username, java.lang.String password, java.lang.String fullName)Create and return a newUserdefined in this user database.GroupfindGroup(java.lang.String groupname)Return theGroupwith the specified group name, if any; otherwise returnnull.RolefindRole(java.lang.String rolename)Return theRolewith the specified role name, if any; otherwise returnnull.UserfindUser(java.lang.String username)Return theUserwith the specified user name, if any; otherwise returnnull.java.util.Iterator<Group>getGroups()java.lang.StringgetId()java.lang.StringgetPathname()booleangetReadonly()java.util.Iterator<Role>getRoles()java.util.Iterator<User>getUsers()booleangetWatchSource()booleanisWritable()Check for permissions to save this user database to persistent storage location.booleanisWriteable()Deprecated.UseisWritable().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(java.lang.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)java.lang.StringtoString()Return a String representation of this UserDatabase.
 
- 
- 
- 
Field Detail- 
groupsprotected final java.util.Map<java.lang.String,Group> groups The set ofGroups defined in this database, keyed by group name.
 - 
idprotected final java.lang.String id The unique global identifier of this user database.
 - 
pathnameprotected java.lang.String pathname The relative (tocatalina.base) or absolute pathname to the XML file in which we will save our persistent information.
 - 
pathnameOldprotected java.lang.String pathnameOld The relative or absolute pathname to the file in which our old information is stored while renaming is in progress.
 - 
pathnameNewprotected java.lang.String pathnameNew The relative or absolute pathname of the file in which we write our new information prior to renaming.
 - 
readonlyprotected boolean readonly A flag, indicating if the user database is read only.
 - 
rolesprotected final java.util.Map<java.lang.String,Role> roles The set ofRoles defined in this database, keyed by role name.
 
- 
 - 
Method Detail- 
getGroupspublic java.util.Iterator<Group> getGroups() - Specified by:
- getGroupsin interface- UserDatabase
- Returns:
- the set of Groups defined in this user database.
 
 - 
getIdpublic java.lang.String getId() - Specified by:
- getIdin interface- UserDatabase
- Returns:
- the unique global identifier of this user database.
 
 - 
getPathnamepublic java.lang.String getPathname() - Returns:
- the relative or absolute pathname to the persistent storage file.
 
 - 
setPathnamepublic void setPathname(java.lang.String pathname) Set the relative or absolute pathname to the persistent storage file.- Parameters:
- pathname- The new pathname
 
 - 
getReadonlypublic boolean getReadonly() - Returns:
- the readonly status of the user database
 
 - 
setReadonlypublic void setReadonly(boolean readonly) Setting the readonly status of the user database- Parameters:
- readonly- the new status
 
 - 
getWatchSourcepublic boolean getWatchSource() 
 - 
setWatchSourcepublic void setWatchSource(boolean watchSource) 
 - 
getRolespublic java.util.Iterator<Role> getRoles() - Specified by:
- getRolesin interface- UserDatabase
- Returns:
- the set of Roles defined in this user database.
 
 - 
getUserspublic java.util.Iterator<User> getUsers() - Specified by:
- getUsersin interface- UserDatabase
- Returns:
- the set of Users defined in this user database.
 
 - 
closepublic void close() throws java.lang.ExceptionFinalize access to this user database.- Specified by:
- closein interface- UserDatabase
- Throws:
- java.lang.Exception- if any exception is thrown during closing
 
 - 
createGrouppublic Group createGroup(java.lang.String groupname, java.lang.String description) Create and return a newGroupdefined in this user database.- Specified by:
- createGroupin interface- UserDatabase
- Parameters:
- groupname- The group name of the new group (must be unique)
- description- The description of this group
- Returns:
- The new group
 
 - 
createRolepublic Role createRole(java.lang.String rolename, java.lang.String description) Create and return a newRoledefined in this user database.- Specified by:
- createRolein interface- UserDatabase
- Parameters:
- rolename- The role name of the new group (must be unique)
- description- The description of this group
- Returns:
- The new role
 
 - 
createUserpublic User createUser(java.lang.String username, java.lang.String password, java.lang.String fullName) Create and return a newUserdefined in this user database.- Specified by:
- createUserin 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
- Returns:
- The new user
 
 - 
findGrouppublic Group findGroup(java.lang.String groupname) Return theGroupwith the specified group name, if any; otherwise returnnull.- Specified by:
- findGroupin interface- UserDatabase
- Parameters:
- groupname- Name of the group to return
- Returns:
- the Groupwith the specified group name, if any; otherwise returnnull.
 
 - 
findRolepublic Role findRole(java.lang.String rolename) Return theRolewith the specified role name, if any; otherwise returnnull.- Specified by:
- findRolein interface- UserDatabase
- Parameters:
- rolename- Name of the role to return
- Returns:
- the Rolewith the specified role name, if any; otherwise returnnull.
 
 - 
findUserpublic User findUser(java.lang.String username) Return theUserwith the specified user name, if any; otherwise returnnull.- Specified by:
- findUserin interface- UserDatabase
- Parameters:
- username- Name of the user to return
- Returns:
- the Userwith the specified user name, if any; otherwise returnnull.
 
 - 
openpublic void open() throws java.lang.ExceptionInitialize access to this user database.- Specified by:
- openin interface- UserDatabase
- Throws:
- java.lang.Exception- if any exception is thrown during opening
 
 - 
removeGrouppublic void removeGroup(Group group) Remove the specifiedGroupfrom this user database.- Specified by:
- removeGroupin interface- UserDatabase
- Parameters:
- group- The group to be removed
 
 - 
removeRolepublic void removeRole(Role role) Remove the specifiedRolefrom this user database.- Specified by:
- removeRolein interface- UserDatabase
- Parameters:
- role- The role to be removed
 
 - 
removeUserpublic void removeUser(User user) Remove the specifiedUserfrom this user database.- Specified by:
- removeUserin interface- UserDatabase
- Parameters:
- user- The user to be removed
 
 - 
isWriteable@Deprecated public boolean isWriteable() Deprecated.UseisWritable(). This method will be removed in Tomcat 10.1.x onwards.Check for permissions to save this user database to persistent storage location.- Returns:
- trueif the database is writable
 
 - 
isWritablepublic boolean isWritable() Check for permissions to save this user database to persistent storage location.- Returns:
- trueif the database is writable
 
 - 
savepublic void save() throws java.lang.ExceptionSave any updated information to the persistent storage location for this user database.- Specified by:
- savein interface- UserDatabase
- Throws:
- java.lang.Exception- if any exception is thrown during saving
 
 - 
backgroundProcesspublic void backgroundProcess() 
 - 
toStringpublic java.lang.String toString() Return a String representation of this UserDatabase.- Overrides:
- toStringin class- java.lang.Object
 
 
- 
 
-