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()]);
}
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);
}
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()]);
}
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);
}
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()]);
}
Aggregations