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
Modifier and TypeFieldDescriptionThe set ofGroup
s defined in this database, keyed by group name.protected final String
The unique global identifier of this user database.protected String
The relative (tocatalina.base
) or absolute pathname to the XML file in which we will save our persistent information.protected String
The relative or absolute pathname of the file in which we write our new information prior to renaming.protected String
The relative or absolute pathname to the file in which our old information is stored while renaming is in progress.protected boolean
A flag, indicating if the user database is read only.The set ofRole
s defined in this database, keyed by role name.The set ofUser
s defined in this database, keyed by user name. -
Constructor Summary
ConstructorDescriptionCreate a new instance with default values.Create a new instance with the specified values. -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
close()
Finalize access to this user database.createGroup
(String groupname, String description) Create and return a newGroup
defined in this user database.createRole
(String rolename, String description) Create and return a newRole
defined in this user database.createUser
(String username, String password, String fullName) Create and return a newUser
defined in this user database.Return theGroup
with the specified group name, if any; otherwise returnnull
.Return theRole
with the specified role name, if any; otherwise returnnull
.Return theUser
with the specified user name, if any; otherwise returnnull
.getId()
boolean
getRoles()
getUsers()
boolean
boolean
Check for permissions to save this user database to persistent storage location.boolean
Deprecated.void
open()
Initialize access to this user database.void
removeGroup
(Group group) Remove the specifiedGroup
from this user database.void
removeRole
(Role role) Remove the specifiedRole
from this user database.void
removeUser
(User user) Remove the specifiedUser
from this user database.void
save()
Save any updated information to the persistent storage location for this user database.void
setPathname
(String pathname) Set the relative or absolute pathname to the persistent storage file.void
setReadonly
(boolean readonly) Setting the readonly status of the user databasevoid
setWatchSource
(boolean watchSource) toString()
Return a String representation of this UserDatabase.
-
Field Details
-
groups
The set ofGroup
s defined in this database, keyed by group name. -
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
The set ofRole
s defined in this database, keyed by role name. -
users
The set ofUser
s defined in this database, keyed by user name.
-
-
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:
getGroups
in interfaceUserDatabase
- Returns:
- the set of
Group
s defined in this user database.
-
getId
- Specified by:
getId
in 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:
getRoles
in interfaceUserDatabase
- Returns:
- the set of
Role
s defined in this user database.
-
getUsers
- Specified by:
getUsers
in interfaceUserDatabase
- Returns:
- the set of
User
s defined in this user database.
-
close
Finalize access to this user database.- Specified by:
close
in interfaceUserDatabase
- Throws:
Exception
- if any exception is thrown during closing
-
createGroup
Create and return a newGroup
defined in this user database.- Specified by:
createGroup
in interfaceUserDatabase
- Parameters:
groupname
- The group name of the new group (must be unique)description
- The description of this group- Returns:
- The new group
-
createRole
Create and return a newRole
defined in this user database.- Specified by:
createRole
in interfaceUserDatabase
- Parameters:
rolename
- The role name of the new group (must be unique)description
- The description of this group- Returns:
- The new role
-
createUser
Create and return a newUser
defined in this user database.- Specified by:
createUser
in 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
Return theGroup
with the specified group name, if any; otherwise returnnull
.- Specified by:
findGroup
in interfaceUserDatabase
- Parameters:
groupname
- Name of the group to return- Returns:
- the
Group
with the specified group name, if any; otherwise returnnull
.
-
findRole
Return theRole
with the specified role name, if any; otherwise returnnull
.- Specified by:
findRole
in interfaceUserDatabase
- Parameters:
rolename
- Name of the role to return- Returns:
- the
Role
with the specified role name, if any; otherwise returnnull
.
-
findUser
Return theUser
with the specified user name, if any; otherwise returnnull
.- Specified by:
findUser
in interfaceUserDatabase
- Parameters:
username
- Name of the user to return- Returns:
- the
User
with the specified user name, if any; otherwise returnnull
.
-
open
Initialize access to this user database.- Specified by:
open
in interfaceUserDatabase
- Throws:
Exception
- if any exception is thrown during opening
-
removeGroup
Remove the specifiedGroup
from this user database.- Specified by:
removeGroup
in interfaceUserDatabase
- Parameters:
group
- The group to be removed
-
removeRole
Remove the specifiedRole
from this user database.- Specified by:
removeRole
in interfaceUserDatabase
- Parameters:
role
- The role to be removed
-
removeUser
Remove the specifiedUser
from this user database.- Specified by:
removeUser
in interfaceUserDatabase
- Parameters:
user
- The user to be removed
-
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:
true
if the database is writable
-
isWritable
public boolean isWritable()Check for permissions to save this user database to persistent storage location.- Returns:
true
if the database is writable
-
save
Save any updated information to the persistent storage location for this user database.- Specified by:
save
in interfaceUserDatabase
- Throws:
Exception
- if any exception is thrown during saving
-
backgroundProcess
public void backgroundProcess() -
toString
Return a String representation of this UserDatabase.
-
isWritable()
.