Search in sources :

Example 1 with MemoryUserDatabase

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
        }
    }
}
Also used : MemoryUserDatabase(org.apache.catalina.users.MemoryUserDatabase) UserDatabase(org.apache.catalina.UserDatabase) MemoryUserDatabase(org.apache.catalina.users.MemoryUserDatabase) NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl) ContextResource(org.apache.tomcat.util.descriptor.web.ContextResource)

Aggregations

UserDatabase (org.apache.catalina.UserDatabase)1 NamingResourcesImpl (org.apache.catalina.deploy.NamingResourcesImpl)1 MemoryUserDatabase (org.apache.catalina.users.MemoryUserDatabase)1 ContextResource (org.apache.tomcat.util.descriptor.web.ContextResource)1