Search in sources :

Example 46 with Group

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

the class DataSourceUserDatabaseMBean method addGroupRole.

/**
 * Add role to a group.
 * @param groupname The group name
 * @param rolename The role name
 */
public void addGroupRole(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.addRole(role);
    }
}
Also used : Role(org.apache.catalina.Role) Group(org.apache.catalina.Group) UserDatabase(org.apache.catalina.UserDatabase)

Example 47 with Group

use of org.apache.catalina.Group 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;
    List<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) {
            throw new IllegalArgumentException(sm.getString("userMBean.createError.role", role), e);
        }
    }
    return results.toArray(new String[0]);
}
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 48 with Group

use of org.apache.catalina.Group 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(sm.getString("userMBean.invalidRole", rolename));
    }
    group.addRole(role);
}
Also used : Role(org.apache.catalina.Role) Group(org.apache.catalina.Group)

Example 49 with Group

use of org.apache.catalina.Group 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(sm.getString("userMBean.invalidRole", rolename));
    }
    group.removeRole(role);
}
Also used : Role(org.apache.catalina.Role) Group(org.apache.catalina.Group)

Example 50 with Group

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

the class SparseUserDatabaseMBean method getGroups.

// ------------------------------------------------------------- Attributes
/**
 * @return the MBean Names of all groups defined in this database.
 */
public String[] getGroups() {
    UserDatabase database = (UserDatabase) this.resource;
    List<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[0]);
}
Also used : Group(org.apache.catalina.Group) UserDatabase(org.apache.catalina.UserDatabase) ArrayList(java.util.ArrayList)

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