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

public Class DataSourceUserDatabase

extends SparseUserDatabase
Class Inheritance
Imports
java.sql.Connection, .PreparedStatement, .ResultSet, .SQLException, java.util.ArrayList, .HashMap, .Iterator, java.util.concurrent.ConcurrentHashMap, java.util.concurrent.locks.Lock, .ReentrantReadWriteLock, javax.sql.DataSource, org.apache.catalina.Group, .Role, .User, org.apache.juli.logging.Log, .LogFactory, org.apache.tomcat.util.res.StringManager

UserDatabase backed by a data source.

Field Summary

Modifier and TypeField and Description
private volatile boolean
connectionSuccess

Last connection attempt.

protected final ConcurrentHashMap<String, Group>
protected final ConcurrentHashMap<String, Role>
protected final ConcurrentHashMap<String, User>
protected final DataSource
dataSource

DataSource to use.

protected String
dataSourceName

The name of the JNDI JDBC DataSource

private final ReentrantReadWriteLock
private final Lock
private final Lock
protected String
groupNameCol

The column in the user group table that names a group

protected String
groupRoleTable

The table that holds the relation between groups and roles

private final ReentrantReadWriteLock
private final Lock
private final Lock
protected String
groupTable

The table that holds user data.

protected final String
id

The unique global identifier of this user database.

private static final Log
protected final ConcurrentHashMap<String, Group>
protected final ConcurrentHashMap<String, Role>
protected final ConcurrentHashMap<String, User>
private String
preparedAllGroups

The generated string for the all groups PreparedStatement

private String
preparedAllRoles

The generated string for the all roles PreparedStatement

private String
preparedAllUsers

The generated string for the all users PreparedStatement

private String
preparedGroup

The generated string for the group PreparedStatement

private String
preparedGroupRoles

The generated string for the groups PreparedStatement

private String
preparedRole

The generated string for the role PreparedStatement

private String
preparedUser

The generated string for the user PreparedStatement

private String
preparedUserGroups

The generated string for the groups PreparedStatement

private String
preparedUserRoles

The generated string for the roles PreparedStatement

protected boolean
readonly

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

protected final ConcurrentHashMap<String, Group>
protected final ConcurrentHashMap<String, Role>
protected final ConcurrentHashMap<String, User>
protected String
roleAndGroupDescriptionCol

The column in the role and group tables for the description

protected String
roleNameCol

The column in the user role table that names a role

private final ReentrantReadWriteLock
private final Lock
private final Lock
protected String
roleTable

The table that holds user data.

private static final StringManager
protected String
userCredCol

The column in the user table that holds the user's credentials

protected String
userFullNameCol

The column in the user table that holds the user's full name

protected String
userGroupTable

The table that holds the relation between users and groups

protected String
userNameCol

The column in the user table that holds the user's name

protected String
userRoleTable

The table that holds the relation between users and roles

private final ReentrantReadWriteLock
private final Lock
private final Lock
protected String
userTable

The table that holds user data.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements org.apache.catalina.UserDatabase.close.

Finalize access to this user database.

protected void
closeConnection(Connection
The connection to be closed
dbConnection
)

Close the specified database connection.

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 role (must be unique)
rolename
,
String
The description of this role
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.

public Group
findGroupInternal(Connection dbConnection, String groupName)

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

Implements org.apache.catalina.UserDatabase.findRole.

public Role
findRoleInternal(Connection dbConnection, String roleName)

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

Implements org.apache.catalina.UserDatabase.findUser.

public User
findUserInternal(Connection dbConnection, String userName)

public String

Returns:

the name of the JNDI JDBC DataSource.
getDataSourceName
()

public String

Returns:

the groupNameCol
getGroupNameCol
()

public String

Returns:

the groupRoleTable
getGroupRoleTable
()

public Iterator<Group>
public String

Returns:

the groupTable
getGroupTable
()

public String
public boolean

Returns:

the readonly
getReadonly
()

public String

Returns:

