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;
  }