@Override
 public void configure(
     final DeploymentPhaseContext context,
     final ComponentConfiguration componentConfiguration,
     final ViewDescription description,
     final ViewConfiguration configuration)
     throws DeploymentUnitProcessingException {
   final EJBComponentDescription ejbComponentDescription =
       (EJBComponentDescription) componentConfiguration.getComponentDescription();
   if (ejbComponentDescription.getTransactionManagementType()
       == TransactionManagementType.CONTAINER) {
     configuration.addViewInterceptor(
         EjbIIOPTransactionInterceptor.FACTORY, InterceptorOrder.View.EJB_IIOP_TRANSACTION);
   }
 }
  @Override
  public void configure(
      DeploymentPhaseContext context,
      ComponentConfiguration componentConfiguration,
      ViewDescription viewDescription,
      ViewConfiguration viewConfiguration)
      throws DeploymentUnitProcessingException {
    if (componentConfiguration.getComponentDescription() instanceof EJBComponentDescription
        == false) {
      throw MESSAGES.invalidEjbComponent(
          componentConfiguration.getComponentName(), componentConfiguration.getComponentClass());
    }
    final EJBComponentDescription ejbComponentDescription =
        (EJBComponentDescription) componentConfiguration.getComponentDescription();
    // if security is not enabled on the EJB, then do *not* add the security related interceptors
    if (!ejbComponentDescription.isSecurityEnabled()) {
      ROOT_LOGGER.debug(
          "Security is *not* enabled on EJB: "
              + ejbComponentDescription.getEJBName()
              + ", no security interceptors will apply");
      return;
    }
    final String viewClassName = viewDescription.getViewClassName();
    // setup the security context interceptor
    viewConfiguration.addViewInterceptor(
        new SecurityContextInterceptorFactory(), InterceptorOrder.View.SECURITY_CONTEXT);

    // now setup the rest of the method specific security interceptor(s)
    final List<Method> viewMethods = viewConfiguration.getProxyFactory().getCachedMethods();
    for (final Method viewMethod : viewMethods) {
      // TODO: proxy factory exposes non-public methods, is this a bug in the no-interface view?
      if (!Modifier.isPublic(viewMethod.getModifiers())) {
        continue;
      }
      if (viewMethod.getDeclaringClass() == WriteReplaceInterface.class) {
        continue;
      }
      final EJBMethodSecurityMetaData ejbMethodSecurityMetaData =
          new EJBMethodSecurityMetaData(componentConfiguration, viewClassName, viewMethod);
      // setup the authorization interceptor
      final Interceptor authorizationInterceptor =
          new AuthorizationInterceptor(ejbMethodSecurityMetaData, viewClassName, viewMethod);
      viewConfiguration.addViewInterceptor(
          viewMethod,
          new ImmediateInterceptorFactory(authorizationInterceptor),
          InterceptorOrder.View.EJB_SECURITY_AUTHORIZATION_INTERCEPTOR);
    }
  }
