Search in sources :

Example 6 with Role

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

the class UserMBean method removeRole.

/**
     * Remove a {@link Role} from those this user belongs to.
     *
     * @param rolename Role name of the old role
     */
public void removeRole(String rolename) {
    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);
}
Also used : Role(org.apache.catalina.Role) User(org.apache.catalina.User)

Example 7 with Role

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

the class MemoryUserDatabaseMBean method getRoles.

/**
     * @return the MBean Names of all roles defined in this database.
     */
public String[] getRoles() {
    UserDatabase database = (UserDatabase) this.resource;
    ArrayList<String> results = new ArrayList<>();
    Iterator<Role> roles = database.getRoles();
    while (roles.hasNext()) {
        Role role = roles.next();
        results.add(findRole(role.getRolename()));
    }
    return results.toArray(new String[results.size()]);
}
Also used : Role(org.apache.catalina.Role) UserDatabase(org.apache.catalina.UserDatabase) ArrayList(java.util.ArrayList)

Example 8 with Role

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

the class MemoryUserDatabaseMBean method findRole.

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

Example 9 with Role

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

the class MemoryUserDatabaseMBean method removeRole.

/**
     * Remove an existing role and destroy the corresponding MBean.
     *
     * @param rolename Role name to remove
     */
public void removeRole(String rolename) {
    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 [" + rolename + "] MBean");
        iae.initCause(e);
        throw iae;
    }
}
Also used : Role(org.apache.catalina.Role) UserDatabase(org.apache.catalina.UserDatabase) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanException(javax.management.MBeanException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 10 with Role

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

the class MemoryUserDatabaseMBean method createRole.

/**
     * 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
     * @return the new role object name
     */
public String createRole(String rolename, String description) {
    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 [" + rolename + "] MBean");
        iae.initCause(e);
        throw iae;
    }
    return findRole(rolename);
}
Also used : Role(org.apache.catalina.Role) UserDatabase(org.apache.catalina.UserDatabase) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanException(javax.management.MBeanException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

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