use of org.apache.catalina.Group in project tomcat by apache.
the class MemoryUserCreationFactory method createObject.
@Override
public Object createObject(Attributes attributes) {
String groupname = attributes.getValue("groupname");
if (groupname == null) {
groupname = attributes.getValue("name");
}
String description = attributes.getValue("description");
String roles = attributes.getValue("roles");
Group group = database.findGroup(groupname);
if (group == null) {
group = database.createGroup(groupname, description);
} else {
if (group.getDescription() == null) {
group.setDescription(description);
}
}
if (roles != null) {
while (roles.length() > 0) {
String rolename = null;
int comma = roles.indexOf(',');
if (comma >= 0) {
rolename = roles.substring(0, comma).trim();
roles = roles.substring(comma + 1);
} else {
rolename = roles.trim();
roles = "";
}
if (rolename.length() > 0) {
Role role = database.findRole(rolename);
if (role == null) {
role = database.createRole(rolename, null);
}
group.addRole(role);
}
}
}
return group;
}
use of org.apache.catalina.Group in project tomcat by apache.
the class DataSourceUserDatabaseMBean method removeGroup.
/**
* Remove an existing group.
*
* @param groupname Group name to remove
*/
public void removeGroup(String groupname) {
UserDatabase database = (UserDatabase) this.resource;
Group group = database.findGroup(groupname);
if (group == null) {
return;
}
database.removeGroup(group);
}
use of org.apache.catalina.Group in project tomcat by apache.
the class DataSourceUserDatabaseMBean method getUserGroups.
/**
* Get groups for a user.
* @param username The user name
* @return Array of group names
*/
public String[] getUserGroups(String username) {
UserDatabase database = (UserDatabase) this.resource;
User user = database.findUser(username);
if (user != null) {
List<String> results = new ArrayList<>();
Iterator<Group> groups = user.getGroups();
while (groups.hasNext()) {
Group group = groups.next();
results.add(group.getGroupname());
}
return results.toArray(new String[0]);
} else {
return null;
}
}
use of org.apache.catalina.Group in project tomcat by apache.
the class DataSourceUserDatabaseMBean method getGroups.
// ------------------------------------------------------------- Attributes
/**
* @return the 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(group.getGroupname());
}
return results.toArray(new String[0]);
}
use of org.apache.catalina.Group in project tomcat by apache.
the class DataSourceUserDatabaseMBean method removeUserGroup.
/**
* Remove group from user.
* @param username The user name
* @param groupname The group name
*/
public void removeUserGroup(String username, String groupname) {
UserDatabase database = (UserDatabase) this.resource;
User user = database.findUser(username);
Group group = database.findGroup(groupname);
if (user != null && group != null) {
user.removeGroup(group);
}
}
Aggregations