Search in sources :

Example 21 with Role

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

the class SparseUserDatabaseMBean 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) {
        throw new IllegalArgumentException(sm.getString("userMBean.destroyError.role", rolename), e);
    }
}
Also used : Role(org.apache.catalina.Role) UserDatabase(org.apache.catalina.UserDatabase)

Example 22 with Role

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

the class SparseUserDatabaseMBean 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) {
        throw new IllegalArgumentException(sm.getString("userMBean.createMBeanError.role", rolename), e);
    }
    return findRole(rolename);
}
Also used : Role(org.apache.catalina.Role) UserDatabase(org.apache.catalina.UserDatabase)

Example 23 with Role

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

the class DataSourceUserDatabaseMBean method removeUserRole.

/**
 * Remove specified role from the user.
 * @param username The user name
 * @param rolename The role name
 */
public void removeUserRole(String username, String rolename) {
    UserDatabase database = (UserDatabase) this.resource;
    User user = database.findUser(username);
    Role role = database.findRole(rolename);
    if (user != null && role != null) {
        user.removeRole(role);
    }
}
Also used : Role(org.apache.catalina.Role) User(org.apache.catalina.User) UserDatabase(org.apache.catalina.UserDatabase)

Example 24 with Role

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

the class DataSourceUserDatabaseMBean method removeGroupRole.

/**
 * Remove role from a group.
 * @param groupname The group name
 * @param rolename The role name
 */
public void removeGroupRole(String groupname, String rolename) {
    UserDatabase database = (UserDatabase) this.resource;
    Group group = database.findGroup(groupname);
    Role role = database.findRole(rolename);
    if (group != null && role != null) {
        group.removeRole(role);
    }
}
Also used : Role(org.apache.catalina.Role) Group(org.apache.catalina.Group) UserDatabase(org.apache.catalina.UserDatabase)

Example 25 with Role

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

the class UserDatabaseRealm method getRoles.

public static String[] getRoles(User user) {
    Set<String> roles = new HashSet<>();
    Iterator<Role> uroles = user.getRoles();
    while (uroles.hasNext()) {
        Role role = uroles.next();
        roles.add(role.getName());
    }
    Iterator<Group> groups = user.getGroups();
    while (groups.hasNext()) {
        Group group = groups.next();
        uroles = group.getRoles();
        while (uroles.hasNext()) {
            Role role = uroles.next();
            roles.add(role.getName());
        }
    }
    return roles.toArray(new String[0]);
}
Also used : Role(org.apache.catalina.Role) Group(org.apache.catalina.Group) HashSet(java.util.HashSet)

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