void launchServices(
      final OperationContext context,
      final PathAddress pathAddress,
      final ModelNode model,
      final ServiceVerificationHandler verificationHandler,
      final List<ServiceController<?>> newControllers)
      throws OperationFailedException {
    Handler newHandler = new Handler();

    newHandler.setClazz(
        HandlerResourceDefinition.CLASS.resolveModelAttribute(context, model).asString());

    ModelNode handler = Resource.Tools.readModel(context.readResourceFromRoot(pathAddress));

    if (handler.hasDefined(COMMON_HANDLER_PARAMETER.getName())) {
      for (ModelNode handlerParameter : handler.get(COMMON_HANDLER_PARAMETER.getName()).asList()) {
        Property property = handlerParameter.asProperty();
        String paramName = property.getName();
        String paramValue =
            HandlerParameterResourceDefinition.VALUE
                .resolveModelAttribute(context, property.getValue())
                .asString();

        KeyValueType kv = new KeyValueType();

        kv.setKey(paramName);
        kv.setValue(paramValue);

        newHandler.add(kv);
      }
    }

    SAMLHandlerService service = new SAMLHandlerService(newHandler);
    PathElement providerAlias = pathAddress.subAddress(0, pathAddress.size() - 1).getLastElement();

    ServiceTarget serviceTarget = context.getServiceTarget();
    ServiceBuilder<SAMLHandlerService> serviceBuilder =
        serviceTarget.addService(
            createServiceName(providerAlias.getValue(), newHandler.getClazz()), service);
    ServiceName serviceName;

    if (providerAlias.getKey().equals(IDENTITY_PROVIDER.getName())) {
      serviceName = IdentityProviderService.createServiceName(providerAlias.getValue());
    } else {
      serviceName = ServiceProviderService.createServiceName(providerAlias.getValue());
    }

    serviceBuilder.addDependency(
        serviceName, EntityProviderService.class, service.getEntityProviderService());

    ServiceController<SAMLHandlerService> controller =
        serviceBuilder
            .addListener(verificationHandler)
            .setInitialMode(ServiceController.Mode.PASSIVE)
            .install();

    if (newControllers != null) {
      newControllers.add(controller);
    }
  }
  private static DescribedOp getDescribedOp(
      OperationContext context, String operationName, ModelNode operation, boolean lenient)
      throws OperationFailedException {
    DescribedOp result = null;
    OperationEntry operationEntry;
    // First try to get the current resource registration to give authz a chance to reject this
    // request
    ImmutableManagementResourceRegistration registry = context.getResourceRegistration();
    if (registry != null) {
      operationEntry = registry.getOperationEntry(PathAddress.EMPTY_ADDRESS, operationName);
    } else {
      // We know the user is authorized to read this address.
      // There's no MRR at that address, but see if the MRR tree can resolve an operation entry
      // (e.g. an inherited one)
      operationEntry =
          context
              .getRootResourceRegistration()
              .getOperationEntry(context.getCurrentAddress(), operationName);
    }

    if (operationEntry != null) {
      Locale locale = GlobalOperationHandlers.getLocale(context, operation);
      result = new DescribedOp(operationEntry, locale);
    } else if (lenient) {
      // For wildcard elements, check specific registrations where the same OSH is used
      // for all such registrations
      PathAddress address = context.getCurrentAddress();
      if (address.size() > 0) {
        PathElement pe = address.getLastElement();
        if (pe.isWildcard()) {
          ImmutableManagementResourceRegistration rootRegistration =
              context.getRootResourceRegistration();
          String type = pe.getKey();
          PathAddress parent = address.subAddress(0, address.size() - 1);
          Set<PathElement> children = rootRegistration.getChildAddresses(parent);
          if (children != null) {
            Locale locale = GlobalOperationHandlers.getLocale(context, operation);
            DescribedOp found = null;
            for (PathElement child : children) {
              if (type.equals(child.getKey())) {
                OperationEntry oe =
                    rootRegistration.getOperationEntry(parent.append(child), operationName);
                DescribedOp describedOp = oe == null ? null : new DescribedOp(oe, locale);
                if (describedOp == null || (found != null && !found.equals(describedOp))) {
                  // Not all children have the same handler; give up
                  found = null;
                  break;
                }
                // We have a candidate OSH
                found = describedOp;
              }
            }
            result = found;
          }
        }
      }
    }
    return result;
  }
 void println(String msg) {
   if (!outputPath) {
     outputPath = true;
     PathAddress relative = pathAddress.subAddress(rootAddress.size());
     System.out.println(
         "--- Problems for relative address to root " + formatAddressOneLine(relative) + ":");
   }
   System.out.println(msg);
 }