the roleAndGroupDescriptionCol
getRoleAndGroupDescriptionCol
()

public String

Returns:

the column in the user role table that names a role.
getRoleNameCol
()

public Iterator<Role>
public String

Returns:

the roleTable
getRoleTable
()

public String

Returns:

the column in the user table that holds the user's credentials.
getUserCredCol
()

public String

Returns:

the userFullNameCol
getUserFullNameCol
()

public String

Returns:

the userGroupTable
getUserGroupTable
()

public String

Returns:

the column in the user table that holds the user's name.
getUserNameCol
()

public String

Returns:

the table that holds the relation between user's and roles.
getUserRoleTable
()

public Iterator<User>
public String

Returns:

the table that holds user data..
getUserTable
()

public boolean
isAvailable()

Overrides default org.apache.catalina.UserDatabase.isAvailable.

Is the database available.

protected boolean

Returns:

true when groups are used
isGroupStoreDefined
()

Only use groups if the tables are fully defined.

protected boolean

Returns:

true when roles are used
isRoleStoreDefined
()

Only use roles if the tables are fully defined.

public void
modifiedGroup(Group
The group that has been modified
group
)

Overrides default org.apache.catalina.UserDatabase.modifiedGroup.

Signal the specified Group from this user database has been modified.

public void
modifiedRole(Role
The role that has been modified
role
)

Overrides default org.apache.catalina.UserDatabase.modifiedRole.

Signal the specified Role from this user database has been modified.

public void
modifiedUser(User
The user that has been modified
user
)

Overrides default org.apache.catalina.UserDatabase.modifiedUser.

Signal the specified User from this user database has been modified.

public void
open()

Implements org.apache.catalina.UserDatabase.open.

Initialize access to this user database.

protected Connection

Returns:

Connection to the database
openConnection
()

Open the specified database connection.

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.

protected void
saveInternal(Connection dbConnection)

public void
setDataSourceName(String
the name of the JNDI JDBC DataSource
dataSourceName
)

Set the name of the JNDI JDBC DataSource.

public void
setGroupNameCol(String
the groupNameCol to set
groupNameCol
)

public void
setGroupRoleTable(String
the groupRoleTable to set
groupRoleTable
)

public void
setGroupTable(String
the groupTable to set
groupTable
)

public void
setReadonly(boolean
the readonly to set
readonly
)

public void
setRoleAndGroupDescriptionCol(String
the roleAndGroupDescriptionCol to set
roleAndGroupDescriptionCol
)

public void
setRoleNameCol(String
The column name
roleNameCol
)

Set the column in the user role table that names a role.

public void
setRoleTable(String
the roleTable to set
roleTable
)

public void
setUserCredCol(String
The column name
userCredCol
)

Set the column in the user table that holds the user's credentials.

public void
setUserFullNameCol(String
the userFullNameCol to set
userFullNameCol
)

public void
setUserGroupTable(String
the userGroupTable to set
userGroupTable
)

public void
setUserNameCol(String
The column name
userNameCol
)

Set the column in the user table that holds the user's name.

public void
setUserRoleTable(String
The table name
userRoleTable
)

Set the table that holds the relation between user's and roles.

public void
setUserTable(String
The table name
userTable
)

Set the table that holds user data.

Inherited from org.apache.catalina.users.SparseUserDatabase:
isSparse

Field Detail

connectionSuccessback to summary
private volatile boolean connectionSuccess

Last connection attempt.

createdGroupsback to summary
protected final ConcurrentHashMap<String, Group> createdGroups
createdRolesback to summary
protected final ConcurrentHashMap<String, Role> createdRoles
createdUsersback to summary
protected final ConcurrentHashMap<String, User> createdUsers
dataSourceback to summary
protected final DataSource dataSource

DataSource to use.

dataSourceNameback to summary
protected String dataSourceName

The name of the JNDI JDBC DataSource

