FileDocCategorySizeDatePackage
MemoryUserDatabaseMBean.javaAPI DocApache Tomcat 6.0.1412232Fri Jul 20 04:20:34 BST 2007org.apache.catalina.mbeans

MemoryUserDatabaseMBean

public class MemoryUserDatabaseMBean extends org.apache.tomcat.util.modeler.BaseModelMBean

A ModelMBean implementation for the org.apache.catalina.users.MemoryUserDatabase component.

author
Craig R. McClanahan
version
$Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $

Fields Summary
protected org.apache.tomcat.util.modeler.Registry
registry
The configuration information registry for our managed beans.
protected MBeanServer
mserver
The MBeanServer in which we are registered.
protected org.apache.tomcat.util.modeler.ManagedBean
managed
The ManagedBean information describing this MBean.
protected org.apache.tomcat.util.modeler.ManagedBean
managedGroup
The ManagedBean information describing Group MBeans.
protected org.apache.tomcat.util.modeler.ManagedBean
managedRole
The ManagedBean information describing Group MBeans.
protected org.apache.tomcat.util.modeler.ManagedBean
managedUser
The ManagedBean information describing User MBeans.
Constructors Summary
public MemoryUserDatabaseMBean()
Construct a ModelMBean with default ModelMBeanInfo information.

exception
MBeanException if the initializer of an object throws an exception
exception
RuntimeOperationsException if an IllegalArgumentException occurs


        super();

    
Methods Summary
public java.lang.StringcreateGroup(java.lang.String groupname, java.lang.String description)
Create a new Group and return the corresponding MBean Name.

param
groupname Group name of the new group
param
description Description of the new group


        UserDatabase database = (UserDatabase) this.resource;
        Group group = database.createGroup(groupname, description);
        try {
            MBeanUtils.createMBean(group);
        } catch (Exception e) {
            IllegalArgumentException iae = new IllegalArgumentException
                ("Exception creating group " + group + " MBean");
            iae.initCause(e);
            throw iae;
        }
        return (findGroup(groupname));

    
public java.lang.StringcreateRole(java.lang.String rolename, java.lang.String description)
Create a new Role and return the corresponding MBean Name.

param
rolename Group name of the new group
param
description Description of the new group


        UserDatabase database = (UserDatabase) this.resource;
        Role role = database.createRole(rolename, description);
        try {
            MBeanUtils.createMBean(role);
        } catch (Exception e) {
            IllegalArgumentException iae = new IllegalArgumentException
                ("Exception creating role " + role + " MBean");
            iae.initCause(e);
            throw iae;
        }
        return (findRole(rolename));

    
public java.lang.StringcreateUser(java.lang.String username, java.lang.String password, java.lang.String fullName)
Create a new User and return the corresponding MBean Name.

param
username User name of the new user
param
password Password for the new user
param
fullName Full name for the new user


        UserDatabase database = (UserDatabase) this.resource;
        User user = database.createUser(username, password, fullName);
        try {
            MBeanUtils.createMBean(user);
        } catch (Exception e) {
            IllegalArgumentException iae = new IllegalArgumentException
                ("Exception creating user " + user + " MBean");
            iae.initCause(e);
            throw iae;
        }
        return (findUser(username));

    
public java.lang.StringfindGroup(java.lang.String groupname)
Return the MBean Name for the specified group name (if any); otherwise return null.

param
groupname Group name to look up


        UserDatabase database = (UserDatabase) this.resource;
        Group group = database.findGroup(groupname);
        if (group == null) {
            return (null);
        }
        try {
            ObjectName oname =
                MBeanUtils.createObjectName(managedGroup.getDomain(), group);
            return (oname.toString());
        } catch (MalformedObjectNameException e) {
            IllegalArgumentException iae = new IllegalArgumentException
                ("Cannot create object name for group " + group);
            iae.initCause(e);
            throw iae;
        }

    
public java.lang.StringfindRole(java.lang.String rolename)
Return the MBean Name for the specified role name (if any); otherwise return null.

