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(); }
/** * 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; }
/** * 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; }