Beispiel #4
0
  public static PathAddress getParentAddressByKey(PathAddress address, String parentKey) {
    for (int i = address.size() - 1; i >= 0; i--) {
      PathElement pe = address.getElement(i);
      if (parentKey.equals(pe.getKey())) {
        return address.subAddress(0, i + 1);
      }
    }

    return null;
  }
Beispiel #5
0
  @Override
  protected void performRuntime(
      OperationContext context,
      ModelNode operation,
      ModelNode model,
      ServiceVerificationHandler verificationHandler,
      List<ServiceController<?>> newControllers)
      throws OperationFailedException {
    final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
    final PathAddress parent = address.subAddress(0, address.size() - 1);
    String name = address.getLastElement().getValue();
    String bindingRef =
        ListenerResourceDefinition.SOCKET_BINDING.resolveModelAttribute(context, model).asString();
    String workerName =
        ListenerResourceDefinition.WORKER.resolveModelAttribute(context, model).asString();
    String bufferPoolName =
        ListenerResourceDefinition.BUFFER_POOL.resolveModelAttribute(context, model).asString();
    boolean enabled =
        ListenerResourceDefinition.ENABLED.resolveModelAttribute(context, model).asBoolean();
    OptionMap listenerOptions =
        OptionList.resolveOptions(context, model, ListenerResourceDefinition.LISTENER_OPTIONS);
    OptionMap socketOptions =
        OptionList.resolveOptions(context, model, ListenerResourceDefinition.SOCKET_OPTIONS);
    String serverName = parent.getLastElement().getValue();
    final ServiceName listenerServiceName = UndertowService.listenerName(name);
    final ListenerService<? extends ListenerService> service =
        createService(name, serverName, context, model, listenerOptions, socketOptions);
    final ServiceBuilder<? extends ListenerService> serviceBuilder =
        context.getServiceTarget().addService(listenerServiceName, service);
    serviceBuilder
        .addDependency(IOServices.WORKER.append(workerName), XnioWorker.class, service.getWorker())
        .addDependency(
            SocketBinding.JBOSS_BINDING_NAME.append(bindingRef),
            SocketBinding.class,
            service.getBinding())
        .addDependency(
            IOServices.BUFFER_POOL.append(bufferPoolName), Pool.class, service.getBufferPool())
        .addDependency(
            UndertowService.SERVER.append(serverName), Server.class, service.getServerService());

    configureAdditionalDependencies(context, serviceBuilder, model, service);
    serviceBuilder.setInitialMode(
        enabled ? ServiceController.Mode.ACTIVE : ServiceController.Mode.NEVER);

    serviceBuilder.addListener(verificationHandler);
    final ServiceController<? extends ListenerService> serviceController = serviceBuilder.install();
    if (newControllers != null) {
      newControllers.add(serviceController);
    }
  }
  static void launchServices(
      OperationContext context,
      ModelNode operation,
      ModelNode model,
      ServiceVerificationHandler verificationHandler,
      List<ServiceController<?>> newControllers)
      throws OperationFailedException {
    PathAddress pathAddress =
        PathAddress.pathAddress(operation.get(ModelDescriptionConstants.ADDRESS));
    String federationAlias =
        pathAddress.subAddress(0, pathAddress.size() - 1).getLastElement().getValue();

    ModelNode relativeToNode =
        KeyStoreProviderResourceDefinition.RELATIVE_TO.resolveModelAttribute(context, model);
    String relativeTo = null;

    if (relativeToNode.isDefined()) {
      relativeTo = relativeToNode.asString();
    }

    String file =
        KeyStoreProviderResourceDefinition.FILE.resolveModelAttribute(context, model).asString();

    KeyStoreProviderService service =
        new KeyStoreProviderService(toKeyProviderType(context, model), file, relativeTo);
    ServiceBuilder<KeyStoreProviderService> serviceBuilder =
        context
            .getServiceTarget()
            .addService(KeyStoreProviderService.createServiceName(federationAlias), service);

    serviceBuilder.addDependency(
        FederationService.createServiceName(federationAlias),
        FederationService.class,
        service.getFederationService());

    serviceBuilder.addDependency(
        PathManagerService.SERVICE_NAME, PathManager.class, service.getPathManager());

    if (verificationHandler != null) {
      serviceBuilder.addListener(verificationHandler);
    }

    ServiceController<KeyStoreProviderService> controller =
        serviceBuilder.setInitialMode(ServiceController.Mode.PASSIVE).install();

    if (newControllers != null) {
      newControllers.add(controller);
    }
  }
 private void checkNoOtherProtocol(OperationContext context, ModelNode operation)
     throws OperationFailedException {
   PathAddress opAddr = PathAddress.pathAddress(operation.require(OP_ADDR));
   PathAddress addr = opAddr.subAddress(0, opAddr.size() - 1);
   Resource resource = context.readResourceFromRoot(addr);
   Set<ResourceEntry> existing = resource.getChildren(ModelDescriptionConstants.PROTOCOL);
   if (existing.size() > 1) {
     for (ResourceEntry entry : existing) {
       PathElement mine = addr.getLastElement();
       if (!entry.getPathElement().equals(mine)) {
         throw DomainManagementLogger.ROOT_LOGGER.sysLogProtocolAlreadyConfigured(
             addr.append(mine));
       }
     }
   }
 }
 /**
  * Creates an operations that targets this handler.
  *
  * @param operationToValidate the operation that this handler will validate
  * @return the validation operation
  */
 static ModelNode createOperation(final ModelNode operationToValidate) {
   PathAddress pa =
       PathAddress.pathAddress(operationToValidate.require(ModelDescriptionConstants.OP_ADDR));
   PathAddress realmPA = null;
   for (int i = pa.size() - 1; i > 0; i--) {
     PathElement pe = pa.getElement(i);
     if (ModelDescriptionConstants.SECURITY_REALM.equals(pe.getKey())) {
       realmPA = pa.subAddress(0, i + 1);
       break;
     }
   }
   assert realmPA != null
       : "operationToValidate did not have an address that included a "
           + ModelDescriptionConstants.SECURITY_REALM;
   return Util.getEmptyOperation("validate-authorization", realmPA.toModelNode());
 }
 static String findPoolName(OperationContext context, String jndiName)
     throws OperationFailedException {
   PathAddress address = context.getCurrentAddress();
   PathAddress rootAddress = address.subAddress(0, address.size() - 4);
   PathAddress subsystemAddress =
       rootAddress.append(
           PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, "datasources"));
   Resource subsystem = context.readResourceFromRoot(subsystemAddress);
   for (String type : Arrays.asList("data-source", "xa-data-source")) {
     if (subsystem.hasChildren(type)) {
       for (Resource.ResourceEntry entry : subsystem.getChildren(type)) {
         ModelNode model = entry.getModel();
         if (model.get("jndi-name").asString().equals(jndiName)) {
           return entry.getName();
         }
       }
     }
   }
   throw InfinispanLogger.ROOT_LOGGER.dataSourceJndiNameNotFound(jndiName);
 }
    @Override
    protected void executeRuntimeStep(OperationContext context, ModelNode operation)
        throws OperationFailedException {

      final PathAddress address =
          PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));

      final Resource web =
          context.readResourceFromRoot(address.subAddress(0, address.size()), false);
      final ModelNode subModel = web.getModel();

      final String host = VIRTUAL_HOST.resolveModelAttribute(context, subModel).asString();
      final String path = CONTEXT_ROOT.resolveModelAttribute(context, subModel).asString();
      final String server = SERVER.resolveModelAttribute(context, subModel).asString();

      final ServiceController<?> controller =
          context
              .getServiceRegistry(false)
              .getService(UndertowService.deploymentServiceName(server, host, path));

      SessionStat stat =
          SessionStat.getStat(operation.require(ModelDescriptionConstants.NAME).asString());

      if (stat == null) {
        context
            .getFailureDescription()
            .set(
                UndertowMessages.MESSAGES.unknownMetric(
                    operation.require(ModelDescriptionConstants.NAME).asString()));
      } else {
        context.getResult().set("<not implemented>");
        /*final Context webContext = Context.class.cast(controller.getValue());
        ManagerBase sm = (ManagerBase) webContext.getManager();
        ModelNode result = new ModelNode();
        switch (stat) {
            case ACTIVE_SESSIONS:
                result.set(sm.getActiveSessions());
                break;
            case EXPIRED_SESSIONS:
                result.set(sm.getExpiredSessions());
                break;
            case MAX_ACTIVE_SESSIONS:
                result.set(sm.getMaxActive());
                break;
            case SESSIONS_CREATED:
                result.set(sm.getSessionCounter());
                break;
            case DUPLICATED_SESSION_IDS:
                result.set(sm.getDuplicates());
                break;
            case SESSION_AVG_ALIVE_TIME:
                result.set(sm.getSessionAverageAliveTime());
                break;
            case SESSION_MAX_ALIVE_TIME:
                result.set(sm.getSessionMaxAliveTime());
                break;
            case REJECTED_SESSIONS:
                result.set(sm.getRejectedSessions());
                break;
            default:
                throw new IllegalStateException(WebMessages.MESSAGES.unknownMetric(stat));
        }
        context.getResult().set(result);*/
      }

      context.stepCompleted();
    }
