protected void assertInterceptors(IEjbJarMetaData<?, ?, ?, ?> ejbJarMetaData, Mode mode) {
   InterceptorsMetaData interceptorsMetaData = ejbJarMetaData.getInterceptors();
   assertNotNull("interceptors is null", interceptorsMetaData);
   // assertId("interceptors", interceptorsMetaData);
   assertDescriptions("interceptors", interceptorsMetaData.getDescriptions());
   assertEquals(2, interceptorsMetaData.size());
   int count = 1;
   for (InterceptorMetaData interceptor : interceptorsMetaData)
     assertInterceptor("interceptor" + (count++), interceptor, mode);
 }
Пример #2
0
 /**
  * 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);
 }
Пример #3
0
  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();
  }
Пример #4
0
  /**
   * 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;
  }
Пример #5
0
  /**
   * Utility method which, given a bean name, all interceptors available in a deployment and the all
   * the interceptor binding information, will return only those interceptors which are applicable
   * to the EJB corresponding to the bean name
   *
   * @param ejbName Name of the EJB
   * @param allInterceptors {@link InterceptorsMetaData} of all interceptors
   * @param allInterceptorBindings {@link InterceptorBindingsMetaData} of all interceptor bindings
   * @return
   */
  private static InterceptorsMetaData getInterceptors(
      String ejbName,
      InterceptorsMetaData allInterceptors,
      InterceptorBindingsMetaData allInterceptorBindings) {
    InterceptorsMetaData beanApplicableInterceptors = new InterceptorsMetaData();
    // the default interceptors (ejbname = *) will be
    // considered as *not* applicable for a bean, if *all* the interceptor
    // bindings for that bean, have set the exclude-default-interceptors to true
    boolean includeDefaultInterceptors = false;
    InterceptorsMetaData defaultInterceptors = new InterceptorsMetaData();
    for (InterceptorBindingMetaData binding : allInterceptorBindings) {
      // the interceptor binding corresponds to the bean we are interested in
      if (ejbName != null && ejbName.equals(binding.getEjbName())) {
        // atleast one interceptor binding on the bean, is interested
        // in the default interceptors (ejbname = *). So set the flag to include the default
        // interceptors in the list of applicable interceptors
        if (binding.isExcludeDefaultInterceptors() == false) {
          includeDefaultInterceptors = true;
        }
        InterceptorClassesMetaData interceptorClasses = null;
        if (binding.isTotalOrdering()) {
          interceptorClasses = binding.getInterceptorOrder();
        } else {
          interceptorClasses = binding.getInterceptorClasses();
        }
        // interceptor binding has no classes, so move on to the next interceptor binding
        if (interceptorClasses == null || interceptorClasses.isEmpty()) {
          continue;
        }
        for (String interceptorClass : interceptorClasses) {
          // get the corresponding interceptor metadata for the interceptor class
          InterceptorMetaData interceptorMetaData = allInterceptors.get(interceptorClass);
          // TODO: the interceptor metadata for a interceptor class will only be
          // null, if the metadata isn't fully populated/processed. Let's not thrown
          // any errors and just ignore such cases for now
          if (interceptorMetaData != null) {
            // include this interceptor metadata as applicable for the bean
            beanApplicableInterceptors.add(interceptorMetaData);
          }
        }
      } else if (binding.getEjbName().equals("*")) // binding for default interceptors
      {
        InterceptorClassesMetaData interceptorClasses = null;
        if (binding.isTotalOrdering()) {
          interceptorClasses = binding.getInterceptorOrder();
        } else {
          interceptorClasses = binding.getInterceptorClasses();
        }
        // no interceptor class, so skip to next interceptor binding
        if (interceptorClasses == null || interceptorClasses.isEmpty()) {
          continue;
        }
        // interceptor binding on the bean, is interested
        // in the default interceptors (ejbname = *). So set the flag to include the default
        // interceptors in the list of applicable interceptors
        if (binding.isExcludeDefaultInterceptors() == false) {
          includeDefaultInterceptors = true;
        }
        for (String interceptorClass : interceptorClasses) {
          InterceptorMetaData interceptorMetaData = allInterceptors.get(interceptorClass);
          // TODO: the interceptor metadata for a interceptor class will only be
          // null, if the metadata isn't fully populated/processed. Let's not thrown
          // any errors and just ignore such cases for now
          if (interceptorMetaData != null) {
            // add the interceptor metadata to the set of default interceptors.
            // Whether or not these default interceptors are applicable for
            // the bean being processed, will be decide later
            defaultInterceptors.add(interceptorMetaData);
          }
        }
      }
    }
    // if the default interceptors (ejb name= *) are to be included
    // for this bean.
    // the default interceptors (ejbname = *) will be
    // considered as *not* applicable for a bean, if *all* the interceptor
    // bindings for that bean, have set the exclude-default-interceptors to true
    if (includeDefaultInterceptors) {
      beanApplicableInterceptors.addAll(defaultInterceptors);
    }

    // return the interceptors which are applicable for the bean
    return beanApplicableInterceptors;
  }