Top Description Fields Constructors Methods
org.apache.catalina.users

public Class MemoryUserDatabase

Additional top-level classes in compilation unit: MemoryGroupCreationFactory, MemoryRoleCreationFactory, MemoryUserCreationFactory.

extends Object
implements UserDatabase
Class Inheritance
All Implemented Interfaces
org.apache.catalina.UserDatabase
Imports
java.io.File, .FileNotFoundException, .FileOutputStream, .IOException, .OutputStreamWriter, .PrintWriter, java.net.URI, .URL, .URLConnection, java.nio.charset.StandardCharsets, java.util.ArrayList, .Iterator, .Map, java.util.concurrent.ConcurrentHashMap, java.util.concurrent.locks.Lock, .ReentrantReadWriteLock, org.apache.catalina.Globals, .Group, .Role, .User, .UserDatabase, org.apache.juli.logging.Log, .LogFactory, org.apache.tomcat.util.digester.AbstractObjectCreationFactory, .Digester, org.apache.tomcat.util.file.ConfigFileLoader, .ConfigurationSource, org.apache.tomcat.util.res.StringManager, org.apache.tomcat.util.security.Escape, org.xml.sax.Attributes

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.

Author
Craig R. McClanahan
Since
4.1

Field Summary

Modifier and TypeField and Description
private final ReentrantReadWriteLock
protected final Map<String, Group>
groups

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

protected final String
id

The unique global identifier of this user database.

private volatile long
private static final Log
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.

private final Lock
protected boolean
readonly

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

protected final Map<String, Role>
roles

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

private static final StringManager
protected final Map<String, User>
users

The set of Users defined in this database, keyed by user name.

private boolean
private final Lock

Constructor Summary

AccessConstructor and Description
public
MemoryUserDatabase()

Create a new instance with default values.

public
MemoryUserDatabase(String
Unique global identifier of this user database
id
)

Create a new instance with the specified values.

Method Summary

Modifier and TypeMethod and Description
public void
backgroundProcess()

Overrides default org.apache.catalina.UserDatabase.backgroundProcess.

Perform any background processing (e.g. checking for changes in persisted storage) required for the user database.

public void
close()

Implements org.apache.catalina.UserDatabase.close.

Finalize access to this user database.

public Group
createGroup(String
The group name of the new group (must be unique)
groupname
,
String
The description of this group
description
)

Implements org.apache.catalina.UserDatabase.createGroup.

Create and return a new Group defined in this user database.

public Role
createRole(String
The role name of the new group (must be unique)
rolename
,
String
The description of this group
description
)

Implements org.apache.catalina.UserDatabase.createRole.

Create and return a new Role defined in this user database.

public User
createUser(String
The logon username of the new user (must be unique)
username
,
String
The logon password of the new user
password
,
String
The full name of the new user
fullName
)

Implements org.apache.catalina.UserDatabase.createUser.

Create and return a new User defined in this user database.

public Group
findGroup(String
Name of the group to return
groupname
)

Implements org.apache.catalina.UserDatabase.findGroup.

Return the Group with the specified group name, if any; otherwise return null.

public Role
findRole(String
Name of the role to return
rolename
)

Implements org.apache.catalina.UserDatabase.findRole.

Return the Role with the specified role name, if any; otherwise return null.

public User
findUser(String
Name of the user to return
username
)

Implements org.apache.catalina.UserDatabase.findUser.

Return the User with the specified user name, if any; otherwise return null.

public Iterator<Group>

Returns:

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

Implements org.apache.catalina.UserDatabase.getGroups.

public String

Returns:

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

Implements org.apache.catalina.UserDatabase.getId.

public String

Returns:

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

public boolean

Returns:

the readonly status of the user database
getReadonly
()

public Iterator<Role>

Returns:

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

Implements org.apache.catalina.UserDatabase.getRoles.

public Iterator<User>

Returns:

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

Implements org.apache.catalina.UserDatabase.getUsers.

