@Override public BeanManager getBeanManager() { checkContainerState(container); final String callerName = getCallingClassName(); if(callerName.startsWith("org.glassfish.soteria")) { //the Java EE Security RI uses CDI.current() to perform bean lookup, however //as it is part of the container its bean archive does not have visibility to deployment beans //we use this code path to enable it to get the bean manager of the current module //so it can look up the deployment beans it needs to work try { BeanManager bm = (BeanManager) new InitialContext().lookup("java:comp/BeanManager"); if(bm != null) { return bm; } } catch (NamingException e) { //ignore } } final ClassLoader tccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged(); final Class<?> callerClass = Reflections.loadClass(callerName, tccl); if (callerClass != null) { final BeanDeploymentArchive bda = deployment.getBeanDeploymentArchive(callerClass); if (bda != null) { return new BeanManagerProxy(container.beanDeploymentArchives().get(bda)); } } // fallback for cases when we are unable to load the class or no BeanManager exists yet for the given BDA return rootBeanManager; }
/** {@inheritDoc} */ public synchronized BeanDeploymentArchive loadBeanDeploymentArchive(final Class<?> beanClass) { final BeanDeploymentArchive bda = this.getBeanDeploymentArchive(beanClass); if (bda != null) { return bda; } Module module = Module.forClass(beanClass); if (module == null) { // Bean class loaded by the bootstrap class loader if (bootstrapClassLoaderBeanDeploymentArchive == null) { bootstrapClassLoaderBeanDeploymentArchive = createAndRegisterAdditionalBeanDeploymentArchive(module, beanClass); } else { bootstrapClassLoaderBeanDeploymentArchive.addBeanClass(beanClass); } return bootstrapClassLoaderBeanDeploymentArchive; } /* * No, there is no BDA for the class yet. Let's create one. */ return createAndRegisterAdditionalBeanDeploymentArchive(module, beanClass); }