FileDocCategorySizeDatePackage
UserMBean.javaAPI DocGlassfish v2 API8027Fri May 04 22:32:10 BST 2007org.apache.catalina.mbeans

UserMBean

public class UserMBean extends com.sun.org.apache.commons.modeler.BaseModelMBean

A ModelMBean implementation for the org.apache.catalina.User component.

author
Craig R. McClanahan
version
$Revision: 1.4 $ $Date: 2007/05/05 05:32:10 $

Fields Summary
protected com.sun.org.apache.commons.modeler.Registry
registry
The configuration information registry for our managed beans.
protected MBeanServer
mserver
The MBeanServer in which we are registered.
protected com.sun.org.apache.commons.modeler.ManagedBean
managed
The ManagedBean information describing this MBean.
Constructors Summary
public UserMBean()
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 voidaddGroup(java.lang.String groupname)
Add a new {@link Group} to those this user belongs to.

param
groupname Group name of the new group


        User user = (User) this.resource;
        if (user == null) {
            return;
        }
        Group group = user.getUserDatabase().findGroup(groupname);
        if (group == null) {
            throw new IllegalArgumentException
                ("Invalid group name '" + groupname + "'");
        }
        user.addGroup(group);

    
public voidaddRole(java.lang.String rolename)
Add a new {@link Role} to those this user belongs to.

param
rolename Role name of the new role


        User user = (User) this.resource;
        if (user == null) {
            return;
        }
        Role role = user.getUserDatabase().findRole(rolename);
        if (role == null) {
            throw new IllegalArgumentException
                ("Invalid role name '" + rolename + "'");
        }
        user.addRole(role);

    
public java.lang.String[]getGroups()
Return the MBean Names of all groups this user is a member of.



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


                      
       

        User user = (User) this.resource;
        ArrayList results = new ArrayList();
        Iterator groups = user.getGroups();
        while (groups.hasNext()) {
            Group group = null;
            try {
                group = (Group) groups.next();
                ObjectName oname =
                    MBeanUtils.createObjectName(managed.getDomain(), group);
                results.add(oname.toString());
            } catch (MalformedObjectNameException e) {
                IllegalArgumentException iae = new IllegalArgumentException
                    ("Cannot create object name for group " + group);
                iae.initCause(e);
                throw iae;
            }
        }
        return ((String[]) results.toArray(new String[results.size()]));

    
public java.lang.String[]getRoles()
Return the MBean Names of all roles assigned to this user.


        User user = (User) this.resource;
        ArrayList results = new ArrayList();
        Iterator roles = user.getRoles();
        while (roles.hasNext()) {
            Role role = null;
            try {
                role = (Role) roles.next();
                ObjectName oname =
                    MBeanUtils.createObjectName(managed.getDomain(), role);
                results.add(oname.toString());
            } catch (MalformedObjectNameException e) {
                IllegalArgumentException iae = new IllegalArgumentException
                    ("Cannot create object name for role " + role);
                iae.initCause(e);
                throw iae;
            }
        }
        return ((String[]) results.toArray(new String[results.size()]));

    
public voidremoveGroup(java.lang.String groupname)
Remove a {@link Group} from those this user belongs to.

param
groupname Group name of the old group


        User user = (User) this.resource;
        if (user == null) {
            return;
        }
        Group group = user.getUserDatabase().findGroup(groupname);
        if (group == null) {
            throw new IllegalArgumentException
                ("Invalid group name '" + groupname + "'");
        }
        user.removeGroup(group);

    
public voidremoveRole(java.lang.String rolename)
Remove a {@link Role} from those this user belongs to.

param
rolename Role name of the old role


        User user = (User) this.resource;
        if (user == null) {
            return;
        }
        Role role = user.getUserDatabase().findRole(rolename);
        if (role == null) {
            throw new IllegalArgumentException
                ("Invalid role name '" + rolename + "'");
        }
        user.removeRole(role);