use of org.apache.catalina.UserDatabase in project tomcat by apache.
the class MemoryUserDatabaseMBean 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) {
IllegalArgumentException iae = new IllegalArgumentException("Exception destroying role [" + rolename + "] MBean");
iae.initCause(e);
throw iae;
}
}
use of org.apache.catalina.UserDatabase in project tomcat by apache.
the class MemoryUserDatabaseMBean 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) {
IllegalArgumentException iae = new IllegalArgumentException("Exception creating role [" + rolename + "] MBean");
iae.initCause(e);
throw iae;
}
return findRole(rolename);
}
use of org.apache.catalina.UserDatabase in project tomcat by apache.
the class GlobalResourcesLifecycleListener method createMBeans.
/**
* Create the MBeans for the interesting global JNDI resources in
* the specified naming context.
*
* @param prefix Prefix for complete object name paths
* @param context Context to be scanned
*
* @exception NamingException if a JNDI exception occurs
*/
protected void createMBeans(String prefix, Context context) throws NamingException {
if (log.isDebugEnabled()) {
log.debug("Creating MBeans for Global JNDI Resources in Context '" + prefix + "'");
}
try {
NamingEnumeration<Binding> bindings = context.listBindings("");
while (bindings.hasMore()) {
Binding binding = bindings.next();
String name = prefix + binding.getName();
Object value = context.lookup(binding.getName());
if (log.isDebugEnabled()) {
log.debug("Checking resource " + name);
}
if (value instanceof Context) {
createMBeans(name + "/", (Context) value);
} else if (value instanceof UserDatabase) {
try {
createMBeans(name, (UserDatabase) value);
} catch (Exception e) {
log.error("Exception creating UserDatabase MBeans for " + name, e);
}
}
}
} catch (RuntimeException ex) {
log.error("RuntimeException " + ex);
} catch (OperationNotSupportedException ex) {
log.error("Operation not supported " + ex);
}
}
use of org.apache.catalina.UserDatabase in project tomee by apache.
the class TomcatWebAppBuilder method start.
public void start(final StandardServer server) {
if (SystemInstance.get().isDefaultProfile()) {
// add user tomee is no user are specified
try {
final NamingResourcesImpl resources = server.getGlobalNamingResources();
final ContextResource userDataBaseResource = resources.findResource("UserDatabase");
final UserDatabase db = (UserDatabase) server.getGlobalNamingContext().lookup(userDataBaseResource.getName());
if (!db.getUsers().hasNext() && db instanceof MemoryUserDatabase) {
final MemoryUserDatabase mudb = (MemoryUserDatabase) db;
final boolean oldRo = mudb.getReadonly();
try {
((MemoryUserDatabase) db).setReadonly(false);
db.createRole("tomee-admin", "tomee admin role");
db.createUser("tomee", "tomee", "TomEE");
db.findUser("tomee").addRole(db.findRole("tomee-admin"));
} finally {
mudb.setReadonly(oldRo);
}
}
} catch (final Throwable t) {
// no-op
}
}
}
Aggregations