public boolean
public boolean

Returns:

true if the database is writable
isWritable
()

Check for permissions to save this user database to persistent storage location.

public void
open()

Implements org.apache.catalina.UserDatabase.open.

Initialize access to this user database.

public void
removeGroup(Group
The group to be removed
group
)

Implements org.apache.catalina.UserDatabase.removeGroup.

Remove the specified Group from this user database.

public void
removeRole(Role
The role to be removed
role
)

Implements org.apache.catalina.UserDatabase.removeRole.

Remove the specified Role from this user database.

public void
removeUser(User
The user to be removed
user
)

Implements org.apache.catalina.UserDatabase.removeUser.

Remove the specified User from this user database.

public void
save()

Implements org.apache.catalina.UserDatabase.save.

Save any updated information to the persistent storage location for this user database.

public void
setPathname(String
The new pathname
pathname
)

Set the relative or absolute pathname to the persistent storage file.

public void
setReadonly(boolean
the new status
readonly
)

Setting the readonly status of the user database

public void
setWatchSource(boolean watchSource)

public String
toString()

Overrides java.lang.Object.toString.

Return a String representation of this UserDatabase.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

dbLockback to summary
private final ReentrantReadWriteLock dbLock
groupsback to summary
protected final Map<String, Group> groups

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

idback to summary
protected final String id

The unique global identifier of this user database.

lastModifiedback to summary
private volatile long lastModified
logback to summary
private static final Log log
pathnameback to summary
protected String pathname

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

pathnameNewback to summary
protected String pathnameNew

The relative or absolute pathname of the file in which we write our new information prior to renaming.

pathnameOldback to summary
protected String pathnameOld

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

readLockback to summary
private final Lock readLock
readonlyback to summary
protected boolean readonly

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

rolesback to summary
protected final Map<String, Role> roles

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

smback to summary
private static final StringManager sm
usersback to summary
protected final Map<String, User> users

The set of Users defined in this database, keyed by user name.

watchSourceback to summary
private boolean watchSource
writeLockback to summary
private final Lock writeLock

Constructor Detail

MemoryUserDatabaseback to summary
public MemoryUserDatabase()

Create a new instance with default values.

MemoryUserDatabaseback to summary
public MemoryUserDatabase(String id)

Create a new instance with the specified values.

Parameters
id:String

Unique global identifier of this user database

Method Detail

backgroundProcessback to summary
public void backgroundProcess()

Overrides default org.apache.catalina.UserDatabase.backgroundProcess.

Doc from org.apache.catalina.UserDatabase.backgroundProcess.

Perform any background processing (e.g. checking for changes in persisted storage) required for the user database.

Annotations
@Override
closeback to summary
public void close() throws Exception

Implements org.apache.catalina.UserDatabase.close.

Finalize access to this user database.

Annotations
@Override
Exceptions
Exception:
if any exception is thrown during closing
createGroupback to summary
public Group createGroup(String groupname, String description)

Implements org.apache.catalina.UserDatabase.createGroup.

Create and return a new Group defined in this user database.

Parameters
groupname:String

The group name of the new group (must be unique)

description:String

The description of this group

Returns:Group

Doc from org.apache.catalina.UserDatabase.createGroup.

The new group

Annotations
@Override
createRoleback to summary
public Role createRole(String rolename, String description)

Implements org.apache.catalina.UserDatabase.createRole.

Create and return a new Role defined in this user database.

Parameters
rolename:String

The role name of the new group (must be unique)

description:String

The description of this group

Returns:Role

Doc from org.apache.catalina.UserDatabase.createRole.

The new role

Annotations
@Override
createUserback to summary
public User createUser(String username, String password, String fullName)

Implements org.apache.catalina.UserDatabase.createUser.

Create and return a new User defined in this user database.

Parameters
username:String

The logon username of the new user (must be unique)

password:String

The logon password of the new user

fullName:String

The full name of the new user

Returns:User

