# Class SparseUserDatabaseMBean

java.lang.Object
org.apache.tomcat.util.modeler.BaseModelMBean
org.apache.catalina.mbeans.SparseUserDatabaseMBean

All Implemented Interfaces:
  `DynamicMBean`, `MBeanRegistration`, `ModelMBeanNotificationBroadcaster`, `NotificationBroadcaster`

Direct Known Subclasses:
  `MemoryUserDatabaseMBean`

public class SparseUserDatabaseMBean extends BaseModelMBean

A ModelMBean implementation for the `org.apache.catalina.users.SparseUserDatabase` component. The main difference is that the MBeans are created on demand (for example, the findUser method would register the corresponding user and make it available for management). All the MBeans created for users, groups and roles are then discarded when save is invoked.

Author:
  Craig R. McClanahan

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final ManagedBean`
  `managed`
  The `ManagedBean` information describing this MBean.
  `protected final ManagedBean`
  `managedGroup`
  The `ManagedBean` information describing Group MBeans.
  `protected final ManagedBean`
  `managedRole`
  The `ManagedBean` information describing Group MBeans.
  `protected final ManagedBean`
  `managedUser`
  The `ManagedBean` information describing User MBeans.
  `protected final MBeanServer`
  `mserver`
  The `MBeanServer` for this application.
  `protected final Registry`
  `registry`
  The configuration information registry for our managed beans.

  ### Fields inherited from class org.apache.tomcat.util.modeler.BaseModelMBean

  `attributeBroadcaster, generalBroadcaster, managedBean, oname, resource, resourceType`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SparseUserDatabaseMBean()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `String`
  `createGroup(String groupname, String description)`
  Create a new Group and return the corresponding MBean Name.
  `String`
  `createRole(String rolename, String description)`
  Create a new Role and return the corresponding MBean Name.
  `String`
  `createUser(String username, String password, String fullName)`
  Create a new User and return the corresponding MBean Name.
  `String`
  `findGroup(String groupname)`
  Return the MBean Name for the specified group name (if any); otherwise return `null`.
  `String`
  `findRole(String rolename)`
  Return the MBean Name for the specified role name (if any); otherwise return `null`.
  `String`
  `findUser(String username)`
  Return the MBean Name for the specified username (if any); otherwise return `null`.
  `String[]`
  `getGroups()`
  `String[]`
  `getRoles()`
  `String[]`
  `getUsers()`
  `void`
  `removeGroup(String groupname)`
  Remove an existing group and destroy the corresponding MBean.
  `void`
  `removeRole(String rolename)`
  Remove an existing role and destroy the corresponding MBean.
  `void`
  `removeUser(String username)`
  Remove an existing user and destroy the corresponding MBean.
  `void`
  `save()`
  Call actual save and unregister all obsolete beans.

  ### Methods inherited from class org.apache.tomcat.util.modeler.BaseModelMBean

  `addAttributeChangeNotificationListener, addNotificationListener, getAttribute, getAttributes, getClassName, getJmxName, getManagedResource, getMBeanInfo, getModelerType, getNotificationInfo, getObjectName, invoke, postDeregister, postRegister, preDeregister, preRegister, removeAttributeChangeNotificationListener, removeNotificationListener, sendAttributeChangeNotification, sendAttributeChangeNotification, sendNotification, sendNotification, setAttribute, setAttributes, setManagedBean, setManagedResource, toString`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### registry

    protected final Registry registry
    The configuration information registry for our managed beans.

  - ### mserver

    protected final MBeanServer mserver
    The `MBeanServer` for this application.

  - ### managed

    protected final ManagedBean managed
    The `ManagedBean` information describing this MBean.

  - ### managedGroup

    protected final ManagedBean managedGroup
    The `ManagedBean` information describing Group MBeans.

  - ### managedRole

    protected final ManagedBean managedRole
    The `ManagedBean` information describing Group MBeans.

  - ### managedUser

    protected final ManagedBean managedUser
    The `ManagedBean` information describing User MBeans.

- ## Constructor Details

  - ### SparseUserDatabaseMBean

    public SparseUserDatabaseMBean()

- ## Method Details

  - ### getGroups

    public String[] getGroups()
    Returns:
      the MBean Names of all groups defined in this database.

  - ### getRoles

    public String[] getRoles()
    Returns:
      the MBean Names of all roles defined in this database.

  - ### getUsers

    public String[] getUsers()
    Returns:
      the MBean Names of all users defined in this database.

  - ### createGroup

    public String createGroup(String groupname, String description)
    Create a new Group and return the corresponding MBean Name.
    Parameters:
      `groupname` - Group name of the new group
      `description` - Description of the new group
    Returns:
      the new group object name

  - ### createRole

    public String createRole(String rolename, String description)
    Create a new Role and return the corresponding MBean Name.
    Parameters:
      `rolename` - Group name of the new group
      `description` - Description of the new group
    Returns:
      the new role object name

  - ### createUser

    public String createUser(String username, String password, String fullName)
    Create a new User and return the corresponding MBean Name.
    Parameters:
      `username` - Username of the new user
      `password` - Password for the new user
      `fullName` - Full name for the new user
    Returns:
      the new user object name

  - ### findGroup

    public String findGroup(String groupname)
    Return the MBean Name for the specified group name (if any); otherwise return `null`.
    Parameters:
      `groupname` - Group name to look up
    Returns:
      the group object name

  - ### findRole

    public String findRole(String rolename)
    Return the MBean Name for the specified role name (if any); otherwise return `null`.
    Parameters:
      `rolename` - Role name to look up
    Returns:
      the role object name

  - ### findUser

    public String findUser(String username)
    Return the MBean Name for the specified username (if any); otherwise return `null`.
    Parameters:
      `username` - Username to look up
    Returns:
      the user object name

  - ### removeGroup

    public void removeGroup(String groupname)
    Remove an existing group and destroy the corresponding MBean.
    Parameters:
      `groupname` - Group name to remove

  - ### removeRole

    public void removeRole(String rolename)
    Remove an existing role and destroy the corresponding MBean.
    Parameters:
      `rolename` - Role name to remove

  - ### removeUser

    public void removeUser(String username)
    Remove an existing user and destroy the corresponding MBean.
    Parameters:
      `username` - Username to remove

  - ### save

    public void save()
    Call actual save and unregister all obsolete beans.