public class MemoryUserDatabase extends Object implements UserDatabase
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.
Modifier and Type | Field and Description |
---|---|
protected Map<String,Group> |
groups
The set of
Group s defined in this database, keyed by group name. |
protected String |
id
The unique global identifier of this user database.
|
protected String |
pathname
The relative (to
catalina.base ) or absolute pathname to the
XML file in which we will save our persistent information. |
protected String |
pathnameNew
The relative or absolute pathname of the file in which we write our new
information prior to renaming.
|
protected 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 Map<String,Role> |
roles
The set of
Role s defined in this database, keyed by role name. |
protected Map<String,User> |
users
The set of
User s defined in this database, keyed by user name. |
Constructor and Description |
---|
MemoryUserDatabase()
Create a new instance with default values.
|
MemoryUserDatabase(String id)
Create a new instance with the specified values.
|
Modifier and Type | Method and Description |
---|---|
void |
backgroundProcess()
Perform any background processing (e.g. checking for changes in persisted
storage) required for the user database.
|
void |
close()
Finalize access to this user database.
|
Group |
createGroup(String groupname,
String description)
Create and return a new
Group defined in this user database. |
Role |
createRole(String rolename,
String description)
Create and return a new
Role defined in this user database. |
User |
createUser(String username,
String password,
String fullName)
Create and return a new
User defined in this user database. |
Group |
findGroup(String groupname)
Return the
Group with the specified group name, if any; otherwise
return null . |
Role |
findRole(String rolename)
Return the
Role with the specified role name, if any; otherwise
return null . |
User |
findUser(String username)
Return the
User with the specified user name, if any; otherwise
return null . |
Iterator<Group> |
getGroups() |
String |
getId() |
String |
getPathname() |
boolean |
getReadonly() |
Iterator<Role> |
getRoles() |
Iterator<User> |
getUsers() |
boolean |
getWatchSource() |
boolean |
isWritable()
Check for permissions to save this user database to persistent storage
location.
|
boolean |
isWriteable()
Deprecated.
Use
isWritable() . This method will be removed in
Tomcat 10.1.x onwards. |
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(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
|
void |
setWatchSource(boolean watchSource) |
String |
toString()
Return a String representation of this UserDatabase.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
isAvailable, isSparse, modifiedGroup, modifiedRole, modifiedUser
protected final Map<String,Group> groups
Group
s defined in this database, keyed by group name.protected final String id
protected String pathname
catalina.base
) or absolute pathname to the
XML file in which we will save our persistent information.protected String pathnameOld
protected String pathnameNew
protected boolean readonly
protected final Map<String,Role> roles
Role
s defined in this database, keyed by role name.public MemoryUserDatabase()
public MemoryUserDatabase(String id)
id
- Unique global identifier of this user databasepublic Iterator<Group> getGroups()
getGroups
in interface UserDatabase
Group
s defined in this user database.public String getId()
getId
in interface UserDatabase
public String getPathname()
public void setPathname(String pathname)
pathname
- The new pathnamepublic boolean getReadonly()
public void setReadonly(boolean readonly)
readonly
- the new statuspublic boolean getWatchSource()
public void setWatchSource(boolean watchSource)
public Iterator<Role> getRoles()
getRoles
in interface UserDatabase
Role
s defined in this user database.public Iterator<User> getUsers()
getUsers
in interface UserDatabase
User
s defined in this user database.public void close() throws Exception
close
in interface UserDatabase
Exception
- if any exception is thrown during closingpublic Group createGroup(String groupname, String description)
Group
defined in this user database.createGroup
in interface UserDatabase
groupname
- The group name of the new group (must be unique)description
- The description of this grouppublic Role createRole(String rolename, String description)
Role
defined in this user database.createRole
in interface UserDatabase
rolename
- The role name of the new group (must be unique)description
- The description of this grouppublic User createUser(String username, String password, String fullName)
User
defined in this user database.createUser
in interface UserDatabase
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 userpublic Group findGroup(String groupname)
Group
with the specified group name, if any; otherwise
return null
.findGroup
in interface UserDatabase
groupname
- Name of the group to returnGroup
with the specified group name, if any;
otherwise return null
.public Role findRole(String rolename)
Role
with the specified role name, if any; otherwise
return null
.findRole
in interface UserDatabase
rolename
- Name of the role to returnRole
with the specified role name, if any; otherwise
return null
.public User findUser(String username)
User
with the specified user name, if any; otherwise
return null
.findUser
in interface UserDatabase
username
- Name of the user to returnUser
with the specified user name, if any; otherwise
return null
.public void open() throws Exception
open
in interface UserDatabase
Exception
- if any exception is thrown during openingpublic void removeGroup(Group group)
Group
from this user database.removeGroup
in interface UserDatabase
group
- The group to be removedpublic void removeRole(Role role)
Role
from this user database.removeRole
in interface UserDatabase
role
- The role to be removedpublic void removeUser(User user)
User
from this user database.removeUser
in interface UserDatabase
user
- The user to be removed@Deprecated public boolean isWriteable()
isWritable()
. This method will be removed in
Tomcat 10.1.x onwards.true
if the database is writablepublic boolean isWritable()
true
if the database is writablepublic void save() throws Exception
save
in interface UserDatabase
Exception
- if any exception is thrown during savingpublic void backgroundProcess()
UserDatabase
backgroundProcess
in interface UserDatabase
Copyright © 2000-2022 Apache Software Foundation. All Rights Reserved.