use of org.apache.catalina.UserDatabase in project tomcat by apache.
the class MemoryUserDatabaseMBean method findUser.
/**
* Return the MBean Name for the specified user name (if any);
* otherwise return <code>null</code>.
*
* @param username User name to look up
* @return the user object name
*/
public String findUser(String username) {
UserDatabase database = (UserDatabase) this.resource;
User user = database.findUser(username);
if (user == null) {
return null;
}
try {
ObjectName oname = MBeanUtils.createObjectName(managedUser.getDomain(), user);
return oname.toString();
} catch (MalformedObjectNameException e) {
IllegalArgumentException iae = new IllegalArgumentException("Cannot create object name for user [" + username + "]");
iae.initCause(e);
throw iae;
}
}
use of org.apache.catalina.UserDatabase in project tomcat by apache.
the class MemoryUserDatabaseMBean method removeGroup.
/**
* Remove an existing group and destroy the corresponding MBean.
*
* @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;
}
try {
MBeanUtils.destroyMBean(group);
database.removeGroup(group);
} catch (Exception e) {
IllegalArgumentException iae = new IllegalArgumentException("Exception destroying group [" + groupname + "] MBean");
iae.initCause(e);
throw iae;
}
}
use of org.apache.catalina.UserDatabase in project tomcat by apache.
the class MemoryUserDatabaseMBean method removeUser.
/**
* Remove an existing user and destroy the corresponding MBean.
*
* @param username User name to remove
*/
public void removeUser(String username) {
UserDatabase database = (UserDatabase) this.resource;
User user = database.findUser(username);
if (user == null) {
return;
}
try {
MBeanUtils.destroyMBean(user);
database.removeUser(user);
} catch (Exception e) {
IllegalArgumentException iae = new IllegalArgumentException("Exception destroying user [" + username + "] MBean");
iae.initCause(e);
throw iae;
}
}
use of org.apache.catalina.UserDatabase in project tomcat by apache.
the class MemoryUserDatabaseMBean 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) {
IllegalArgumentException iae = new IllegalArgumentException("Exception creating user [" + username + "] MBean");
iae.initCause(e);
throw iae;
}
return findUser(username);
}
use of org.apache.catalina.UserDatabase in project tomcat by apache.
the class MemoryUserDatabaseMBean method getRoles.
/**
* @return the MBean Names of all roles defined in this database.
*/
public String[] getRoles() {
UserDatabase database = (UserDatabase) this.resource;
ArrayList<String> results = new ArrayList<>();
Iterator<Role> roles = database.getRoles();
while (roles.hasNext()) {
Role role = roles.next();
results.add(findRole(role.getRolename()));
}
return results.toArray(new String[results.size()]);
}
Aggregations