Search in sources :

Example 11 with Role

use of org.apache.catalina.Role 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 12 with Role

use of org.apache.catalina.Role 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 13 with Role

use of org.apache.catalina.Role 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 14 with Role

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

the class MemoryUserCreationFactory method createObject.

@Override
public Object createObject(Attributes attributes) {
    String groupname = attributes.getValue("groupname");
    if (groupname == null) {
        groupname = attributes.getValue("name");
    }
    String description = attributes.getValue("description");
    String roles = attributes.getValue("roles");
    Group group = database.createGroup(groupname, description);
    if (roles != null) {
        while (roles.length() > 0) {
            String rolename = null;
            int comma = roles.indexOf(',');
            if (comma >= 0) {
                rolename = roles.substring(0, comma).trim();
                roles = roles.substring(comma + 1);
            } else {
                rolename = roles.trim();
                roles = "";
            }
            if (rolename.length() > 0) {
                Role role = database.findRole(rolename);
                if (role == null) {
                    role = database.createRole(rolename, null);
                }
                group.addRole(role);
            }
        }
    }
    return (group);
}
Also used : Role(org.apache.catalina.Role) Group(org.apache.catalina.Group)

Aggregations

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