@Override public void addContextResourceLink(Context context, List<ApplicationResource> resourceList, boolean contextBound) { NamingResourcesImpl namingResources = context.getNamingResources(); for (ContextResourceLink link : namingResources.findResourceLinks()) { ApplicationResource resource = new ApplicationResource(); logger.debug("reading resourceLink: {}", link.getName()); resource.setApplicationName(context.getName()); resource.setName(link.getName()); resource.setType(link.getType()); resource.setLinkTo(link.getGlobal()); resourceList.add(resource); } }
@Override public void addContextResource(Context context, List<ApplicationResource> resourceList, boolean contextBound) { NamingResourcesImpl namingResources = context.getNamingResources(); for (ContextResource contextResource : namingResources.findResources()) { ApplicationResource resource = new ApplicationResource(); logger.info("reading resource: {}", contextResource.getName()); resource.setApplicationName(context.getName()); resource.setName(contextResource.getName()); resource.setType(contextResource.getType()); resource.setScope(contextResource.getScope()); resource.setAuth(contextResource.getAuth()); resource.setDescription(contextResource.getDescription()); resourceList.add(resource); } }
public void addContextResource(Context context, List resourceList, boolean contextBound) { NamingResourcesImpl namingResources = context.getNamingResources(); ContextResource[] resources = namingResources.findResources(); for (int i = 0; i < resources.length; i++) { ContextResource contextResource = resources[i]; ApplicationResource resource = new ApplicationResource(); logger.info("reading resource: " + contextResource.getName()); resource.setApplicationName(context.getName()); resource.setName(contextResource.getName()); resource.setType(contextResource.getType()); resource.setScope(contextResource.getScope()); resource.setAuth(contextResource.getAuth()); resource.setDescription(contextResource.getDescription()); //lookupResource(resource, contextBound, false); resourceList.add(resource); } }
private boolean isLookupRef(final NamingResourcesImpl naming, final InjectableInfo ref) { if (ref.location == null) { return false; } if (ref.location.jndiName == null) { return false; } if (!ref.location.jndiName.startsWith("java:")) { return false; } final ContextResourceEnvRef lookup = new ContextResourceEnvRef(); lookup.setName(ref.referenceName.replaceAll("^comp/env/", "")); lookup.setProperty(Constants.FACTORY, LookupFactory.class.getName()); lookup.setProperty(NamingUtil.JNDI_NAME, ref.location.jndiName); lookup.setType(Object.class.getName()); lookup.setOverride(false); naming.addResourceEnvRef(lookup); return true; }
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); } }
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 } } }
@Override protected void contextConfig(final Digester digester) { final NamingResourcesImpl resources; if (context != null) { resources = context.getNamingResources(); } else { resources = null; } if (resources instanceof OpenEJBNamingResource) { ((OpenEJBNamingResource) resources).setTomcatResource(true); } super.contextConfig(digester); if (resources instanceof OpenEJBNamingResource) { ((OpenEJBNamingResource) resources).setTomcatResource(false); } if (context instanceof StandardContext) { final StandardContext standardContext = (StandardContext) context; final NamingContextListener namingContextListener = standardContext.getNamingContextListener(); if (null != namingContextListener) { namingContextListener.setExceptionOnFailedWrite(standardContext.getJndiExceptionOnFailedWrite()); } } }
@Override public TomcatServerBuilder addGlobalResource(ContextResource resource) { if (!enableNaming) { enableJndi(); } if (server.getGlobalNamingResources() == null) { NamingResourcesImpl globalNamingResources = new NamingResourcesImpl(); server.setGlobalNamingResources(globalNamingResources); globalNamingResources.setContainer(server); } server.getGlobalNamingResources().addResource(resource); return this; }
public void mergeRef(final NamingResourcesImpl naming, final EjbReferenceInfo ref) { if (isLookupRef(naming, ref)) { return; } ContextEjb ejb = naming.findEjb(ref.referenceName.replaceAll("^comp/env/", "")); boolean addEntry = false; if (ejb == null) { ejb = new ContextEjb(); ejb.setName(ref.referenceName.replaceAll("^comp/env/", "")); addEntry = true; } ejb.setProperty(Constants.FACTORY, EjbFactory.class.getName()); ejb.setProperty(NamingUtil.NAME, ref.referenceName.replaceAll("^comp/env/", "")); ejb.setHome(ref.homeClassName); ejb.setRemote(ref.interfaceClassName); ejb.setLink(null); ejb.setType(ref.interfaceClassName); if (useCrossClassLoaderRef) { ejb.setProperty(NamingUtil.EXTERNAL, Boolean.toString(ref.externalReference)); } if (ref.ejbDeploymentId != null) { ejb.setProperty(NamingUtil.DEPLOYMENT_ID, ref.ejbDeploymentId); } if (ref.location != null) { ejb.setProperty(NamingUtil.JNDI_NAME, ref.location.jndiName); ejb.setProperty(NamingUtil.JNDI_PROVIDER_ID, ref.location.jndiProviderId); } if (addEntry) { naming.addEjb(ejb); } if (replaceEntry) { ContextAccessController.setWritable(namingContextListener.getName(), standardContext.getNamingToken()); if (!addEntry) { namingContextListener.removeEjb(ejb.getName()); } namingContextListener.addEjb(ejb); ContextAccessController.setReadOnly(namingContextListener.getName()); } }
public void mergeRef(final NamingResourcesImpl naming, final EjbLocalReferenceInfo ref) { if (isLookupRef(naming, ref)) { return; } // NamingContextListener.addLocalEjb is empty so we'll just use an ejb ref ContextEjb ejb = naming.findEjb(ref.referenceName.replaceAll("^comp/env/", "")); boolean addEntry = false; if (ejb == null) { ejb = new ContextEjb(); ejb.setName(ref.referenceName.replaceAll("^comp/env/", "")); addEntry = true; } ejb.setProperty(Constants.FACTORY, EjbFactory.class.getName()); ejb.setProperty(NamingUtil.NAME, ref.referenceName.replaceAll("^comp/env/", "")); ejb.setHome(ref.homeClassName); ejb.setRemote(null); ejb.setProperty(ref.localbean ? NamingUtil.LOCALBEAN : NamingUtil.LOCAL, ref.interfaceClassName); ejb.setLink(null); ejb.setType(ref.interfaceClassName); if (ref.ejbDeploymentId != null) { ejb.setProperty(NamingUtil.DEPLOYMENT_ID, ref.ejbDeploymentId); } if (ref.location != null) { ejb.setProperty(NamingUtil.JNDI_NAME, ref.location.jndiName); ejb.setProperty(NamingUtil.JNDI_PROVIDER_ID, ref.location.jndiProviderId); } if (addEntry) { naming.addEjb(ejb); } if (replaceEntry) { ContextAccessController.setWritable(namingContextListener.getName(), standardContext.getNamingToken()); if (!addEntry) { namingContextListener.removeEjb(ejb.getName()); } namingContextListener.addEjb(ejb); ContextAccessController.setReadOnly(namingContextListener.getName()); } }
public void mergeRef(final NamingResourcesImpl naming, final ResourceEnvReferenceInfo ref) { if (isLookupRef(naming, ref)) { return; } ContextResourceEnvRef resourceEnv = naming.findResourceEnvRef(ref.referenceName.replaceAll("^comp/env/", "")); boolean addEntry = false; if (resourceEnv == null) { resourceEnv = new ContextResourceEnvRef(); resourceEnv.setName(ref.referenceName.replaceAll("^comp/env/", "")); addEntry = true; } resourceEnv.setType(ref.resourceEnvRefType); if (UserTransaction.class.getName().equals(ref.resourceEnvRefType)) { resourceEnv.setProperty(Constants.FACTORY, UserTransactionFactory.class.getName()); } else if (TransactionManager.class.getName().equals(ref.resourceEnvRefType)) { resourceEnv.setProperty(Constants.FACTORY, SystemComponentFactory.class.getName()); resourceEnv.setProperty(NamingUtil.COMPONENT_TYPE, TransactionManager.class.getName()); } else if (TransactionSynchronizationRegistry.class.getName().equals(ref.resourceEnvRefType)) { resourceEnv.setProperty(Constants.FACTORY, SystemComponentFactory.class.getName()); resourceEnv.setProperty(NamingUtil.COMPONENT_TYPE, TransactionSynchronizationRegistry.class.getName()); } else if ("org.omg.CORBA.ORB".equals(ref.resourceEnvRefType)) { resourceEnv.setProperty(Constants.FACTORY, SystemComponentFactory.class.getName()); resourceEnv.setProperty(NamingUtil.COMPONENT_TYPE, ref.resourceEnvRefType); } else if (HandleDelegate.class.getName().equals(ref.resourceEnvRefType)) { resourceEnv.setProperty(Constants.FACTORY, SystemComponentFactory.class.getName()); resourceEnv.setProperty(NamingUtil.COMPONENT_TYPE, HandleDelegate.class.getName()); } else { resourceEnv.setProperty(Constants.FACTORY, ResourceFactory.class.getName()); resourceEnv.setProperty(NamingUtil.NAME, ref.referenceName.replaceAll("^comp/env/", "")); if (ref.resourceID != null) { resourceEnv.setProperty(NamingUtil.RESOURCE_ID, ref.resourceID); } if (ref.location != null) { resourceEnv.setProperty(NamingUtil.JNDI_NAME, ref.location.jndiName); resourceEnv.setProperty(NamingUtil.JNDI_PROVIDER_ID, ref.location.jndiProviderId); } } if (addEntry) { naming.addResourceEnvRef(resourceEnv); } if (replaceEntry) { ContextAccessController.setWritable(namingContextListener.getName(), standardContext.getNamingToken()); if (!addEntry) { namingContextListener.removeResourceEnvRef(resourceEnv.getName()); } namingContextListener.addResourceEnvRef(resourceEnv); ContextAccessController.setReadOnly(namingContextListener.getName()); } }
private boolean isOpenEjb(final NamingResourcesImpl naming, final String name) { final ContextResource resource = naming.findResource(name); return resource != null && ResourceFactory.class.getName().equals(resource.getProperty("factory")); }
@Override public NamingResourcesImpl getGlobalNamingResources() { return server.getGlobalNamingResources(); }
@Override public void setGlobalNamingResources(NamingResourcesImpl globalNamingResources) { throw new UnsupportedOperationException("GlobalNamingResources can't be changed at runtime"); }