use of org.apache.catalina.Role in project tomcat by apache.
the class SparseUserDatabaseMBean method removeRole.
/**
* Remove an existing role and destroy the corresponding MBean.
*
* @param rolename Role name to remove
*/
public void removeRole(String rolename) {
UserDatabase database = (UserDatabase) this.resource;
Role role = database.findRole(rolename);
if (role == null) {
return;
}
try {
MBeanUtils.destroyMBean(role);
database.removeRole(role);
} catch (Exception e) {
throw new IllegalArgumentException(sm.getString("userMBean.destroyError.role", rolename), e);
}
}
use of org.apache.catalina.Role in project tomcat by apache.
the class SparseUserDatabaseMBean method createRole.
/**
* Create a new Role and return the corresponding MBean Name.
*
* @param rolename Group name of the new group
* @param description Description of the new group
* @return the new role object name
*/
public String createRole(String rolename, String description) {
UserDatabase database = (UserDatabase) this.resource;
Role role = database.createRole(rolename, description);
try {
MBeanUtils.createMBean(role);
} catch (Exception e) {
throw new IllegalArgumentException(sm.getString("userMBean.createMBeanError.role", rolename), e);
}
return findRole(rolename);
}
use of org.apache.catalina.Role in project tomcat by apache.
the class DataSourceUserDatabaseMBean method removeUserRole.
/**
* Remove specified role from the user.
* @param username The user name
* @param rolename The role name
*/
public void removeUserRole(String username, String rolename) {
UserDatabase database = (UserDatabase) this.resource;
User user = database.findUser(username);
Role role = database.findRole(rolename);
if (user != null && role != null) {
user.removeRole(role);
}
}
use of org.apache.catalina.Role 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.Role 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]);
}
Aggregations