Пример #3
0
  public void resolve(final DeploymentPhaseContext phaseContext)
      throws DeploymentUnitProcessingException {
    final Set<ViewDescription> componentsForViewName = getViews(phaseContext);
    if (componentsForViewName.isEmpty()) {
      error = "No component found for type '" + typeName + "' with name " + beanName;
      return;
    }
    if (componentsForViewName.size() > 1) {
      error = "More than 1 component found for type '" + typeName + "' and bean name " + beanName;
      return;
    }
    ViewDescription description = componentsForViewName.iterator().next();
    if (description instanceof EJBViewDescription) {
      final EJBViewDescription ejbViewDescription = (EJBViewDescription) description;
      // for remote interfaces we do not want to use a normal binding
      // we need to bind the remote proxy factory into JNDI instead to get the correct behaviour

      if (ejbViewDescription.getMethodIntf() == MethodIntf.REMOTE
          || ejbViewDescription.getMethodIntf() == MethodIntf.HOME) {
        final EJBComponentDescription componentDescription =
            (EJBComponentDescription) description.getComponentDescription();
        final EEModuleDescription moduleDescription = componentDescription.getModuleDescription();
        final String earApplicationName = moduleDescription.getEarApplicationName();
        remoteFactory =
            new RemoteViewManagedReferenceFactory(
                earApplicationName,
                moduleDescription.getModuleName(),
                moduleDescription.getDistinctName(),
                componentDescription.getComponentName(),
                description.getViewClassName(),
                componentDescription.isStateful());
      }
    }
    ServiceName serviceName = description.getServiceName();
    resolvedViewName = serviceName;
  }
  @Override
  public void deploy(final DeploymentPhaseContext phaseContext)
      throws DeploymentUnitProcessingException {

    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!IIOPDeploymentMarker.isIIOPDeployment(deploymentUnit)) {
      return;
    }

    final EEModuleDescription moduleDescription =
        deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    if (!EjbDeploymentMarker.isEjbDeployment(deploymentUnit)) {
      return;
    }

    // a bean-name -> IIOPMetaData map, reflecting the assembly descriptor IIOP configuration.
    Map<String, IIOPMetaData> iiopMetaDataMap = new HashMap<String, IIOPMetaData>();
    final EjbJarMetaData ejbMetaData =
        deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
    if (ejbMetaData != null && ejbMetaData.getAssemblyDescriptor() != null) {
      List<IIOPMetaData> iiopMetaDatas =
          ejbMetaData.getAssemblyDescriptor().getAny(IIOPMetaData.class);
      if (iiopMetaDatas != null && iiopMetaDatas.size() > 0) {
        for (IIOPMetaData metaData : iiopMetaDatas) {
          iiopMetaDataMap.put(metaData.getEjbName(), metaData);
        }
      }
    }

    final DeploymentClassIndex classIndex =
        deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.CLASS_INDEX);
    final DeploymentReflectionIndex deploymentReflectionIndex =
        deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX);
    final Module module =
        deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    if (moduleDescription != null) {
      for (final ComponentDescription componentDescription :
          moduleDescription.getComponentDescriptions()) {
        if (componentDescription instanceof EJBComponentDescription) {
          final EJBComponentDescription ejbComponentDescription =
              (EJBComponentDescription) componentDescription;
          if (ejbComponentDescription.getEjbRemoteView() != null
              && ejbComponentDescription.getEjbHomeView() != null) {
            // check if there is IIOP metadata for the bean - first using the bean name, then the
            // wildcard "*" if needed.
            IIOPMetaData iiopMetaData = iiopMetaDataMap.get(ejbComponentDescription.getEJBName());
            if (iiopMetaData == null) {
              iiopMetaData = iiopMetaDataMap.get(IIOPMetaData.WILDCARD_BEAN_NAME);
            }
            // the bean will be exposed via IIOP if it has IIOP metadata that applies to it or if
            // IIOP access
            // has been enabled by default in the EJB3 subsystem.
            if (iiopMetaData != null || settingsService.isEnabledByDefault()) {
              processEjb(
                  ejbComponentDescription,
                  classIndex,
                  deploymentReflectionIndex,
                  module,
                  phaseContext.getServiceTarget(),
                  iiopMetaData);
            }
          }
        }
      }
    }
  }
  private void processEjb(
      final EJBComponentDescription componentDescription,
      final DeploymentClassIndex classIndex,
      final DeploymentReflectionIndex deploymentReflectionIndex,
      final Module module,
      final ServiceTarget serviceTarget,
      final IIOPMetaData iiopMetaData) {
    componentDescription.setExposedViaIiop(true);

    // Create bean method mappings for container invoker

    final EJBViewDescription remoteView = componentDescription.getEjbRemoteView();
    final ClassIndex remoteClass;
    try {
      remoteClass = classIndex.classIndex(remoteView.getViewClassName());
    } catch (ClassNotFoundException e) {
      throw EjbLogger.ROOT_LOGGER.failedToLoadViewClassForComponent(
          e, componentDescription.getEJBClassName());
    }
    final EJBViewDescription homeView = componentDescription.getEjbHomeView();
    final ClassIndex homeClass;
    try {
      homeClass = classIndex.classIndex(homeView.getViewClassName());
    } catch (ClassNotFoundException e) {
      throw EjbLogger.ROOT_LOGGER.failedToLoadViewClassForComponent(
          e, componentDescription.getEJBClassName());
    }

    componentDescription
        .getEjbHomeView()
        .getConfigurators()
        .add(new IIOPInterceptorViewConfigurator());
    componentDescription
        .getEjbRemoteView()
        .getConfigurators()
        .add(new IIOPInterceptorViewConfigurator());

    final InterfaceAnalysis remoteInterfaceAnalysis;
    try {
      // TODO: change all this to use the deployment reflection index
      remoteInterfaceAnalysis =
          InterfaceAnalysis.getInterfaceAnalysis(remoteClass.getModuleClass());
    } catch (RMIIIOPViolationException e) {
      throw EjbLogger.ROOT_LOGGER.failedToAnalyzeRemoteInterface(
          e, componentDescription.getComponentName());
    }

    final Map<String, SkeletonStrategy> beanMethodMap = new HashMap<String, SkeletonStrategy>();

    final AttributeAnalysis[] remoteAttrs = remoteInterfaceAnalysis.getAttributes();
    for (int i = 0; i < remoteAttrs.length; i++) {
      final OperationAnalysis op = remoteAttrs[i].getAccessorAnalysis();
      if (op != null) {
        EjbLogger.ROOT_LOGGER.debugf(
            "    %s\n                %s", op.getJavaName(), op.getIDLName());
        // translate to the deployment reflection index method
        // TODO: this needs to be fixed so it just returns the correct method
        final Method method = translateMethod(deploymentReflectionIndex, op);

        beanMethodMap.put(op.getIDLName(), new SkeletonStrategy(method));
        final OperationAnalysis setop = remoteAttrs[i].getMutatorAnalysis();
        if (setop != null) {
          EjbLogger.ROOT_LOGGER.debugf(
              "    %s\n                %s", setop.getJavaName(), setop.getIDLName());
          // translate to the deployment reflection index method
          // TODO: this needs to be fixed so it just returns the correct method
          final Method realSetmethod = translateMethod(deploymentReflectionIndex, setop);
          beanMethodMap.put(setop.getIDLName(), new SkeletonStrategy(realSetmethod));
        }
      }
    }

    final OperationAnalysis[] ops = remoteInterfaceAnalysis.getOperations();
    for (int i = 0; i < ops.length; i++) {
      EjbLogger.ROOT_LOGGER.debugf(
          "    %s\n                %s", ops[i].getJavaName(), ops[i].getIDLName());
      beanMethodMap.put(
          ops[i].getIDLName(),
          new SkeletonStrategy(translateMethod(deploymentReflectionIndex, ops[i])));
    }

    // Initialize repository ids of remote interface
    final String[] beanRepositoryIds = remoteInterfaceAnalysis.getAllTypeIds();

    // Create home method mappings for container invoker
    final InterfaceAnalysis homeInterfaceAnalysis;
    try {
      // TODO: change all this to use the deployment reflection index
      homeInterfaceAnalysis = InterfaceAnalysis.getInterfaceAnalysis(homeClass.getModuleClass());
    } catch (RMIIIOPViolationException e) {
      throw EjbLogger.ROOT_LOGGER.failedToAnalyzeRemoteInterface(
          e, componentDescription.getComponentName());
    }

    final Map<String, SkeletonStrategy> homeMethodMap = new HashMap<String, SkeletonStrategy>();

    final AttributeAnalysis[] attrs = homeInterfaceAnalysis.getAttributes();
    for (int i = 0; i < attrs.length; i++) {
      final OperationAnalysis op = attrs[i].getAccessorAnalysis();
      if (op != null) {
        EjbLogger.ROOT_LOGGER.debugf(
            "    %s\n                %s", op.getJavaName(), op.getIDLName());
        homeMethodMap.put(
            op.getIDLName(), new SkeletonStrategy(translateMethod(deploymentReflectionIndex, op)));
        final OperationAnalysis setop = attrs[i].getMutatorAnalysis();
        if (setop != null) {
          EjbLogger.ROOT_LOGGER.debugf(
              "    %s\n                %s", setop.getJavaName(), setop.getIDLName());
          homeMethodMap.put(
              setop.getIDLName(),
              new SkeletonStrategy(translateMethod(deploymentReflectionIndex, setop)));
        }
      }
    }

    final OperationAnalysis[] homeops = homeInterfaceAnalysis.getOperations();
    for (int i = 0; i < homeops.length; i++) {
      EjbLogger.ROOT_LOGGER.debugf(
          "    %s\n                %s", homeops[i].getJavaName(), homeops[i].getIDLName());
      homeMethodMap.put(
          homeops[i].getIDLName(),
          new SkeletonStrategy(translateMethod(deploymentReflectionIndex, homeops[i])));
    }

    // Initialize repository ids of home interface
    final String[] homeRepositoryIds = homeInterfaceAnalysis.getAllTypeIds();

    final EjbIIOPService service =
        new EjbIIOPService(
            beanMethodMap,
            beanRepositoryIds,
            homeMethodMap,
            homeRepositoryIds,
            settingsService.isUseQualifiedName(),
            iiopMetaData,
            module);
    final ServiceBuilder<EjbIIOPService> builder =
        serviceTarget.addService(
            componentDescription.getServiceName().append(EjbIIOPService.SERVICE_NAME), service);
    builder.addDependency(
        componentDescription.getCreateServiceName(),
        EJBComponent.class,
        service.getEjbComponentInjectedValue());
    builder.addDependency(homeView.getServiceName(), ComponentView.class, service.getHomeView());
    builder.addDependency(
        remoteView.getServiceName(), ComponentView.class, service.getRemoteView());
    builder.addDependency(CorbaORBService.SERVICE_NAME, ORB.class, service.getOrb());
    builder.addDependency(POARegistry.SERVICE_NAME, POARegistry.class, service.getPoaRegistry());
    builder.addDependency(
        CorbaPOAService.INTERFACE_REPOSITORY_SERVICE_NAME, POA.class, service.getIrPoa());
    builder.addDependency(
        CorbaNamingService.SERVICE_NAME, NamingContextExt.class, service.getCorbaNamingContext());
    builder.addDependency(
        IORSecConfigMetaDataService.SERVICE_NAME,
        IORSecurityConfigMetaData.class,
        service.getIORSecConfigMetaDataInjectedValue());
    builder.addDependency(
        Services.JBOSS_SERVICE_MODULE_LOADER,
        ServiceModuleLoader.class,
        service.getServiceModuleLoaderInjectedValue());

    // we need the arjunta transaction manager to be up, as it performs some initialization that is
    // required by the orb interceptors
    builder.addDependency(TxnServices.JBOSS_TXN_ARJUNA_TRANSACTION_MANAGER);
    builder.install();
  }