dbLockback to summary
private final ReentrantReadWriteLock dbLock
dbReadLockback to summary
private final Lock dbReadLock
dbWriteLockback to summary
private final Lock dbWriteLock
groupNameColback to summary
protected String groupNameCol

The column in the user group table that names a group

groupRoleTableback to summary
protected String groupRoleTable

The table that holds the relation between groups and roles

groupsLockback to summary
private final ReentrantReadWriteLock groupsLock
groupsReadLockback to summary
private final Lock groupsReadLock
groupsWriteLockback to summary
private final Lock groupsWriteLock
groupTableback to summary
protected String groupTable

The table that holds user data.

idback to summary
protected final String id

The unique global identifier of this user database.

logback to summary
private static final Log log
modifiedGroupsback to summary
protected final ConcurrentHashMap<String, Group> modifiedGroups
modifiedRolesback to summary
protected final ConcurrentHashMap<String, Role> modifiedRoles
modifiedUsersback to summary
protected final ConcurrentHashMap<String, User> modifiedUsers
preparedAllGroupsback to summary
private String preparedAllGroups

The generated string for the all groups PreparedStatement

preparedAllRolesback to summary
private String preparedAllRoles

The generated string for the all roles PreparedStatement

preparedAllUsersback to summary
private String preparedAllUsers

The generated string for the all users PreparedStatement

preparedGroupback to summary
private String preparedGroup

The generated string for the group PreparedStatement

preparedGroupRolesback to summary
private String preparedGroupRoles

The generated string for the groups PreparedStatement

preparedRoleback to summary
private String preparedRole

The generated string for the role PreparedStatement

preparedUserback to summary
private String preparedUser

The generated string for the user PreparedStatement

preparedUserGroupsback to summary
private String preparedUserGroups

The generated string for the groups PreparedStatement

preparedUserRolesback to summary
private String preparedUserRoles

The generated string for the roles PreparedStatement

readonlyback to summary
protected boolean readonly

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

removedGroupsback to summary
protected final ConcurrentHashMap<String, Group> removedGroups
removedRolesback to summary
protected final ConcurrentHashMap<String, Role> removedRoles
removedUsersback to summary
protected final ConcurrentHashMap<String, User> removedUsers
roleAndGroupDescriptionColback to summary
protected String roleAndGroupDescriptionCol

The column in the role and group tables for the description

roleNameColback to summary
protected String roleNameCol

The column in the user role table that names a role

rolesLockback to summary
private final ReentrantReadWriteLock rolesLock
rolesReadLockback to summary
private final Lock rolesReadLock
rolesWriteLockback to summary
private final Lock rolesWriteLock
roleTableback to summary
protected String roleTable

The table that holds user data.

smback to summary
private static final StringManager sm
userCredColback to summary
protected String userCredCol

The column in the user table that holds the user's credentials

userFullNameColback to summary
protected String userFullNameCol

The column in the user table that holds the user's full name

userGroupTableback to summary
protected String userGroupTable

The table that holds the relation between users and groups

userNameColback to summary
protected String userNameCol

The column in the user table that holds the user's name

userRoleTableback to summary
protected String userRoleTable

The table that holds the relation between users and roles

usersLockback to summary
private final ReentrantReadWriteLock usersLock
usersReadLockback to summary
private final Lock usersReadLock
usersWriteLockback to summary
private final Lock usersWriteLock
userTableback to summary
protected String userTable

The table that holds user data.

Constructor Detail

DataSourceUserDatabaseback to summary
public DataSourceUserDatabase(DataSource dataSource, String id)

Method Detail

closeback to summary
public void close() throws Exception

Implements org.apache.catalina.UserDatabase.close.

Doc from org.apache.catalina.UserDatabase.close.

Finalize access to this user database.

Annotations
@Override
Exceptions
Exception:
if any exception is thrown during closing
closeConnectionback to summary
protected void closeConnection(Connection dbConnection)

Close the specified database connection.

Parameters
dbConnection:Connection

The connection to be closed

createGroupback to summary
public Group createGroup(String groupname, String description)

