Ejemplo n.º 1
0
 private static void addClusteringServices(
     final OperationContext context, final boolean appclient) {
   if (appclient) {
     return;
   }
   ServiceTarget target = context.getServiceTarget();
   target
       .addService(RegistryCollectorService.SERVICE_NAME, new RegistryCollectorService<>())
       .setInitialMode(ServiceController.Mode.ON_DEMAND)
       .install();
   target
       .addService(
           CacheFactoryBuilderRegistryService.SERVICE_NAME,
           new CacheFactoryBuilderRegistryService<>())
       .setInitialMode(ServiceController.Mode.ON_DEMAND)
       .install();
   if (context.hasOptionalCapability(
       SingletonPolicy.CAPABILITY_NAME.concat(".default"),
       CLUSTERED_SINGLETON_CAPABILITY.getName(),
       null)) {
     final ClusteredSingletonServiceCreator singletonBarrierCreator =
         new ClusteredSingletonServiceCreator();
     target
         .addService(
             CLUSTERED_SINGLETON_CAPABILITY.getCapabilityServiceName().append("creator"),
             singletonBarrierCreator)
         .addDependency(
             context.getCapabilityServiceName(
                 SingletonPolicy.CAPABILITY_NAME, SingletonPolicy.class),
             SingletonPolicy.class,
             singletonBarrierCreator.getSingletonPolicy())
         .install();
   }
 }
    @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();
    }