Example #1
0
 /**
  * Access the RunAsIdentity associated with the given servlet
  *
  * @param ejbName - the servlet-name from the web.xml
  * @return RunAsIdentity for the servet if one exists, null otherwise
  */
 public RunAsIdentityMetaData getRunAsIdentity(String ejbName) {
   RunAsIdentityMetaData identity = runAsIdentity.get(ejbName);
   if (identity == null) {
     JBossEnterpriseBeanMetaData ejb = this.getEnterpriseBean(ejbName);
     if (ejb != null) {
       // Check for a ejb-jar.xml run-as only specification
       synchronized (runAsIdentity) {
         SecurityIdentityMetaData si = ejb.getSecurityIdentity();
         if (si != null) {
           RunAsMetaData runAs = si.getRunAs();
           if (runAs != null) {
             String roleName = runAs.getRoleName();
             identity = new RunAsIdentityMetaData(roleName, null);
             runAsIdentity.put(ejbName, identity);
           }
         }
       }
     }
   }
   return identity;
 }
Example #2
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();
  }
Example #3
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;
  }