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