Beispiel #11
0
 protected PathAddress getCacheContainerAddressFromOperation(ModelNode operation) {
   final PathAddress cacheAddress = getCacheAddressFromOperation(operation);
   final PathAddress containerAddress = cacheAddress.subAddress(0, cacheAddress.size() - 1);
   return containerAddress;
 }
Beispiel #12
0
  static void launchServices(
      final OperationContext context,
      final PathAddress pathAddress,
      final ModelNode model,
      final ServiceVerificationHandler verificationHandler,
      final List<ServiceController<?>> newControllers)
      throws OperationFailedException {
    Handler newHandler = new Handler();

    ModelNode classNameNode = HandlerResourceDefinition.CLASS.resolveModelAttribute(context, model);
    ModelNode codeNode = HandlerResourceDefinition.CODE.resolveModelAttribute(context, model);
    String typeName;

    if (classNameNode.isDefined()) {
      typeName = classNameNode.asString();
    } else if (codeNode.isDefined()) {
      typeName = HandlerTypeEnum.forType(codeNode.asString());
    } else {
      throw PicketLinkLogger.ROOT_LOGGER.federationHandlerTypeNotProvided();
    }

    newHandler.setClazz(typeName);

    ModelNode handler = Resource.Tools.readModel(context.readResourceFromRoot(pathAddress));

    if (handler.hasDefined(COMMON_HANDLER_PARAMETER.getName())) {
      for (Property handlerParameter :
          handler.get(COMMON_HANDLER_PARAMETER.getName()).asPropertyList()) {
        String paramName = handlerParameter.getName();
        String paramValue =
            HandlerParameterResourceDefinition.VALUE
                .resolveModelAttribute(context, handlerParameter.getValue())
                .asString();

        KeyValueType kv = new KeyValueType();

        kv.setKey(paramName);
        kv.setValue(paramValue);

        newHandler.add(kv);
      }
    }

    SAMLHandlerService service = new SAMLHandlerService(newHandler);
    PathElement providerAlias = pathAddress.subAddress(0, pathAddress.size() - 1).getLastElement();

    ServiceTarget serviceTarget = context.getServiceTarget();
    ServiceBuilder<SAMLHandlerService> serviceBuilder =
        serviceTarget.addService(
            createServiceName(providerAlias.getValue(), newHandler.getClazz()), service);
    ServiceName serviceName;

    if (providerAlias.getKey().equals(IDENTITY_PROVIDER.getName())) {
      serviceName = IdentityProviderService.createServiceName(providerAlias.getValue());
    } else {
      serviceName = ServiceProviderService.createServiceName(providerAlias.getValue());
    }

    serviceBuilder.addDependency(
        serviceName, EntityProviderService.class, service.getEntityProviderService());

    if (verificationHandler != null) {
      serviceBuilder.addListener(verificationHandler);
    }

    ServiceController<SAMLHandlerService> controller =
        serviceBuilder.setInitialMode(ServiceController.Mode.PASSIVE).install();

    if (newControllers != null) {
      newControllers.add(controller);
    }

    if (!context.isBooting()) {
      // a reload is required to get the chain properly updated with the domain model state.
      context.reloadRequired();
    }
  }
    @Override
    public void execute(OperationContext context, ModelNode operation)
        throws OperationFailedException {
      PathAddress address = context.getCurrentAddress();
      String clsName = address.getLastElement().getValue();
      PathAddress parentAddress = address.getParent();
      final ModelNode subModel =
          context
              .readResourceFromRoot(
                  parentAddress
                      .subAddress(0, parentAddress.size() - 1)
                      .append(SUBSYSTEM, UndertowExtension.SUBSYSTEM_NAME),
                  false)
              .getModel();
      final String host = VIRTUAL_HOST.resolveModelAttribute(context, subModel).asString();
      final String contextPath = CONTEXT_ROOT.resolveModelAttribute(context, subModel).asString();
      final String server = SERVER.resolveModelAttribute(context, subModel).asString();

      final ServiceController<?> controller =
          context
              .getServiceRegistry(false)
              .getService(UndertowService.deploymentServiceName(server, host, contextPath));
      final UndertowDeploymentService deploymentService =
          (UndertowDeploymentService) controller.getService();
      Servlet resteasyServlet = null;
      Handle handle = deploymentService.getDeployment().getThreadSetupAction().setup(null);
      try {
        for (Map.Entry<String, ServletHandler> servletHandler :
            deploymentService.getDeployment().getServlets().getServletHandlers().entrySet()) {
          if (HttpServletDispatcher.class.isAssignableFrom(
              servletHandler.getValue().getManagedServlet().getServletInfo().getServletClass())) {
            resteasyServlet =
                (Servlet) servletHandler.getValue().getManagedServlet().getServlet().getInstance();
            break;
          }
        }
        if (resteasyServlet != null) {
          final Collection<String> servletMappings =
              resteasyServlet
                  .getServletConfig()
                  .getServletContext()
                  .getServletRegistration(resteasyServlet.getServletConfig().getServletName())
                  .getMappings();
          final ResourceMethodRegistry registry =
              (ResourceMethodRegistry)
                  ((HttpServletDispatcher) resteasyServlet).getDispatcher().getRegistry();
          context.addStep(
              new OperationStepHandler() {
                @Override
                public void execute(OperationContext context, ModelNode operation)
                    throws OperationFailedException {
                  final ModelNode response = new ModelNode();
                  List<JaxrsResourceMethodDescription> resMethodInvokers = new ArrayList<>();
                  List<JaxrsResourceLocatorDescription> resLocatorInvokers = new ArrayList<>();
                  for (Map.Entry<String, List<ResourceInvoker>> resource :
                      registry.getBounded().entrySet()) {
                    String mapping = resource.getKey();
                    List<ResourceInvoker> resouceInvokers = resource.getValue();
                    for (ResourceInvoker resourceInvoker : resouceInvokers) {
                      if (ResourceMethodInvoker.class.isAssignableFrom(
                          resourceInvoker.getClass())) {
                        ResourceMethodInvoker methodInvoker =
                            (ResourceMethodInvoker) resourceInvoker;
                        if (methodInvoker.getResourceClass().getCanonicalName().equals(clsName)) {
                          JaxrsResourceMethodDescription resMethodDesc =
                              resMethodDescription(
                                  methodInvoker, contextPath, mapping, servletMappings);
                          resMethodInvokers.add(resMethodDesc);
                        }
                      } else if (ResourceLocatorInvoker.class.isAssignableFrom(
                          resourceInvoker.getClass())) {
                        ResourceLocatorInvoker locatorInvoker =
                            (ResourceLocatorInvoker) resourceInvoker;
                        if (clsName.equals(
                            locatorInvoker.getMethod().getDeclaringClass().getCanonicalName())) {
                          ResourceClass resClass =
                              ResourceBuilder.locatorFromAnnotations(
                                  locatorInvoker.getMethod().getReturnType());
                          JaxrsResourceLocatorDescription resLocatorDesc =
                              resLocatorDescription(
                                  resClass,
                                  contextPath,
                                  mapping,
                                  servletMappings,
                                  new ArrayList<Class<?>>());
                          resLocatorInvokers.add(resLocatorDesc);
                        }
                      }
                    }
                  }
                  Collections.sort(resMethodInvokers);
                  Collections.sort(resLocatorInvokers);
                  handleAttribute(
                      clsName, resMethodInvokers, resLocatorInvokers, servletMappings, response);
                  context.getResult().set(response);
                }
              },
              OperationContext.Stage.RUNTIME);
        }
      } catch (ServletException ex) {
        throw new RuntimeException(ex);
      } finally {
        handle.tearDown();
      }
    }