param
rolename Role name to look up


        UserDatabase database = (UserDatabase) this.resource;
        Role role = database.findRole(rolename);
        if (role == null) {
            return (null);
        }
        try {
            ObjectName oname =
                MBeanUtils.createObjectName(managedRole.getDomain(), role);
            return (oname.toString());
        } catch (MalformedObjectNameException e) {
            IllegalArgumentException iae = new IllegalArgumentException
                ("Cannot create object name for role " + role);
            iae.initCause(e);
            throw iae;
        }

    
public java.lang.StringfindUser(java.lang.String username)
Return the MBean Name for the specified user name (if any); otherwise return null.

param
username User name to look up


        UserDatabase database = (UserDatabase) this.resource;
        User user = database.findUser(username);
        if (user == null) {
            return (null);
        }
        try {
            ObjectName oname =
                MBeanUtils.createObjectName(managedUser.getDomain(), user);
            return (oname.toString());
        } catch (MalformedObjectNameException e) {
            IllegalArgumentException iae = new IllegalArgumentException
                ("Cannot create object name for user " + user);
            iae.initCause(e);
            throw iae;
        }

    
public java.lang.String[]getGroups()
Return the MBean Names of all groups defined in this database.



    // ------------------------------------------------------------- Attributes


                    
       

        UserDatabase database = (UserDatabase) this.resource;
        ArrayList results = new ArrayList();
        Iterator groups = database.getGroups();
        while (groups.hasNext()) {
            Group group = (Group) groups.next();
            results.add(findGroup(group.getGroupname()));
        }
        return ((String[]) results.toArray(new String[results.size()]));

    
public java.lang.String[]getRoles()
Return the MBean Names of all roles defined in this database.


        UserDatabase database = (UserDatabase) this.resource;
        ArrayList results = new ArrayList();
        Iterator roles = database.getRoles();
        while (roles.hasNext()) {
            Role role = (Role) roles.next();
            results.add(findRole(role.getRolename()));
        }
        return ((String[]) results.toArray(new String[results.size()]));

    
public java.lang.String[]getUsers()
Return the MBean Names of all users defined in this database.


        UserDatabase database = (UserDatabase) this.resource;
        ArrayList results = new ArrayList();
        Iterator users = database.getUsers();
        while (users.hasNext()) {
            User user = (User) users.next();
            results.add(findUser(user.getUsername()));
        }
        return ((String[]) results.toArray(new String[results.size()]));

    
public voidremoveGroup(java.lang.String groupname)
Remove an existing group and destroy the corresponding MBean.

param
groupname Group name to remove


        UserDatabase database = (UserDatabase) this.resource;
        Group group = database.findGroup(groupname);
        if (group == null) {
            return;
        }
        try {
            MBeanUtils.destroyMBean(group);
            database.removeGroup(group);
        } catch (Exception e) {
            IllegalArgumentException iae = new IllegalArgumentException
                ("Exception destroying group " + group + " MBean");
            iae.initCause(e);
            throw iae;
        }

    
public voidremoveRole(java.lang.String rolename)
Remove an existing role and destroy the corresponding MBean.

param
rolename Role name to remove


        UserDatabase database = (UserDatabase) this.resource;
        Role role = database.findRole(rolename);
        if (role == null) {
            return;
        }
        try {
            MBeanUtils.destroyMBean(role);
            database.removeRole(role);
        } catch (Exception e) {
            IllegalArgumentException iae = new IllegalArgumentException
                ("Exception destroying role " + role + " MBean");
            iae.initCause(e);
            throw iae;
        }

    
public voidremoveUser(java.lang.String username)
Remove an existing user and destroy the corresponding MBean.

param
username User name to remove


        UserDatabase database = (UserDatabase) this.resource;
        User user = database.findUser(username);
        if (user == null) {
            return;
        }
        try {
            MBeanUtils.destroyMBean(user);
            database.removeUser(user);
        } catch (Exception e) {
            IllegalArgumentException iae = new IllegalArgumentException
                ("Exception destroying user " + user + " MBean");
            iae.initCause(e);
            throw iae;
        }