private IdentityStoreConfigurationBuilder<?, ?> configureFileIdentityStore(
      OperationContext context,
      ServiceBuilder<PartitionManager> serviceBuilder,
      ServiceVerificationHandler verificationHandler,
      List<ServiceController<?>> newControllers,
      PartitionManagerService partitionManagerService,
      ModelNode resource,
      String configurationName,
      final NamedIdentityConfigurationBuilder builder)
      throws OperationFailedException {
    FileStoreConfigurationBuilder fileStoreBuilder = builder.stores().file();
    String workingDir =
        FileStoreResourceDefinition.WORKING_DIR.resolveModelAttribute(context, resource).asString();
    String relativeTo =
        FileStoreResourceDefinition.RELATIVE_TO.resolveModelAttribute(context, resource).asString();
    ModelNode alwaysCreateFiles =
        FileStoreResourceDefinition.ALWAYS_CREATE_FILE.resolveModelAttribute(context, resource);
    ModelNode asyncWrite =
        FileStoreResourceDefinition.ASYNC_WRITE.resolveModelAttribute(context, resource);
    ModelNode asyncWriteThreadPool =
        FileStoreResourceDefinition.ASYNC_WRITE_THREAD_POOL.resolveModelAttribute(
            context, resource);

    fileStoreBuilder.preserveState(!alwaysCreateFiles.asBoolean());
    fileStoreBuilder.asyncWrite(asyncWrite.asBoolean());
    fileStoreBuilder.asyncWriteThreadPool(asyncWriteThreadPool.asInt());

    if (serviceBuilder != null) {
      FileIdentityStoreService storeService =
          new FileIdentityStoreService(fileStoreBuilder, workingDir, relativeTo);
      ServiceName storeServiceName =
          PartitionManagerService.createIdentityStoreServiceName(
              partitionManagerService.getName(),
              configurationName,
              ModelElement.FILE_STORE.getName());
      ServiceBuilder<FileIdentityStoreService> storeServiceBuilder =
          context.getServiceTarget().addService(storeServiceName, storeService);

      storeServiceBuilder.addDependency(
          PathManagerService.SERVICE_NAME, PathManager.class, storeService.getPathManager());

      serviceBuilder.addDependency(storeServiceName);

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

      ServiceController<FileIdentityStoreService> controller =
          storeServiceBuilder.setInitialMode(Mode.PASSIVE).install();

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

    return fileStoreBuilder;
  }
  private JPAStoreSubsystemConfigurationBuilder configureJPAIdentityStore(
      OperationContext context,
      ServiceBuilder<PartitionManager> serviceBuilder,
      ServiceVerificationHandler verificationHandler,
      List<ServiceController<?>> newControllers,
      PartitionManagerService partitionManagerService,
      final ModelNode identityStore,
      String configurationName,
      final NamedIdentityConfigurationBuilder builder)
      throws OperationFailedException {
    JPAStoreSubsystemConfigurationBuilder storeConfig =
        builder
            .stores()
            .add(JPAStoreSubsystemConfiguration.class, JPAStoreSubsystemConfigurationBuilder.class);

    ModelNode jpaDataSourceNode =
        JPAStoreResourceDefinition.DATA_SOURCE.resolveModelAttribute(context, identityStore);
    ModelNode jpaEntityModule =
        JPAStoreResourceDefinition.ENTITY_MODULE.resolveModelAttribute(context, identityStore);
    ModelNode jpaEntityModuleUnitName =
        JPAStoreResourceDefinition.ENTITY_MODULE_UNIT_NAME.resolveModelAttribute(
            context, identityStore);
    ModelNode jpaEntityManagerFactoryNode =
        JPAStoreResourceDefinition.ENTITY_MANAGER_FACTORY.resolveModelAttribute(
            context, identityStore);

    if (jpaEntityModule.isDefined()) {
      storeConfig.entityModule(jpaEntityModule.asString());
    }

    storeConfig.entityModuleUnitName(jpaEntityModuleUnitName.asString());

    if (serviceBuilder != null) {
      JPAIdentityStoreService storeService = new JPAIdentityStoreService(storeConfig);
      ServiceName storeServiceName =
          PartitionManagerService.createIdentityStoreServiceName(
              partitionManagerService.getName(),
              configurationName,
              ModelElement.JPA_STORE.getName());
      ServiceBuilder<JPAIdentityStoreService> storeServiceBuilder =
          context.getServiceTarget().addService(storeServiceName, storeService);

      storeServiceBuilder.addDependency(
          TxnServices.JBOSS_TXN_TRANSACTION_MANAGER,
          TransactionManager.class,
          storeService.getTransactionManager());

      storeServiceBuilder.addDependency(
          TxnServices.JBOSS_TXN_SYNCHRONIZATION_REGISTRY,
          TransactionSynchronizationRegistry.class,
          storeService.getTransactionSynchronizationRegistry());

      if (jpaDataSourceNode.isDefined()) {
        storeConfig.dataSourceJndiUrl(toJndiName(jpaDataSourceNode.asString()));
        storeServiceBuilder.addDependency(
            ContextNames.JAVA_CONTEXT_SERVICE_NAME.append(
                toJndiName(jpaDataSourceNode.asString()).split("/")));
      }

      if (jpaEntityManagerFactoryNode.isDefined()) {
        storeConfig.entityManagerFactoryJndiName(jpaEntityManagerFactoryNode.asString());
        storeServiceBuilder.addDependency(
            ContextNames.JAVA_CONTEXT_SERVICE_NAME.append(
                jpaEntityManagerFactoryNode.asString().split("/")),
            ValueManagedReferenceFactory.class,
            new InjectedValue<ValueManagedReferenceFactory>());
      }

      serviceBuilder.addDependency(storeServiceName);

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

      ServiceController<JPAIdentityStoreService> controller =
          storeServiceBuilder.setInitialMode(Mode.PASSIVE).install();

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

    return storeConfig;
  }
  public void createPartitionManagerService(
      final OperationContext context,
      String partitionManagerName,
      final ModelNode partitionManager,
      final ServiceVerificationHandler verificationHandler,
      final List<ServiceController<?>> newControllers,
      boolean onlyValidate)
      throws OperationFailedException {
    String jndiName =
        PartitionManagerResourceDefinition.IDENTITY_MANAGEMENT_JNDI_URL
            .resolveModelAttribute(context, partitionManager)
            .asString();
    IdentityConfigurationBuilder builder = new IdentityConfigurationBuilder();
    PartitionManagerService partitionManagerService =
        new PartitionManagerService(partitionManagerName, jndiName, builder);
    ServiceBuilder<PartitionManager> serviceBuilder = null;

    if (!onlyValidate) {
      serviceBuilder =
          context
              .getServiceTarget()
              .addService(
                  PartitionManagerService.createServiceName(partitionManagerName),
                  partitionManagerService);
    }

    ModelNode identityConfigurationNode = partitionManager.get(IDENTITY_CONFIGURATION.getName());

    if (!identityConfigurationNode.isDefined()) {
      throw ROOT_LOGGER.idmNoIdentityConfigurationProvided();
    }

    for (Property identityConfiguration : identityConfigurationNode.asPropertyList()) {
      String configurationName = identityConfiguration.getName();
      NamedIdentityConfigurationBuilder namedIdentityConfigurationBuilder =
          builder.named(configurationName);

      if (!identityConfiguration.getValue().isDefined()) {
        throw ROOT_LOGGER.idmNoIdentityStoreProvided(configurationName);
      }

      List<ModelNode> identityStores = identityConfiguration.getValue().asList();

      for (ModelNode store : identityStores) {
        configureIdentityStore(
            context,
            serviceBuilder,
            verificationHandler,
            newControllers,
            partitionManagerService,
            configurationName,
            namedIdentityConfigurationBuilder,
            store);
      }
    }

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

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

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