Search in sources :

Example 26 with Group

use of org.apache.catalina.Group 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 27 with Group

use of org.apache.catalina.Group 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)

Example 28 with Group

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

the class MemoryUserDatabaseMBean method createGroup.

// ------------------------------------------------------------- Operations
/**
     * Create a new Group and return the corresponding MBean Name.
     *
     * @param groupname Group name of the new group
     * @param description Description of the new group
     * @return the new group object name
     */
public String createGroup(String groupname, String description) {
    UserDatabase database = (UserDatabase) this.resource;
    Group group = database.createGroup(groupname, description);
    try {
        MBeanUtils.createMBean(group);
    } catch (Exception e) {
        IllegalArgumentException iae = new IllegalArgumentException("Exception creating group [" + groupname + "] MBean");
        iae.initCause(e);
        throw iae;
    }
    return findGroup(groupname);
}
Also used : Group(org.apache.catalina.Group) UserDatabase(org.apache.catalina.UserDatabase) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanException(javax.management.MBeanException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 29 with Group

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

the class MemoryUserDatabaseMBean method getGroups.

// ------------------------------------------------------------- Attributes
/**
     * @return the MBean Names of all groups defined in this database.
     */
public String[] getGroups() {
    UserDatabase database = (UserDatabase) this.resource;
    ArrayList<String> results = new ArrayList<>();
    Iterator<Group> groups = database.getGroups();
    while (groups.hasNext()) {
        Group group = groups.next();
        results.add(findGroup(group.getGroupname()));
    }
    return results.toArray(new String[results.size()]);
}
Also used : Group(org.apache.catalina.Group) UserDatabase(org.apache.catalina.UserDatabase) ArrayList(java.util.ArrayList)

Example 30 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)

Aggregations

Group (org.apache.catalina.Group)51 User (org.apache.catalina.User)21 UserDatabase (org.apache.catalina.UserDatabase)21 Role (org.apache.catalina.Role)20 ArrayList (java.util.ArrayList)15 MalformedObjectNameException (javax.management.MalformedObjectNameException)12 ObjectName (javax.management.ObjectName)9 PreparedStatement (java.sql.PreparedStatement)4 SQLException (java.sql.SQLException)4 MBeanException (javax.management.MBeanException)4 RuntimeOperationsException (javax.management.RuntimeOperationsException)4 Connection (java.sql.Connection)3 ResultSet (java.sql.ResultSet)3 NamingException (javax.naming.NamingException)2 OperationNotSupportedException (javax.naming.OperationNotSupportedException)2 Statement (java.sql.Statement)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 LoggingBaseTest (org.apache.catalina.startup.LoggingBaseTest)1