Implements org.apache.catalina.UserDatabase.createGroup.

Doc from 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

The new group

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

Implements org.apache.catalina.UserDatabase.createRole.

Doc from 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 role (must be unique)

description:String

The description of this role

Returns:Role

The new role

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

Implements org.apache.catalina.UserDatabase.createUser.

Doc from 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

The new user

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

Implements org.apache.catalina.UserDatabase.findGroup.

Parameters
groupname:String

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

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
findGroupInternalback to summary
public Group findGroupInternal(Connection dbConnection, String groupName)
findRoleback to summary
public Role findRole(String rolename)

Implements org.apache.catalina.UserDatabase.findRole.

Parameters
rolename:String

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

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
findRoleInternalback to summary
public Role findRoleInternal(Connection dbConnection, String roleName)
findUserback to summary
public User findUser(String username)

Implements org.apache.catalina.UserDatabase.findUser.

Parameters
username:String

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

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
findUserInternalback to summary
public User findUserInternal(Connection dbConnection, String userName)
getDataSourceNameback to summary
public String getDataSourceName()
Returns:String

the name of the JNDI JDBC DataSource.

getGroupNameColback to summary
public String getGroupNameCol()
Returns:String

the groupNameCol

getGroupRoleTableback to summary
public String getGroupRoleTable()
Returns:String

the groupRoleTable

getGroupsback to summary
public Iterator<Group> getGroups()

Implements org.apache.catalina.UserDatabase.getGroups.

Returns:Iterator<Group>

Doc from org.apache.catalina.UserDatabase.getGroups.

the set of Groups defined in this user database.

Annotations
@Override
getGroupTableback to summary
public String getGroupTable()
Returns:String

the groupTable

getIdback to summary
public String getId()

Implements org.apache.catalina.UserDatabase.getId.

Returns:String

Doc from org.apache.catalina.UserDatabase.getId.

the unique global identifier of this user database.

Annotations
@Override
getReadonlyback to summary
public boolean getReadonly()
Returns:boolean

the readonly

getRoleAndGroupDescriptionColback to summary
public String getRoleAndGroupDescriptionCol()
Returns:String

the roleAndGroupDescriptionCol

getRoleNameColback to summary
public String getRoleNameCol()
Returns:String

the column in the user role table that names a role.

getRolesback to summary
public Iterator<Role> getRoles()

Implements org.apache.catalina.UserDatabase.getRoles.

Returns:Iterator<Role>

Doc from org.apache.catalina.UserDatabase.getRoles.

the set of Roles defined in this user database.

Annotations
@Override
getRoleTableback to summary
public String getRoleTable()
Returns:String

the roleTable

getUserCredColback to summary
public String getUserCredCol()
Returns:String

the column in the user table that holds the user's credentials.

getUserFullNameColback to summary
public String getUserFullNameCol()
Returns:String

the userFullNameCol

getUserGroupTableback to summary
public String getUserGroupTable()
Returns:String

the userGroupTable

getUserNameColback to summary
public String getUserNameCol()
Returns:String

the column in the user table that holds the user's name.

getUserRoleTableback to summary
public String getUserRoleTable()
Returns:String

the table that holds the relation between user's and roles.

getUsersback to summary
public Iterator<User> getUsers()

Implements org.apache.catalina.UserDatabase.getUsers.

Returns:Iterator<User>

Doc from org.apache.catalina.UserDatabase.getUsers.

the set of Users defined in this user database.

Annotations
@Override
getUserTableback to summary
public String getUserTable()
Returns:String

the table that holds user data..

isAvailableback to summary
public boolean isAvailable()

Overrides default org.apache.catalina.UserDatabase.isAvailable.

Doc from org.apache.catalina.UserDatabase.isAvailable.

Is the database available.

Returns:boolean

true

Annotations
@Override
isGroupStoreDefinedback to summary
protected boolean isGroupStoreDefined()

Only use groups if the tables are fully defined.

Returns:boolean

true when groups are used

