Class DataSourceUserDatabase

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.concurrent.ConcurrentHashMap<java.lang.String,​Group> createdGroups
      Groups that have been created but not yet persisted.
      protected java.util.concurrent.ConcurrentHashMap<java.lang.String,​Role> createdRoles
      Roles that have been created but not yet persisted.
      protected java.util.concurrent.ConcurrentHashMap<java.lang.String,​User> createdUsers
      Users that have been created but not yet persisted.
      protected javax.sql.DataSource dataSource
      DataSource to use.
      protected java.lang.String dataSourceName
      The name of the JNDI JDBC DataSource
      protected java.lang.String groupNameCol
      The column in the user group table that names a group
      protected java.lang.String groupRoleTable
      The table that holds the relation between groups and roles
      protected java.lang.String groupTable
      The table that holds user data.
      protected java.lang.String id
      The unique global identifier of this user database.
      protected java.util.concurrent.ConcurrentHashMap<java.lang.String,​Group> modifiedGroups
      Groups that have been modified but not yet persisted.
      protected java.util.concurrent.ConcurrentHashMap<java.lang.String,​Role> modifiedRoles
      Roles that have been modified but not yet persisted.
      protected java.util.concurrent.ConcurrentHashMap<java.lang.String,​User> modifiedUsers
      Users that have been modified but not yet persisted.
      protected boolean readonly
      A flag, indicating if the user database is read only.
      protected java.util.concurrent.ConcurrentHashMap<java.lang.String,​Group> removedGroups
      Groups that have been removed but not yet persisted.
      protected java.util.concurrent.ConcurrentHashMap<java.lang.String,​Role> removedRoles
      Roles that have been removed but not yet persisted.
      protected java.util.concurrent.ConcurrentHashMap<java.lang.String,​User> removedUsers
      Users that have been removed but not yet persisted.
      protected java.lang.String roleAndGroupDescriptionCol
      The column in the role and group tables for the description
      protected java.lang.String roleNameCol
      The column in the user role table that names a role
      protected java.lang.String roleTable
      The table that holds user data.
      protected java.lang.String userCredCol
      The column in the user table that holds the user's credentials
      protected java.lang.String userFullNameCol
      The column in the user table that holds the user's full name
      protected java.lang.String userGroupTable
      The table that holds the relation between users and groups
      protected java.lang.String userNameCol
      The column in the user table that holds the user's name
      protected java.lang.String userRoleTable
      The table that holds the relation between users and roles
      protected java.lang.String userTable
      The table that holds user data.
    • Constructor Summary

      Constructors 
      Constructor Description
      DataSourceUserDatabase​(javax.sql.DataSource dataSource, java.lang.String id)
      Create a new DataSourceUserDatabase.
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void close()
      Finalize access to this user database.
      protected void closeConnection​(java.sql.Connection dbConnection)
      Close the specified database connection.
      Group createGroup​(java.lang.String groupname, java.lang.String description)
      Create and return a new Group defined in this user database.
      Role createRole​(java.lang.String rolename, java.lang.String description)
      Create and return a new Role defined in this user database.
      User createUser​(java.lang.String username, java.lang.String password, java.lang.String fullName)
      Create and return a new User defined in this user database.
      Group findGroup​(java.lang.String groupname)
      Find the Group with the specified group name.
      Group findGroupInternal​(java.sql.Connection dbConnection, java.lang.String groupName)
      Find a group by name using the provided database connection.
      Role findRole​(java.lang.String rolename)
      Find the Role with the specified role name.
      Role findRoleInternal​(java.sql.Connection dbConnection, java.lang.String roleName)
      Find a role by name using the provided database connection.
      User findUser​(java.lang.String username)
      Find the User with the specified username.
      User findUserInternal​(java.sql.Connection dbConnection, java.lang.String userName)
      Deprecated.
      Will be made private in Tomcat 12
      java.lang.String getDataSourceName()
      Return the name of the JNDI JDBC DataSource.
      java.lang.String getGroupNameCol()
      Return the column name used for group names.
      java.lang.String getGroupRoleTable()
      Return the table that holds the relation between groups and roles.
      java.util.Iterator<Group> getGroups()
      Get the set of Groups defined in this user database.
      java.lang.String getGroupTable()
      Return the table that holds group data.
      java.lang.String getId()
      Get the unique global identifier of this user database.
      boolean getReadonly()
      Return whether the user database is read only.
      java.lang.String getRoleAndGroupDescriptionCol()
      Return the column name used for role and group descriptions.
      java.lang.String getRoleNameCol()
      Return the column in the user role table that names a role.
      java.util.Iterator<Role> getRoles()
      Get the set of Roles defined in this user database.
      java.lang.String getRoleTable()
      Return the table that holds role data.
      java.lang.String getUserCredCol()
      Return the column in the user table that holds the user's credentials.
      java.lang.String getUserFullNameCol()
      Return the column name used for user full names.
      java.lang.String getUserGroupTable()
      Return the table that holds the relation between users and groups.
      java.lang.String getUserNameCol()
      Return the column in the user table that holds the user's name.
      java.lang.String getUserRoleTable()
      Return the table that holds the relation between user's and roles.
      java.util.Iterator<User> getUsers()
      Get the set of Users defined in this user database.
      java.lang.String getUserTable()
      Return the table that holds user data.
      boolean isAvailable()
      Is the database available.
      protected boolean isGroupStoreDefined()
      Only use groups if the tables are fully defined.
      protected boolean isRoleStoreDefined()
      Only use roles if the tables are fully defined.
      void modifiedGroup​(Group group)
      Signal the specified Group from this user database has been modified.
      void modifiedRole​(Role role)
      Signal the specified Role from this user database has been modified.
      void modifiedUser​(User user)
      Signal the specified User from this user database has been modified.
      void open()
      Initialize access to this user database.
      protected java.sql.Connection openConnection()
      Open the specified database connection.
      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.
      protected void saveInternal​(java.sql.Connection dbConnection)
      Save all pending changes to the database using the provided connection.
      void setDataSourceName​(java.lang.String dataSourceName)
      Set the name of the JNDI JDBC DataSource.
      void setGroupNameCol​(java.lang.String groupNameCol)
      Set the column name used for group names.
      void setGroupRoleTable​(java.lang.String groupRoleTable)
      Set the table that holds the relation between groups and roles.
      void setGroupTable​(java.lang.String groupTable)
      Set the table that holds group data.
      void setReadonly​(boolean readonly)
      Set whether the user database is read only.
      void setRoleAndGroupDescriptionCol​(java.lang.String roleAndGroupDescriptionCol)
      Set the column name used for role and group descriptions.
      void setRoleNameCol​(java.lang.String roleNameCol)
      Set the column in the user role table that names a role.
      void setRoleTable​(java.lang.String roleTable)
      Set the table that holds role data.
      void setUserCredCol​(java.lang.String userCredCol)
      Set the column in the user table that holds the user's credentials.
      void setUserFullNameCol​(java.lang.String userFullNameCol)
      Set the column name used for user full names.
      void setUserGroupTable​(java.lang.String userGroupTable)
      Set the table that holds the relation between users and groups.
      void setUserNameCol​(java.lang.String userNameCol)
      Set the column in the user table that holds the user's name.
      void setUserRoleTable​(java.lang.String userRoleTable)
      Set the table that holds the relation between user's and roles.
      void setUserTable​(java.lang.String userTable)
      Set the table that holds user data.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • dataSource

        protected final javax.sql.DataSource dataSource
        DataSource to use.
      • id

        protected final java.lang.String id
        The unique global identifier of this user database.
      • createdUsers

        protected final java.util.concurrent.ConcurrentHashMap<java.lang.String,​User> createdUsers
        Users that have been created but not yet persisted.
      • modifiedUsers

        protected final java.util.concurrent.ConcurrentHashMap<java.lang.String,​User> modifiedUsers
        Users that have been modified but not yet persisted.
      • removedUsers

        protected final java.util.concurrent.ConcurrentHashMap<java.lang.String,​User> removedUsers
        Users that have been removed but not yet persisted.
      • createdGroups

        protected final java.util.concurrent.ConcurrentHashMap<java.lang.String,​Group> createdGroups
        Groups that have been created but not yet persisted.
      • modifiedGroups

        protected final java.util.concurrent.ConcurrentHashMap<java.lang.String,​Group> modifiedGroups
        Groups that have been modified but not yet persisted.
      • removedGroups

        protected final java.util.concurrent.ConcurrentHashMap<java.lang.String,​Group> removedGroups
        Groups that have been removed but not yet persisted.
      • createdRoles

        protected final java.util.concurrent.ConcurrentHashMap<java.lang.String,​Role> createdRoles
        Roles that have been created but not yet persisted.
      • modifiedRoles

        protected final java.util.concurrent.ConcurrentHashMap<java.lang.String,​Role> modifiedRoles
        Roles that have been modified but not yet persisted.
      • removedRoles

        protected final java.util.concurrent.ConcurrentHashMap<java.lang.String,​Role> removedRoles
        Roles that have been removed but not yet persisted.
      • dataSourceName

        protected java.lang.String dataSourceName
        The name of the JNDI JDBC DataSource
      • roleNameCol

        protected java.lang.String roleNameCol
        The column in the user role table that names a role
      • roleAndGroupDescriptionCol

        protected java.lang.String roleAndGroupDescriptionCol
        The column in the role and group tables for the description
      • groupNameCol

        protected java.lang.String groupNameCol
        The column in the user group table that names a group
      • userCredCol

        protected java.lang.String userCredCol
        The column in the user table that holds the user's credentials
      • userFullNameCol

        protected java.lang.String userFullNameCol
        The column in the user table that holds the user's full name
      • userNameCol

        protected java.lang.String userNameCol
        The column in the user table that holds the user's name
      • userRoleTable

        protected java.lang.String userRoleTable
        The table that holds the relation between users and roles
      • userGroupTable

        protected java.lang.String userGroupTable
        The table that holds the relation between users and groups
      • groupRoleTable

        protected java.lang.String groupRoleTable
        The table that holds the relation between groups and roles
      • userTable

        protected java.lang.String userTable
        The table that holds user data.
      • groupTable

        protected java.lang.String groupTable
        The table that holds user data.
      • roleTable

        protected java.lang.String roleTable
        The table that holds user data.
      • readonly

        protected boolean readonly
        A flag, indicating if the user database is read only.
    • Constructor Detail

      • DataSourceUserDatabase

        public DataSourceUserDatabase​(javax.sql.DataSource dataSource,
                                      java.lang.String id)
        Create a new DataSourceUserDatabase.
        Parameters:
        dataSource - The data source to use
        id - The unique identifier for this user database
    • Method Detail

      • getDataSourceName

        public java.lang.String getDataSourceName()
        Return the name of the JNDI JDBC DataSource.
        Returns:
        the DataSource name
      • setDataSourceName

        public void setDataSourceName​(java.lang.String dataSourceName)
        Set the name of the JNDI JDBC DataSource.
        Parameters:
        dataSourceName - the name of the JNDI JDBC DataSource to use
      • getRoleNameCol

        public java.lang.String getRoleNameCol()
        Return the column in the user role table that names a role.
        Returns:
        the role name column
      • setRoleNameCol

        public void setRoleNameCol​(java.lang.String roleNameCol)
        Set the column in the user role table that names a role.
        Parameters:
        roleNameCol - The column name to use
      • getUserCredCol

        public java.lang.String getUserCredCol()
        Return the column in the user table that holds the user's credentials.
        Returns:
        the credentials column
      • setUserCredCol

        public void setUserCredCol​(java.lang.String userCredCol)
        Set the column in the user table that holds the user's credentials.
        Parameters:
        userCredCol - The column name to use
      • getUserNameCol

        public java.lang.String getUserNameCol()
        Return the column in the user table that holds the user's name.
        Returns:
        the user name column
      • setUserNameCol

        public void setUserNameCol​(java.lang.String userNameCol)
        Set the column in the user table that holds the user's name.
        Parameters:
        userNameCol - The column name to use
      • getUserRoleTable

        public java.lang.String getUserRoleTable()
        Return the table that holds the relation between user's and roles.
        Returns:
        the user-role table name
      • setUserRoleTable

        public void setUserRoleTable​(java.lang.String userRoleTable)
        Set the table that holds the relation between user's and roles.
        Parameters:
        userRoleTable - The table name to use
      • getUserTable

        public java.lang.String getUserTable()
        Return the table that holds user data.
        Returns:
        the user table name
      • setUserTable

        public void setUserTable​(java.lang.String userTable)
        Set the table that holds user data.
        Parameters:
        userTable - The table name to use
      • getRoleAndGroupDescriptionCol

        public java.lang.String getRoleAndGroupDescriptionCol()
        Return the column name used for role and group descriptions.
        Returns:
        the role and group description column name
      • setRoleAndGroupDescriptionCol

        public void setRoleAndGroupDescriptionCol​(java.lang.String roleAndGroupDescriptionCol)
        Set the column name used for role and group descriptions.
        Parameters:
        roleAndGroupDescriptionCol - the column name to use
      • getGroupNameCol

        public java.lang.String getGroupNameCol()
        Return the column name used for group names.
        Returns:
        the group name column
      • setGroupNameCol

        public void setGroupNameCol​(java.lang.String groupNameCol)
        Set the column name used for group names.
        Parameters:
        groupNameCol - the column name to use
      • getUserFullNameCol

        public java.lang.String getUserFullNameCol()
        Return the column name used for user full names.
        Returns:
        the user full name column
      • setUserFullNameCol

        public void setUserFullNameCol​(java.lang.String userFullNameCol)
        Set the column name used for user full names.
        Parameters:
        userFullNameCol - the column name to use
      • getUserGroupTable

        public java.lang.String getUserGroupTable()
        Return the table that holds the relation between users and groups.
        Returns:
        the user-group table name
      • setUserGroupTable

        public void setUserGroupTable​(java.lang.String userGroupTable)
        Set the table that holds the relation between users and groups.
        Parameters:
        userGroupTable - the table name to use
      • getGroupRoleTable

        public java.lang.String getGroupRoleTable()
        Return the table that holds the relation between groups and roles.
        Returns:
        the group-role table name
      • setGroupRoleTable

        public void setGroupRoleTable​(java.lang.String groupRoleTable)
        Set the table that holds the relation between groups and roles.
        Parameters:
        groupRoleTable - the table name to use
      • getGroupTable

        public java.lang.String getGroupTable()
        Return the table that holds group data.
        Returns:
        the group table name
      • setGroupTable

        public void setGroupTable​(java.lang.String groupTable)
        Set the table that holds group data.
        Parameters:
        groupTable - the table name to use
      • getRoleTable

        public java.lang.String getRoleTable()
        Return the table that holds role data.
        Returns:
        the role table name
      • setRoleTable

        public void setRoleTable​(java.lang.String roleTable)
        Set the table that holds role data.
        Parameters:
        roleTable - the table name to use
      • getReadonly

        public boolean getReadonly()
        Return whether the user database is read only.
        Returns:
        true if the database is read only
      • setReadonly

        public void setReadonly​(boolean readonly)
        Set whether the user database is read only.
        Parameters:
        readonly - true to make the database read only
      • getId

        public java.lang.String getId()
        Description copied from interface: UserDatabase
        Get the unique global identifier of this user database.
        Returns:
        the unique global identifier of this user database.
      • getGroups

        public java.util.Iterator<Group> getGroups()
        Description copied from interface: UserDatabase
        Get the set of Groups defined in this user database.
        Returns:
        the set of Groups defined in this user database.
      • getRoles

        public java.util.Iterator<Role> getRoles()
        Description copied from interface: UserDatabase
        Get the set of Roles defined in this user database.
        Returns:
        the set of Roles defined in this user database.
      • getUsers

        public java.util.Iterator<User> getUsers()
        Description copied from interface: UserDatabase
        Get the set of Users defined in this user database.
        Returns:
        the set of Users defined in this user database.
      • close

        public void close()
                   throws java.lang.Exception
        Description copied from interface: UserDatabase
        Finalize access to this user database.
        Throws:
        java.lang.Exception - if any exception is thrown during closing
      • createGroup

        public Group createGroup​(java.lang.String groupname,
                                 java.lang.String description)
        Description copied from interface: UserDatabase
        Create and return a new Group defined in this user database.
        Parameters:
        groupname - The group name of the new group (must be unique)
        description - The description of this group
        Returns:
        The new group, or null if there's a pre-existing group
      • createRole

        public Role createRole​(java.lang.String rolename,
                               java.lang.String description)
        Description copied from interface: UserDatabase
        Create and return a new Role defined in this user database.
        Parameters:
        rolename - The role name of the new role (must be unique)
        description - The description of this role
        Returns:
        The new role, or null if there's a pre-existing role
      • createUser

        public User createUser​(java.lang.String username,
                               java.lang.String password,
                               java.lang.String fullName)
        Description copied from interface: UserDatabase
        Create and return a new User defined in this user database.
        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, or null if there's a pre-existing user
      • findGroup

        public Group findGroup​(java.lang.String groupname)
        Description copied from interface: UserDatabase
        Find the Group with the specified group name.
        Parameters:
        groupname - Name of the group to return
        Returns:
        the Group with the specified group name, if any; otherwise return null.
      • findGroupInternal

        public Group findGroupInternal​(java.sql.Connection dbConnection,
                                       java.lang.String groupName)
        Find a group by name using the provided database connection.
        Parameters:
        dbConnection - The database connection to use
        groupName - The name of the group to find
        Returns:
        the group, or null if not found
      • findRole

        public Role findRole​(java.lang.String rolename)
        Description copied from interface: UserDatabase
        Find the Role with the specified role name.
        Parameters:
        rolename - Name of the role to return
        Returns:
        the Role with the specified role name, if any; otherwise return null.
      • findRoleInternal

        public Role findRoleInternal​(java.sql.Connection dbConnection,
                                     java.lang.String roleName)
        Find a role by name using the provided database connection.
        Parameters:
        dbConnection - The database connection to use
        roleName - The name of the role to find
        Returns:
        the role, or null if not found
      • findUser

        public User findUser​(java.lang.String username)
        Description copied from interface: UserDatabase
        Find the User with the specified username.
        Parameters:
        username - Name of the user to return
        Returns:
        the User with the specified username, if any; otherwise return null.
      • findUserInternal

        @Deprecated
        public User findUserInternal​(java.sql.Connection dbConnection,
                                     java.lang.String userName)
        Deprecated.
        Will be made private in Tomcat 12
        Find a user by name using the provided database connection.
        Parameters:
        dbConnection - The database connection to use
        userName - The name of the user to find
        Returns:
        the user, or null if not found
      • modifiedGroup

        public void modifiedGroup​(Group group)
        Description copied from interface: UserDatabase
        Signal the specified Group from this user database has been modified.
        Parameters:
        group - The group that has been modified
      • modifiedRole

        public void modifiedRole​(Role role)
        Description copied from interface: UserDatabase
        Signal the specified Role from this user database has been modified.
        Parameters:
        role - The role that has been modified
      • modifiedUser

        public void modifiedUser​(User user)
        Description copied from interface: UserDatabase
        Signal the specified User from this user database has been modified.
        Parameters:
        user - The user that has been modified
      • open

        public void open()
                  throws java.lang.Exception
        Description copied from interface: UserDatabase
        Initialize access to this user database.
        Throws:
        java.lang.Exception - if any exception is thrown during opening
      • removeGroup

        public void removeGroup​(Group group)
        Description copied from interface: UserDatabase
        Remove the specified Group from this user database.
        Parameters:
        group - The group to be removed
      • removeRole

        public void removeRole​(Role role)
        Description copied from interface: UserDatabase
        Remove the specified Role from this user database.
        Parameters:
        role - The role to be removed
      • removeUser

        public void removeUser​(User user)
        Description copied from interface: UserDatabase
        Remove the specified User from this user database.
        Parameters:
        user - The user to be removed
      • save

        public void save()
                  throws java.lang.Exception
        Description copied from interface: UserDatabase
        Save any updated information to the persistent storage location for this user database.
        Throws:
        java.lang.Exception - if any exception is thrown during saving
      • saveInternal

        protected void saveInternal​(java.sql.Connection dbConnection)
        Save all pending changes to the database using the provided connection.
        Parameters:
        dbConnection - The database connection to use
      • isAvailable

        public boolean isAvailable()
        Description copied from interface: UserDatabase
        Is the database available.
        Returns:
        true
      • isGroupStoreDefined

        protected boolean isGroupStoreDefined()
        Only use groups if the tables are fully defined.
        Returns:
        true when groups are used
      • isRoleStoreDefined

        protected boolean isRoleStoreDefined()
        Only use roles if the tables are fully defined.
        Returns:
        true when roles are used
      • openConnection

        protected java.sql.Connection openConnection()
        Open the specified database connection.
        Returns:
        Connection to the database
      • closeConnection

        protected void closeConnection​(java.sql.Connection dbConnection)
        Close the specified database connection.
        Parameters:
        dbConnection - The connection to be closed