Search in sources :

Example 6 with Group

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

the class GroupMBean method getUsers.

/**
     * @return the MBean Names of all users that are members of this group.
     */
public String[] getUsers() {
    Group group = (Group) this.resource;
    ArrayList<String> results = new ArrayList<>();
    Iterator<User> users = group.getUsers();
    while (users.hasNext()) {
        User user = null;
        try {
            user = users.next();
            ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), user);
            results.add(oname.toString());
        } catch (MalformedObjectNameException e) {
            IllegalArgumentException iae = new IllegalArgumentException("Cannot create object name for user " + user);
            iae.initCause(e);
            throw iae;
        }
    }
    return results.toArray(new String[results.size()]);
}
Also used : Group(org.apache.catalina.Group) MalformedObjectNameException(javax.management.MalformedObjectNameException) User(org.apache.catalina.User) ArrayList(java.util.ArrayList) ObjectName(javax.management.ObjectName)

Example 7 with Group

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

the class UserDatabaseRealm method getPrincipal.

/**
     * Return the Principal associated with the given user name.
     */
@Override
protected Principal getPrincipal(String username) {
    User user = database.findUser(username);
    if (user == null) {
        return null;
    }
    List<String> roles = new ArrayList<>();
    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 new GenericPrincipal(username, user.getPassword(), roles, user);
}
Also used : Role(org.apache.catalina.Role) Group(org.apache.catalina.Group) User(org.apache.catalina.User) ArrayList(java.util.ArrayList)

Example 8 with Group

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

the class UserMBean method getGroups.

// ------------------------------------------------------------- Attributes
/**
     * @return the MBean Names of all groups this user is a member of.
     */
public String[] getGroups() {
    User user = (User) this.resource;
    ArrayList<String> results = new ArrayList<>();
    Iterator<Group> groups = user.getGroups();
    while (groups.hasNext()) {
        Group group = null;
        try {
            group = groups.next();
            ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), group);
            results.add(oname.toString());
        } catch (MalformedObjectNameException e) {
            IllegalArgumentException iae = new IllegalArgumentException("Cannot create object name for group " + group);
            iae.initCause(e);
            throw iae;
        }
    }
    return results.toArray(new String[results.size()]);
}
Also used : Group(org.apache.catalina.Group) MalformedObjectNameException(javax.management.MalformedObjectNameException) User(org.apache.catalina.User) ArrayList(java.util.ArrayList) ObjectName(javax.management.ObjectName)

Example 9 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 10 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)

Aggregations

Group (org.apache.catalina.Group)16 User (org.apache.catalina.User)8 Role (org.apache.catalina.Role)7 MalformedObjectNameException (javax.management.MalformedObjectNameException)6 ArrayList (java.util.ArrayList)5 ObjectName (javax.management.ObjectName)4 UserDatabase (org.apache.catalina.UserDatabase)4 MBeanException (javax.management.MBeanException)2 RuntimeOperationsException (javax.management.RuntimeOperationsException)2 NamingException (javax.naming.NamingException)1 OperationNotSupportedException (javax.naming.OperationNotSupportedException)1