Beispiel #14
0
  @Override
  protected void performRuntime(
      OperationContext context,
      ModelNode operation,
      ModelNode model,
      ServiceVerificationHandler verificationHandler,
      List<ServiceController<?>> newControllers)
      throws OperationFailedException {
    // Because we use child resources in a read-only manner to configure the cache, replace the
    // local model with the full model
    model = Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS));

    // Configuration to hold the operation data
    ConfigurationBuilder builder =
        new ConfigurationBuilder().read(getDefaultConfiguration(this.mode));

    // create a list for dependencies which may need to be added during processing
    List<Dependency<?>> dependencies = new LinkedList<Dependency<?>>();

    // process cache configuration ModelNode describing overrides to defaults
    processModelNode(model, builder, dependencies);

    // get all required addresses, names and service names
    PathAddress cacheAddress = PathAddress.pathAddress(operation.get(OP_ADDR));
    PathAddress containerAddress = cacheAddress.subAddress(0, cacheAddress.size() - 1);
    String cacheName = cacheAddress.getLastElement().getValue();
    String containerName = containerAddress.getLastElement().getValue();
    ServiceName containerServiceName = EmbeddedCacheManagerService.getServiceName(containerName);
    ServiceName cacheServiceName = containerServiceName.append(cacheName);
    ServiceName cacheConfigurationServiceName =
        CacheConfigurationService.getServiceName(containerName, cacheName);

    // get container Model
    Resource rootResource = context.getRootResource();
    ModelNode container = rootResource.navigate(containerAddress).getModel();

    // get default cache of the container and start mode
    String defaultCache = container.require(ModelKeys.DEFAULT_CACHE).asString();
    ServiceController.Mode initialMode =
        model.hasDefined(ModelKeys.START)
            ? StartMode.valueOf(model.get(ModelKeys.START).asString()).getMode()
            : ServiceController.Mode.ON_DEMAND;

    // install the cache configuration service (configures a cache)
    ServiceTarget target = context.getServiceTarget();
    InjectedValue<EmbeddedCacheManager> containerInjection =
        new InjectedValue<EmbeddedCacheManager>();
    CacheConfigurationDependencies cacheConfigurationDependencies =
        new CacheConfigurationDependencies(containerInjection);
    CacheConfigurationService cacheConfigurationService =
        new CacheConfigurationService(cacheName, builder, cacheConfigurationDependencies);

    ServiceBuilder<Configuration> configBuilder =
        target
            .addService(cacheConfigurationServiceName, cacheConfigurationService)
            .addDependency(containerServiceName, EmbeddedCacheManager.class, containerInjection)
            .setInitialMode(ServiceController.Mode.PASSIVE);

    Configuration config = builder.build();
    if (config.invocationBatching().enabled()) {
      cacheConfigurationDependencies
          .getTransactionManagerInjector()
          .inject(BatchModeTransactionManager.getInstance());
    } else if (config.transaction().transactionMode()
        == org.infinispan.transaction.TransactionMode.TRANSACTIONAL) {
      configBuilder.addDependency(
          TxnServices.JBOSS_TXN_TRANSACTION_MANAGER,
          TransactionManager.class,
          cacheConfigurationDependencies.getTransactionManagerInjector());
      if (config.transaction().useSynchronization()) {
        configBuilder.addDependency(
            TxnServices.JBOSS_TXN_SYNCHRONIZATION_REGISTRY,
            TransactionSynchronizationRegistry.class,
            cacheConfigurationDependencies.getTransactionSynchronizationRegistryInjector());
      }
    }

    // add in any additional dependencies resulting from ModelNode parsing
    for (Dependency<?> dependency : dependencies) {
      this.addDependency(configBuilder, dependency);
    }
    // add an alias for the default cache
    if (cacheName.equals(defaultCache)) {
      configBuilder.addAliases(CacheConfigurationService.getServiceName(containerName, null));
    }
    newControllers.add(configBuilder.install());
    log.debugf(
        "Cache configuration service for %s installed for container %s", cacheName, containerName);

    // now install the corresponding cache service (starts a configured cache)
    CacheDependencies cacheDependencies = new CacheDependencies(containerInjection);
    CacheService<Object, Object> cacheService =
        new CacheService<Object, Object>(cacheName, cacheDependencies);

    ServiceBuilder<Cache<Object, Object>> cacheBuilder =
        target
            .addService(cacheServiceName, cacheService)
            .addDependency(cacheConfigurationServiceName)
            .setInitialMode(initialMode);

    if (config.transaction().recovery().enabled()) {
      cacheBuilder.addDependency(
          TxnServices.JBOSS_TXN_ARJUNA_RECOVERY_MANAGER,
          XAResourceRecoveryRegistry.class,
          cacheDependencies.getRecoveryRegistryInjector());
    }

    // add an alias for the default cache
    if (cacheName.equals(defaultCache)) {
      cacheBuilder.addAliases(CacheService.getServiceName(containerName, null));
    }

    if (initialMode == ServiceController.Mode.ACTIVE) {
      cacheBuilder.addListener(verificationHandler);
    }

    newControllers.add(cacheBuilder.install());

    String jndiName =
        (model.hasDefined(ModelKeys.JNDI_NAME)
                ? InfinispanJndiName.toJndiName(model.get(ModelKeys.JNDI_NAME).asString())
                : InfinispanJndiName.defaultCacheJndiName(containerName, cacheName))
            .getAbsoluteName();
    ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);

    BinderService binder = new BinderService(bindInfo.getBindName());
    @SuppressWarnings("rawtypes")
    ServiceBuilder<ManagedReferenceFactory> binderBuilder =
        target
            .addService(bindInfo.getBinderServiceName(), binder)
            .addAliases(ContextNames.JAVA_CONTEXT_SERVICE_NAME.append(jndiName))
            .addDependency(
                cacheServiceName,
                Cache.class,
                new ManagedReferenceInjector<Cache>(binder.getManagedObjectInjector()))
            .addDependency(
                bindInfo.getParentContextServiceName(),
                ServiceBasedNamingStore.class,
                binder.getNamingStoreInjector())
            .setInitialMode(ServiceController.Mode.PASSIVE);
    newControllers.add(binderBuilder.install());

    log.debugf("Cache service for cache %s installed for container %s", cacheName, containerName);
  }