Search in sources :

Example 26 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 27 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 28 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 29 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)

Example 30 with Role

use of org.apache.catalina.Role in project tomcat70 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<String>();
    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)

Aggregations

Role (org.apache.catalina.Role)50 UserDatabase (org.apache.catalina.UserDatabase)21 Group (org.apache.catalina.Group)20 User (org.apache.catalina.User)18 ArrayList (java.util.ArrayList)13 MalformedObjectNameException (javax.management.MalformedObjectNameException)10 ObjectName (javax.management.ObjectName)7 PreparedStatement (java.sql.PreparedStatement)5 SQLException (java.sql.SQLException)5 Connection (java.sql.Connection)4 ResultSet (java.sql.ResultSet)4 MBeanException (javax.management.MBeanException)4 RuntimeOperationsException (javax.management.RuntimeOperationsException)4 Statement (java.sql.Statement)2 NamingException (javax.naming.NamingException)2 OperationNotSupportedException (javax.naming.OperationNotSupportedException)2 LoggingBaseTest (org.apache.catalina.startup.LoggingBaseTest)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1