use of org.apache.catalina.users.MemoryUserDatabase 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