use of org.apache.catalina.User in project tomcat by apache.
the class UserMBean method getRoles.
/**
* @return the MBean Names of all roles assigned to this user.
*/
public String[] getRoles() {
User user = (User) this.resource;
List<String> results = new ArrayList<>();
Iterator<Role> roles = user.getRoles();
while (roles.hasNext()) {
Role role = null;
try {
role = roles.next();
ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), role);
results.add(oname.toString());
} catch (MalformedObjectNameException e) {
throw new IllegalArgumentException(sm.getString("userMBean.createError.role", role), e);
}
}
return results.toArray(new String[0]);
}
use of org.apache.catalina.User in project tomcat by apache.
the class UserMBean method addGroup.
// ------------------------------------------------------------- Operations
/**
* Add a new {@link Group} to those this user belongs to.
*
* @param groupname Group name of the new group
*/
public void addGroup(String groupname) {
User user = (User) this.resource;
if (user == null) {
return;
}
Group group = user.getUserDatabase().findGroup(groupname);
if (group == null) {
throw new IllegalArgumentException(sm.getString("userMBean.invalidGroup", groupname));
}
user.addGroup(group);
}
use of org.apache.catalina.User in project tomcat by apache.
the class UserMBean method removeGroup.
/**
* Remove a {@link Group} from those this user belongs to.
*
* @param groupname Group name of the old group
*/
public void removeGroup(String groupname) {
User user = (User) this.resource;
if (user == null) {
return;
}
Group group = user.getUserDatabase().findGroup(groupname);
if (group == null) {
throw new IllegalArgumentException(sm.getString("userMBean.invalidGroup", groupname));
}
user.removeGroup(group);
}
use of org.apache.catalina.User in project tomcat by apache.
the class UserMBean method addRole.
/**
* Add a new {@link Role} to those this user belongs to.
*
* @param rolename Role name of the new role
*/
public void addRole(String rolename) {
User user = (User) this.resource;
if (user == null) {
return;
}
Role role = user.getUserDatabase().findRole(rolename);
if (role == null) {
throw new IllegalArgumentException(sm.getString("userMBean.invalidRole", rolename));
}
user.addRole(role);
}
use of org.apache.catalina.User in project tomcat by apache.
the class SparseUserDatabaseMBean method createUser.
/**
* Create a new User and return the corresponding MBean Name.
*
* @param username User name of the new user
* @param password Password for the new user
* @param fullName Full name for the new user
* @return the new user object name
*/
public String createUser(String username, String password, String fullName) {
UserDatabase database = (UserDatabase) this.resource;
User user = database.createUser(username, password, fullName);
try {
MBeanUtils.createMBean(user);
} catch (Exception e) {
throw new IllegalArgumentException(sm.getString("userMBean.createMBeanError.user", username), e);
}
return findUser(username);
}
Aggregations