isRoleStoreDefinedback to summary
protected boolean isRoleStoreDefined()

Only use roles if the tables are fully defined.

Returns:boolean

true when roles are used

modifiedGroupback to summary
public void modifiedGroup(Group group)

Overrides default org.apache.catalina.UserDatabase.modifiedGroup.

Doc from org.apache.catalina.UserDatabase.modifiedGroup.

Signal the specified Group from this user database has been modified.

Parameters
group:Group

The group that has been modified

Annotations
@Override
modifiedRoleback to summary
public void modifiedRole(Role role)

Overrides default org.apache.catalina.UserDatabase.modifiedRole.

Doc from org.apache.catalina.UserDatabase.modifiedRole.

Signal the specified Role from this user database has been modified.

Parameters
role:Role

The role that has been modified

Annotations
@Override
modifiedUserback to summary
public void modifiedUser(User user)

Overrides default org.apache.catalina.UserDatabase.modifiedUser.

Doc from org.apache.catalina.UserDatabase.modifiedUser.

Signal the specified User from this user database has been modified.

Parameters
user:User

The user that has been modified

Annotations
@Override
openback to summary
public void open() throws Exception

Implements org.apache.catalina.UserDatabase.open.

Doc from org.apache.catalina.UserDatabase.open.

Initialize access to this user database.

Annotations
@Override
Exceptions
Exception:
if any exception is thrown during opening
openConnectionback to summary
protected Connection openConnection()

Open the specified database connection.

Returns:Connection

Connection to the database

removeGroupback to summary
public void removeGroup(Group group)

Implements org.apache.catalina.UserDatabase.removeGroup.

Doc from 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.

Doc from 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.

Doc from 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.

Doc from 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
saveInternalback to summary
protected void saveInternal(Connection dbConnection)
setDataSourceNameback to summary
public void setDataSourceName(String dataSourceName)

Set the name of the JNDI JDBC DataSource.

Parameters
dataSourceName:String

the name of the JNDI JDBC DataSource

setGroupNameColback to summary
public void setGroupNameCol(String groupNameCol)
Parameters
groupNameCol:String

the groupNameCol to set

setGroupRoleTableback to summary
public void setGroupRoleTable(String groupRoleTable)
Parameters
groupRoleTable:String

the groupRoleTable to set

setGroupTableback to summary
public void setGroupTable(String groupTable)
Parameters
groupTable:String

the groupTable to set

setReadonlyback to summary
public void setReadonly(boolean readonly)
Parameters
readonly:boolean

the readonly to set

setRoleAndGroupDescriptionColback to summary
public void setRoleAndGroupDescriptionCol(String roleAndGroupDescriptionCol)
Parameters
roleAndGroupDescriptionCol:String

the roleAndGroupDescriptionCol to set

setRoleNameColback to summary
public void setRoleNameCol(String roleNameCol)

Set the column in the user role table that names a role.

Parameters
roleNameCol:String

The column name

setRoleTableback to summary
public void setRoleTable(String roleTable)
Parameters
roleTable:String

the roleTable to set

setUserCredColback to summary
public void setUserCredCol(String userCredCol)

Set the column in the user table that holds the user's credentials.

Parameters
userCredCol:String

The column name

setUserFullNameColback to summary
public void setUserFullNameCol(String userFullNameCol)
Parameters
userFullNameCol:String

the userFullNameCol to set

setUserGroupTableback to summary
public void setUserGroupTable(String userGroupTable)
Parameters
userGroupTable:String

the userGroupTable to set

setUserNameColback to summary
public void setUserNameCol(String userNameCol)

Set the column in the user table that holds the user's name.

Parameters
userNameCol:String

The column name

setUserRoleTableback to summary
public void setUserRoleTable(String userRoleTable)

Set the table that holds the relation between user's and roles.

Parameters
userRoleTable:String

The table name

setUserTableback to summary
public void setUserTable(String userTable)

Set the table that holds user data.

Parameters
userTable:String

The table name