@Override
    protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
        throws OperationFailedException {
      ServiceTarget serviceTarget = context.getServiceTarget();
      RuntimeCapability<Void> runtimeCapability =
          REALM_MAPPER_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue());
      ServiceName realmMapperName = runtimeCapability.getCapabilityServiceName(RealmMapper.class);

      final String pattern = PATTERN.resolveModelAttribute(context, model).asString();

      ModelNode realmMapList = REALM_REALM_MAP.resolveModelAttribute(context, model);
      Set<String> names = realmMapList.keys();
      final Map<String, String> realmRealmMap = new HashMap<String, String>(names.size());
      names.forEach((String s) -> realmRealmMap.put(s, realmMapList.require(s).asString()));

      String delegateRealmMapper = asStringIfDefined(context, DELEGATE_REALM_MAPPER, model);

      final InjectedValue<RealmMapper> delegateRealmMapperInjector =
          new InjectedValue<RealmMapper>();

      TrivialService<RealmMapper> realmMapperService =
          new TrivialService<RealmMapper>(
              () -> {
                RealmMapper delegate = delegateRealmMapperInjector.getOptionalValue();
                Pattern compiledPattern = Pattern.compile(pattern);
                if (delegate == null) {
                  return new MappedRegexRealmMapper(compiledPattern, realmRealmMap);
                } else {
                  return new MappedRegexRealmMapper(compiledPattern, delegate, realmRealmMap);
                }
              });

      ServiceBuilder<RealmMapper> realmMapperBuilder =
          serviceTarget.addService(realmMapperName, realmMapperService);

      if (delegateRealmMapper != null) {
        String delegateCapabilityName =
            RuntimeCapability.buildDynamicCapabilityName(
                REALM_MAPPER_CAPABILITY, delegateRealmMapper);
        ServiceName delegateServiceName =
            context.getCapabilityServiceName(delegateCapabilityName, RealmMapper.class);

        realmMapperBuilder.addDependency(
            delegateServiceName, RealmMapper.class, delegateRealmMapperInjector);
      }

      commonDependencies(realmMapperBuilder).setInitialMode(Mode.LAZY).install();
    }
    @Override
    protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
        throws OperationFailedException {
      ServiceTarget serviceTarget = context.getServiceTarget();
      RuntimeCapability<Void> runtimeCapability =
          SECURITY_REALM_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue());
      ServiceName realmName = runtimeCapability.getCapabilityServiceName(SecurityRealm.class);
      KeyStoreRealmService keyStoreRealmService = new KeyStoreRealmService();

      ServiceBuilder<SecurityRealm> serviceBuilder =
          serviceTarget.addService(realmName, keyStoreRealmService);

      String keyStoreCapabilityName =
          RuntimeCapability.buildDynamicCapabilityName(
              KEYSTORE_CAPABILITY, KEYSTORE.resolveModelAttribute(context, model).asString());
      ServiceName keyStoreServiceName =
          context.getCapabilityServiceName(keyStoreCapabilityName, KeyStore.class);
      KEY_STORE_UTIL.addInjection(
          serviceBuilder, keyStoreRealmService.getKeyStoreInjector(), keyStoreServiceName);
      commonDependencies(serviceBuilder).setInitialMode(Mode.ACTIVE).install();
    }
 /**
  * Gets the service name provided by the given capability for the given service type. This can be
  * used by subclasses to determine the name of a service to remove in {@link
  * org.jboss.as.controller.OperationContext.Stage#RUNTIME} after the capability itself has been
  * removed in {@link org.jboss.as.controller.OperationContext.Stage#MODEL} by {@link
  * #recordCapabilitiesAndRequirements(OperationContext, ModelNode, Resource)}.
  *
  * @param removed the capability. Must be a capability passed to the constructor, and must not be
  *     {@link RuntimeCapability#isDynamicallyNamed() dynamically named}
  * @param serviceType the value type of the service for which a service name is wanted
  * @return the service name. Will not be {@code null}
  * @throws IllegalArgumentException if {@code serviceType} is {@code null } or the capability does
  *     not provide a service of type {@code serviceType}
  */
 protected final ServiceName getCapabilityRemovedServiceName(
     RuntimeCapability removed, Class<?> serviceType) {
   assert capabilities.contains(removed);
   assert !removed.isDynamicallyNamed();
   return removed.getCapabilityServiceName(serviceType);
 }