Doc from org.apache.catalina.UserDatabase.createUser.

The new user

Annotations
@Override
findGroupback to summary
public Group findGroup(String groupname)

Implements org.apache.catalina.UserDatabase.findGroup.

Return the Group with the specified group name, if any; otherwise return null.

Parameters
groupname:String

Name of the group to return

Returns:Group

Doc from org.apache.catalina.UserDatabase.findGroup.

the Group with the specified group name, if any; otherwise return null.

Annotations
@Override
findRoleback to summary
public Role findRole(String rolename)

Implements org.apache.catalina.UserDatabase.findRole.

Return the Role with the specified role name, if any; otherwise return null.

Parameters
rolename:String

Name of the role to return

Returns:Role

Doc from org.apache.catalina.UserDatabase.findRole.

the Role with the specified role name, if any; otherwise return null.

Annotations
@Override
findUserback to summary
public User findUser(String username)

Implements org.apache.catalina.UserDatabase.findUser.

Return the User with the specified user name, if any; otherwise return null.

Parameters
username:String

Name of the user to return

Returns:User

Doc from org.apache.catalina.UserDatabase.findUser.

the User with the specified user name, if any; otherwise return null.

Annotations
@Override
getGroupsback to summary
public Iterator<Group> getGroups()

Implements org.apache.catalina.UserDatabase.getGroups.

Returns:Iterator<Group>

the set of Groups defined in this user database.

Annotations
@Override
getIdback to summary
public String getId()

Implements org.apache.catalina.UserDatabase.getId.

Returns:String

the unique global identifier of this user database.

Annotations
@Override
getPathnameback to summary
public String getPathname()
Returns:String

the relative or absolute pathname to the persistent storage file.

getReadonlyback to summary
public boolean getReadonly()
Returns:boolean

the readonly status of the user database

getRolesback to summary
public Iterator<Role> getRoles()

Implements org.apache.catalina.UserDatabase.getRoles.

Returns:Iterator<Role>

the set of Roles defined in this user database.

Annotations
@Override
getUsersback to summary
public Iterator<User> getUsers()

Implements org.apache.catalina.UserDatabase.getUsers.

Returns:Iterator<User>

the set of Users defined in this user database.

Annotations
@Override
getWatchSourceback to summary
public boolean getWatchSource()
isWritableback to summary
public boolean isWritable()

Check for permissions to save this user database to persistent storage location.

Returns:boolean

true if the database is writable

openback to summary
public void open() throws Exception

Implements org.apache.catalina.UserDatabase.open.

Initialize access to this user database.

Annotations
@Override
Exceptions
Exception:
if any exception is thrown during opening
removeGroupback to summary
public void removeGroup(Group group)

Implements org.apache.catalina.UserDatabase.removeGroup.

Remove the specified Group from this user database.

Parameters
group:Group

The group to be removed

Annotations
@Override
removeRoleback to summary
public void removeRole(Role role)

Implements org.apache.catalina.UserDatabase.removeRole.

Remove the specified Role from this user database.

Parameters
role:Role

The role to be removed

Annotations
@Override
removeUserback to summary
public void removeUser(User user)

Implements org.apache.catalina.UserDatabase.removeUser.

Remove the specified User from this user database.

Parameters
user:User

The user to be removed

Annotations
@Override
saveback to summary
public void save() throws Exception

Implements org.apache.catalina.UserDatabase.save.

Save any updated information to the persistent storage location for this user database.

Annotations
@Override
Exceptions
Exception:
if any exception is thrown during saving
setPathnameback to summary
public void setPathname(String pathname)

Set the relative or absolute pathname to the persistent storage file.

Parameters
pathname:String

The new pathname

setReadonlyback to summary
public void setReadonly(boolean readonly)

Setting the readonly status of the user database

Parameters
readonly:boolean

the new status

setWatchSourceback to summary
public void setWatchSource(boolean watchSource)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Return a String representation of this UserDatabase.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object

Annotations
@Override