Java Code Examples for org.apache.catalina.core.StandardServer#getGlobalNamingResources()

The following examples show how to use org.apache.catalina.core.StandardServer#getGlobalNamingResources() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TomcatJndiBuilder.java    From tomee with Apache License 2.0 6 votes vote down vote up
public static void importOpenEJBResourcesInTomcat(final Collection<ResourceInfo> resources, final StandardServer server) {
    final NamingResourcesImpl naming = server.getGlobalNamingResources();

    for (final ResourceInfo info : resources) {
        final String name = info.id;
        // if invalid or existing or lazy just skip it cause doesnt work during startup
        if (name == null || naming.findResource(name) != null || info.properties.containsKey("UseAppClassLoader")) {
            continue;
        }

        final ContextResource resource = new ContextResource();
        resource.setName(name);
        resource.setProperty(Constants.FACTORY, ResourceFactory.class.getName());
        resource.setProperty(NamingUtil.NAME, name);
        resource.setType(info.className);
        resource.setAuth("Container");

        naming.addResource(resource);
    }
}
 
Example 2
Source File: TomcatWebAppBuilder.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
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
        }
    }
}
 
Example 3
Source File: StandardServerSF.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Store the specified server element children.
 *
 * @param aWriter Current output writer
 * @param indent Indentation level
 * @param aObject Server to store
 * @param parentDesc The element description
 * @throws Exception Configuration storing error
 */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aObject,
        StoreDescription parentDesc) throws Exception {
    if (aObject instanceof StandardServer) {
        StandardServer server = (StandardServer) aObject;
        // Store nested <Listener> elements
        LifecycleListener listeners[] = ((Lifecycle) server)
                .findLifecycleListeners();
        storeElementArray(aWriter, indent, listeners);
        /*LifecycleListener listener = null;
        for (int i = 0; listener == null && i < listeners.length; i++)
            if (listeners[i] instanceof ServerLifecycleListener)
                listener = listeners[i];
        if (listener != null) {
            StoreDescription elementDesc = getRegistry()
                    .findDescription(
                            StandardServer.class.getName()
                                    + ".[ServerLifecycleListener]");
            if (elementDesc != null) {
                elementDesc.getStoreFactory().store(aWriter, indent,
                        listener);
            }
        }*/
        // Store nested <GlobalNamingResources> element
        NamingResourcesImpl globalNamingResources = server
                .getGlobalNamingResources();
        StoreDescription elementDesc = getRegistry().findDescription(
                NamingResourcesImpl.class.getName()
                        + ".[GlobalNamingResources]");
        if (elementDesc != null) {
            elementDesc.getStoreFactory().store(aWriter, indent,
                    globalNamingResources);
        }
        // Store nested <Service> elements
        Service services[] = server.findServices();
        storeElementArray(aWriter, indent, services);
    }
}
 
Example 4
Source File: TomEEDefaultIdentityStore.java    From tomee with Apache License 2.0 5 votes vote down vote up
@PostConstruct
private void init() throws Exception {
    final StandardServer server = TomcatHelper.getServer();
    final NamingResourcesImpl resources = server.getGlobalNamingResources();
    final ContextResource userDataBaseResource = resources.findResource("UserDatabase");
    userDatabase = (UserDatabase) server.getGlobalNamingContext().lookup(userDataBaseResource.getName());
}
 
Example 5
Source File: OpenEJBNamingContextListener.java    From tomee with Apache License 2.0 4 votes vote down vote up
public OpenEJBNamingContextListener(final StandardServer standardServer) {
    this.standardServer = standardServer;
    namingResources = standardServer.getGlobalNamingResources();
}