Search in sources :

Example 11 with Group

use of org.apache.catalina.Group in project tomcat by apache.

the class MemoryUserDatabaseMBean method findGroup.

/**
     * Return the MBean Name for the specified group name (if any);
     * otherwise return <code>null</code>.
     *
     * @param groupname Group name to look up
     * @return the group object name
     */
public String findGroup(String groupname) {
    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 [" + groupname + "]");
        iae.initCause(e);
        throw iae;
    }
}
Also used : Group(org.apache.catalina.Group) MalformedObjectNameException(javax.management.MalformedObjectNameException) UserDatabase(org.apache.catalina.UserDatabase) ObjectName(javax.management.ObjectName)

Example 12 with Group

use of org.apache.catalina.Group in project tomcat by apache.

the class GroupMBean method addRole.

/**
     * Add a new {@link Role} to those this group belongs to.
     *
     * @param rolename Role name of the new role
     */
public void addRole(String rolename) {
    Group group = (Group) this.resource;
    if (group == null) {
        return;
    }
    Role role = group.getUserDatabase().findRole(rolename);
    if (role == null) {
        throw new IllegalArgumentException("Invalid role name '" + rolename + "'");
    }
    group.addRole(role);
}
Also used : Role(org.apache.catalina.Role) Group(org.apache.catalina.Group)

Example 13 with Group

use of org.apache.catalina.Group in project tomcat by apache.

the class GroupMBean method removeRole.

/**
     * Remove a {@link Role} from those this group belongs to.
     *
     * @param rolename Role name of the old role
     */
public void removeRole(String rolename) {
    Group group = (Group) this.resource;
    if (group == null) {
        return;
    }
    Role role = group.getUserDatabase().findRole(rolename);
    if (role == null) {
        throw new IllegalArgumentException("Invalid role name [" + rolename + "]");
    }
    group.removeRole(role);
}
Also used : Role(org.apache.catalina.Role) Group(org.apache.catalina.Group)

Example 14 with Group

use of org.apache.catalina.Group in project tomcat by apache.

the class GroupMBean method getRoles.

/**
     * @return the MBean Names of all authorized roles for this group.
     */
public String[] getRoles() {
    Group group = (Group) this.resource;
    ArrayList<String> results = new ArrayList<>();
    Iterator<Role> roles = group.getRoles();
    while (roles.hasNext()) {
        Role role = null;
        try {
            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 results.toArray(new String[results.size()]);
}
Also used : Role(org.apache.catalina.Role) Group(org.apache.catalina.Group) MalformedObjectNameException(javax.management.MalformedObjectNameException) ArrayList(java.util.ArrayList) ObjectName(javax.management.ObjectName)

Example 15 with Group

use of org.apache.catalina.Group in project tomcat by apache.

the class MemoryUserCreationFactory method removeRole.

/**
     * Remove the specified {@link Role} from this user database.
     *
     * @param role The role to be removed
     */
@Override
public void removeRole(Role role) {
    synchronized (roles) {
        Iterator<Group> groups = getGroups();
        while (groups.hasNext()) {
            Group group = groups.next();
            group.removeRole(role);
        }
        Iterator<User> users = getUsers();
        while (users.hasNext()) {
            User user = users.next();
            user.removeRole(role);
        }
        roles.remove(role.getRolename());
    }
}
Also used : Group(org.apache.catalina.Group) User(org.apache.catalina.User)

Aggregations

Group (org.apache.catalina.Group)16 User (org.apache.catalina.User)8 Role (org.apache.catalina.Role)7 MalformedObjectNameException (javax.management.MalformedObjectNameException)6 ArrayList (java.util.ArrayList)5 ObjectName (javax.management.ObjectName)4 UserDatabase (org.apache.catalina.UserDatabase)4 MBeanException (javax.management.MBeanException)2 RuntimeOperationsException (javax.management.RuntimeOperationsException)2 NamingException (javax.naming.NamingException)1 OperationNotSupportedException (javax.naming.OperationNotSupportedException)1