/** * Process the deployment unit and deploy appropriate MC beans (see details below) if it * corresponds to a no-interface view deployment. * * <p>If any beans in the unit are eligible for no-interface view, then internally this method * creates a {@link NoInterfaceViewJNDIBinderFacade} MC bean for the no-interface view. * * <p>The {@link NoInterfaceViewJNDIBinderFacade}, thus created, will be dependent on the {@link * ControllerState#DESCRIBED} state of the container (endpoint) MC bean. This way, we ensure that * this {@link NoInterfaceViewJNDIBinderFacade} will be deployed only after the corresponding * container MC bean moves to {@link ControllerState#DESCRIBED} state. */ public void deploy(DeploymentUnit unit) throws DeploymentException { if (logger.isTraceEnabled()) { logger.trace("Deploying unit " + unit.getName()); } // get processed metadata JBossMetaData metaData = unit.getAttachment(INPUT, JBossMetaData.class); if (metaData == null) { if (logger.isTraceEnabled()) logger.trace("No JBossMetadata for unit : " + unit.getName()); return; } // work on the ejbs JBossEnterpriseBeansMetaData beans = metaData.getEnterpriseBeans(); for (JBossEnterpriseBeanMetaData bean : beans) { if (bean.isSession()) { if (logger.isTraceEnabled()) { logger.trace( "Found bean of type session: " + bean.getEjbClass() + " in unit " + unit.getName()); } // too bad if (bean instanceof JBossSessionBean31MetaData) { // Process for no-interface view deploy(unit, (JBossSessionBean31MetaData) bean); } } } }
public void testMethodPermissions() throws Exception { EjbJarMetaData result = unmarshal(); JBossMetaData jbossMetaData = new JBossMetaData(); jbossMetaData.merge(null, result); // ApplicationMetaData appData = new ApplicationMetaData(jbossMetaData); // Validate the assembly descriptor permissions IAssemblyDescriptorMetaData admd = result.getAssemblyDescriptor(); MethodPermissionsMetaData allPerms = admd.getMethodPermissions(); assertEquals("ejb-jar has 4 method-permissions", 4, allPerms.size()); // Validate StatelessSession bean permission count IEnterpriseBeanMetaData ebmd = result.getEnterpriseBeans().get("StatelessSession"); MethodPermissionsMetaData beanPerms = ebmd.getMethodPermissions(); assertEquals("StatelessSession has 3 method-permissions", 3, beanPerms.size()); // Now validate the method matching logic String echo = "Echo"; String echoLocal = "EchoLocal"; String internal = "InternalRole"; /* BeanMetaData ss = appData.getBeanByEjbName("StatelessSession"); Class[] sig = {}; Set<String> perms = ss.getMethodPermissions("create", sig, InvocationType.HOME); getLog().debug("home create perms: "+perms); assertTrue("Echo can invoke StatelessSessionHome.create", perms.contains(echo)); assertTrue("EchoLocal cannot invoke StatelessSessionHome.create", perms.contains(echoLocal) == false); perms = ss.getMethodPermissions("create", sig, InvocationType.LOCALHOME); getLog().debug("local home create perms: "+perms); assertTrue("Echo can invoke StatelessSessionLocalHome.create", perms.contains(echo)); assertTrue("EchoLocal can invoke StatelessSessionLocalHome.create", perms.contains(echoLocal)); */ }
protected boolean doAccepts(DeploymentUnit unit) { // ejbs JBossMetaData jbm = unit.getAttachment(JBossMetaData.class); if (jbm != null && jbm.isMetadataComplete()) return false; // wars JBossWebMetaData jwbm = unit.getAttachment(JBossWebMetaData.class); if (jwbm != null && jwbm.isMetadataComplete()) return false; return true; }
public void testMultipleMerge() throws Exception { EjbJarMetaData result = unmarshal(); JBossMetaData jboss = unmarshal("JBoss40_testMultipleMerge.xml", JBossMetaData.class, PropertyReplacers.noop()); JBossEnterpriseBeansMetaData beans = jboss.getEnterpriseBeans(); assertEquals(4, beans.size()); JBossEnterpriseBeanMetaData entity = beans.get("EntityCallee"); assertTrue(entity instanceof JBossEntityBeanMetaData); JBossMetaData jbossMetaData = new JBossMetaData(); jbossMetaData.merge(jboss, result); entity = jbossMetaData.getEnterpriseBean("EntityCallee"); JBossEntityBeanMetaData jentity = (JBossEntityBeanMetaData) entity; assertEquals("caller-info.EntityCallee", jentity.getJndiName()); }
/** * Returns the {@link InterceptorsMetaData} which are applicable for the <code>beanName</code> in * the <code>jbossMetaData</code> * * <p>An interceptor is considered as bound to an EJB if there's atleast one interceptor binding * between the EJB and the interceptor class. The interceptor binding can either be through the * use of <interceptor-binding> element in ejb-jar.xml or through the use of {@link Interceptors} * annotation(s) in the EJB class. * * <p>If the EJB has an around-invoke element which uses class name other than the EJB class name, * then even that class is considered as an interceptor class and is considered to be bound to the * EJB. * * <p>For example: <session> <ejb-name>Dummy</ejb-name> * <ejb-class>org.myapp.ejb.MyBean</ejb-class> <around-invoke> <class>org.myapp.SomeClass</class> * <method-name>blah</method-name> </around-invoke> </session> * * <p>The <code>org.myapp.SomeClass</code> will be considered as a interceptor class bound to the * EJB, <code>org.myapp.ejb.MyBean</code>, even if there is no explicit interceptor binding * between that EJB and the <code>org.myapp.SomeClass</code> * * @param beanName The EJB name * @param jbossMetaData The {@link JBossMetaData} corresponding to the <code>beanName</code> * @return * @throws NullPointerException If either of <code>beanName</code> or <code>jbossMetaData</code> * is null */ public static InterceptorsMetaData getInterceptors(String beanName, JBossMetaData jbossMetaData) { InterceptorsMetaData beanApplicableInterceptors = new InterceptorsMetaData(); if (jbossMetaData.getAssemblyDescriptor() == null) { return beanApplicableInterceptors; } InterceptorBindingsMetaData allInterceptorBindings = jbossMetaData.getAssemblyDescriptor().getInterceptorBindings(); if (allInterceptorBindings == null) { return beanApplicableInterceptors; } InterceptorsMetaData allInterceptors = jbossMetaData.getInterceptors(); if (allInterceptors == null || allInterceptors.isEmpty()) { return beanApplicableInterceptors; } return getInterceptors(beanName, allInterceptors, allInterceptorBindings); }
/** * Returns all interceptor classes which are present in the passed <code>jbossMetaData</code>. * * <p>A class is considered an interceptor class, if it is listed in either of the following: * * <ul> * <li>In the <interceptor> element of ejb-jar.xml * <li>In the <interceptor-binding> element of ejb-jar.xml * <li>In the <class> sub-element of <around-invoke> element in the ejb-jar.xml * <li>Marked as an interceptor class through the use of {@link Interceptors} annotation in a * bean class * </ul> * * @param jbossMetaData The {@link JBossMetaData} which will scanned for interceptor classes * @return */ public static Collection<String> getAllInterceptorClasses(JBossMetaData jbossMetaData) { Collection<String> allInterceptorClassNames = new HashSet<String>(); // process <interceptors> InterceptorsMetaData interceptorsMetadata = jbossMetaData.getInterceptors(); if (interceptorsMetadata != null) { for (InterceptorMetaData interceptor : interceptorsMetadata) { if (interceptor.getInterceptorClass() != null) { allInterceptorClassNames.add(interceptor.getInterceptorClass()); } } } // process <interceptor-bindings> (a.k.a @Interceptors) JBossAssemblyDescriptorMetaData assemblyDescriptor = jbossMetaData.getAssemblyDescriptor(); if (assemblyDescriptor != null) { InterceptorBindingsMetaData interceptorBindings = assemblyDescriptor.getInterceptorBindings(); if (interceptorBindings != null) { for (InterceptorBindingMetaData interceptorBinding : interceptorBindings) { if (interceptorBinding != null) { InterceptorClassesMetaData interceptorClasses = interceptorBinding.getInterceptorClasses(); if (interceptorClasses != null) { for (String interceptorClass : interceptorClasses) { allInterceptorClassNames.add(interceptorClass); } } } } } } // process around-invoke JBossEnterpriseBeansMetaData enterpriseBeans = jbossMetaData.getEnterpriseBeans(); if (enterpriseBeans != null) { for (JBossEnterpriseBeanMetaData enterpriseBean : enterpriseBeans) { String enterpriseBeanClassName = enterpriseBean.getEjbClass(); AroundInvokesMetaData aroundInvokes = null; if (enterpriseBean.isSession()) { JBossSessionBeanMetaData sessionBean = (JBossSessionBeanMetaData) enterpriseBean; aroundInvokes = sessionBean.getAroundInvokes(); } else if (enterpriseBean.isMessageDriven()) { JBossMessageDrivenBeanMetaData messageDrivenBean = (JBossMessageDrivenBeanMetaData) enterpriseBean; aroundInvokes = messageDrivenBean.getAroundInvokes(); } if (aroundInvokes == null || aroundInvokes.isEmpty()) { continue; } for (AroundInvokeMetaData aroundInvoke : aroundInvokes) { String targetClass = aroundInvoke.getClassName(); if (targetClass == null) { continue; } // if the target class name is not the class name of the EJB, // then as per the xsd, it is considered an interceptor class if (targetClass.equals(enterpriseBeanClassName) == false) { // it's an interceptor class allInterceptorClassNames.add(targetClass); } } } } // return the interceptor class names return allInterceptorClassNames; }
public void merge(JBossMetaData override, JBossMetaData original) { NamedModuleImplMerger.merge(this, override, original); if (override != null && override.getVersion() != null) version = override.getVersion(); else if (original != null && original.getVersion() != null) version = original.getVersion(); JBossAssemblyDescriptorMetaData originalAssembly = null; InvokerProxyBindingsMetaData originalInvokerProxyBindings = null; InterceptorsMetaData originalInterceptors = null; WebservicesMetaData originalWebservices = null; JBossEnterpriseBeansMetaData originalBeans = null; if (original != null) { originalAssembly = original.assemblyDescriptor; originalInvokerProxyBindings = original.invokerProxyBindings; originalInterceptors = original.interceptors; originalWebservices = original.webservices; originalBeans = original.enterpriseBeans; if (original.ejbVersion != null) ejbVersion = original.ejbVersion; if (original.metadataComplete) metadataComplete = true; if (original.relationships != null) relationships = original.relationships; if (original.jaccContextID != null) jaccContextID = original.jaccContextID; if (original.jmxName != null) jmxName = original.jmxName; if (original.loaderRepository != null) loaderRepository = original.loaderRepository; if (original.securityDomain != null) securityDomain = original.securityDomain; if (original.unauthenticatedPrincipal != null) unauthenticatedPrincipal = original.unauthenticatedPrincipal; if (original.containerConfigurations != null) { if (containerConfigurations == null) containerConfigurations = new ContainerConfigurationsMetaData(); containerConfigurations.merge(original.containerConfigurations); } if (original.resourceManagers != null) { if (resourceManagers == null) resourceManagers = new ResourceManagersMetaData(); resourceManagers.addAll(original.resourceManagers); } } JBossAssemblyDescriptorMetaData overrideAssembly = null; InvokerProxyBindingsMetaData overrideInvokerProxyBindings = null; InterceptorsMetaData overrideInterceptors = null; WebservicesMetaData overrideWebservices = null; JBossEnterpriseBeansMetaData overrideBeans = null; if (override != null) { overrideAssembly = override.assemblyDescriptor; overrideInvokerProxyBindings = override.invokerProxyBindings; overrideInterceptors = override.interceptors; overrideWebservices = override.webservices; overrideBeans = override.enterpriseBeans; if (override.ejbVersion != null) ejbVersion = override.ejbVersion; if (override.metadataComplete) metadataComplete = true; // TODO: relationships should be merged if (override.relationships != null) relationships = original.relationships; if (override.jaccContextID != null) jaccContextID = override.jaccContextID; if (override.jmxName != null) jmxName = override.jmxName; if (override.loaderRepository != null) loaderRepository = override.loaderRepository; if (override.securityDomain != null) securityDomain = override.securityDomain; if (override.unauthenticatedPrincipal != null) unauthenticatedPrincipal = override.unauthenticatedPrincipal; // Ensure that there is no customization of the Unspecified method permissions if (override.excludeMissingMethods == false) this.excludeMissingMethods = false; if (override.containerConfigurations != null) { if (containerConfigurations == null) containerConfigurations = new ContainerConfigurationsMetaData(); containerConfigurations.merge(override.containerConfigurations); } if (override.resourceManagers != null) { if (resourceManagers == null) resourceManagers = new ResourceManagersMetaData(); resourceManagers.addAll(override.resourceManagers); } } if (assemblyDescriptor == null) assemblyDescriptor = new JBossAssemblyDescriptorMetaData(); if (overrideAssembly != null || originalAssembly != null) assemblyDescriptor.merge(overrideAssembly, originalAssembly); if (invokerProxyBindings == null) invokerProxyBindings = new InvokerProxyBindingsMetaData(); if (overrideInvokerProxyBindings != null || originalInvokerProxyBindings != null) invokerProxyBindings.merge(overrideInvokerProxyBindings, originalInvokerProxyBindings); if (interceptors == null) interceptors = new InterceptorsMetaData(); if (overrideInterceptors != null || originalInterceptors != null) interceptors.merge(overrideInterceptors, originalInterceptors); if (overrideWebservices != null || originalWebservices != null) { if (webservices == null) webservices = new WebservicesMetaData(); webservices.merge(overrideWebservices, originalWebservices); } if (enterpriseBeans == null) { enterpriseBeans = new JBossEnterpriseBeansMetaData(); enterpriseBeans.setJBossMetaData(this); } if (originalBeans != null || overrideBeans != null) enterpriseBeans.merge(overrideBeans, originalBeans); // Update run-as indentity for a run-as-principal if (enterpriseBeans != null) { for (JBossEnterpriseBeanMetaData ejb : enterpriseBeans) { String ejbName = ejb.getEjbName(); SecurityIdentityMetaData si = ejb.getSecurityIdentity(); String principalName = si != null ? si.getRunAsPrincipal() : null; // Get the run-as primary role String ejbXmlRunAs = null; if (si != null && si.getRunAs() != null) ejbXmlRunAs = si.getRunAs().getRoleName(); if (principalName != null) { // Update the run-as indentity to use the principal name if (ejbXmlRunAs == null) { // Can't make this check since the name may come from an annotation // throw new IllegalStateException("run-as-principal: " + principalName + " found in // jboss.xml but there was no run-as in ejb-jar.xml"); ejbXmlRunAs = "anonymous"; } // See if there are any additional roles for this principal Set<String> extraRoles = null; if (getAssemblyDescriptor() != null) { extraRoles = getAssemblyDescriptor().getSecurityRoleNamesByPrincipal(principalName); } RunAsIdentityMetaData runAsId = new RunAsIdentityMetaData(ejbXmlRunAs, principalName, extraRoles); runAsIdentity.put(ejbName, runAsId); } else if (ejbXmlRunAs != null) { RunAsIdentityMetaData runAsId = new RunAsIdentityMetaData(ejbXmlRunAs, null); runAsIdentity.put(ejbName, runAsId); } } } if (override != null && override.getJMSResourceAdapter() != null) jmsResourceAdapter = override.getJMSResourceAdapter(); else if (original != null && original.getJMSResourceAdapter() != null) jmsResourceAdapter = original.getJMSResourceAdapter(); }
/** * Merge the contents of override with original into this. * * @param override data which overrides original * @param original the original data */ public void merge(JBossMetaData override, EjbJarMetaData original) { IdMetaDataImplWithDescriptionGroupMerger.merge(this, override, original); if (override != null && override.getModuleName() != null) setModuleName(override.getModuleName()); else if (original instanceof NamedModule && ((NamedModule) original).getModuleName() != null) setModuleName(((NamedModule) original).getModuleName()); if (override != null && override.getVersion() != null) version = override.getVersion(); else if (original != null && original.getVersion() != null) version = original.getVersion(); if (assemblyDescriptor == null) assemblyDescriptor = new JBossAssemblyDescriptorMetaData(); if (resourceManagers == null) resourceManagers = new ResourceManagersMetaData(); if (containerConfigurations == null) containerConfigurations = new ContainerConfigurationsMetaData(); if (override != null && override.containerConfigurations != null) containerConfigurations.merge(override.containerConfigurations); if (invokerProxyBindings == null) invokerProxyBindings = new InvokerProxyBindingsMetaData(); if (override != null && override.invokerProxyBindings != null) invokerProxyBindings.merge(override.invokerProxyBindings); if (interceptors == null) interceptors = new InterceptorsMetaData(); if (override != null && override.webservices != null) webservices = new WebservicesMetaData(); if (original != null) { ejbVersion = original.getVersion(); relationships = original.getRelationships(); if (original instanceof EjbJar3xMetaData) { EjbJar3xMetaData original3x = (EjbJar3xMetaData) original; metadataComplete = original3x.isMetadataComplete(); } } if (override != null && override.assemblyDescriptor != null) { assemblyDescriptor.merge(override.assemblyDescriptor, original.getAssemblyDescriptor()); } else if (original != null && original.getAssemblyDescriptor() != null) { assemblyDescriptor.merge(null, original.getAssemblyDescriptor()); } // /* FIXME if(override != null && override.resourceManagers != null) resourceManagers.merge(override.resourceManagers); */ if (override != null && override.interceptors != null) interceptors.merge(override.interceptors); else if (original != null && original.getInterceptors() != null) interceptors.merge(original.getInterceptors()); if (override != null) { if (override.jaccContextID != null) jaccContextID = override.jaccContextID; if (override.jmxName != null) jmxName = override.jmxName; if (override.loaderRepository != null) loaderRepository = override.loaderRepository; if (override.securityDomain != null) securityDomain = override.securityDomain; if (override.unauthenticatedPrincipal != null) unauthenticatedPrincipal = override.unauthenticatedPrincipal; if (override.metadataComplete) metadataComplete = true; } if (webservices != null && override != null) webservices.merge(override.webservices); if (enterpriseBeans == null) { enterpriseBeans = new JBossEnterpriseBeansMetaData(); enterpriseBeans.setJBossMetaData(this); } JBossEnterpriseBeansMetaData jbeans = null; if (override != null) { jbeans = override.enterpriseBeans; // Ensure that there is no customization of the Unspecified method permissions if (override.excludeMissingMethods == false) this.excludeMissingMethods = false; } EnterpriseBeansMetaData beans = null; if (original != null) beans = original.getEnterpriseBeans(); boolean isEJB3x = (original == null || original.isEJB3x()); enterpriseBeans.merge(jbeans, beans, "ejb-jar.xml", "jboss.xml", !isEJB3x); // Update run-as indentity for a run-as-principal if (enterpriseBeans != null) { for (JBossEnterpriseBeanMetaData ejb : enterpriseBeans) { String ejbName = ejb.getEjbName(); SecurityIdentityMetaData si = ejb.getSecurityIdentity(); String principalName = si != null ? si.getRunAsPrincipal() : null; // Get the run-as primary role String ejbXmlRunAs = null; if (si != null && si.getRunAs() != null) ejbXmlRunAs = si.getRunAs().getRoleName(); if (principalName != null) { // Update the run-as indentity to use the principal name if (ejbXmlRunAs == null) { // Can't make this check since the name may come from an annotation // throw new IllegalStateException("run-as-principal: " + principalName + " found in // jboss.xml but there was no run-as in ejb-jar.xml"); ejbXmlRunAs = "anonymous"; } // See if there are any additional roles for this principal Set<String> extraRoles = null; if (getAssemblyDescriptor() != null) { extraRoles = getAssemblyDescriptor().getSecurityRoleNamesByPrincipal(principalName); } RunAsIdentityMetaData runAsId = new RunAsIdentityMetaData(ejbXmlRunAs, principalName, extraRoles); runAsIdentity.put(ejbName, runAsId); } else if (ejbXmlRunAs != null) { RunAsIdentityMetaData runAsId = new RunAsIdentityMetaData(ejbXmlRunAs, null); runAsIdentity.put(ejbName, runAsId); } } } if (override != null && override.jmsResourceAdapter != null) jmsResourceAdapter = override.jmsResourceAdapter; }