/**
  * 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 be
  *     {@link RuntimeCapability#isDynamicallyNamed() dynamically named}
  * @param dynamicPart the dynamic part of the capability name. Cannot be {@code null}
  * @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, String dynamicPart, Class<?> serviceType) {
   assert capabilities.contains(removed);
   assert removed.isDynamicallyNamed();
   return RuntimeCapability.fromBaseCapability(removed, dynamicPart)
       .getCapabilityServiceName(serviceType);
 }
    @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();
    }
 /**
  * Record any new {@link org.jboss.as.controller.capability.RuntimeCapability capabilities} that
  * are no longer available as a result of this operation, as well as any requirements for other
  * capabilities that no longer exist. This method is invoked during {@link
  * org.jboss.as.controller.OperationContext.Stage#MODEL}.
  *
  * <p>Any changes made by this method will automatically be discarded if the operation rolls back.
  *
  * <p>This default implementation deregisters any capabilities passed to the constructor.
  *
  * @param context the context. Will not be {@code null}
  * @param operation the operation that is executing Will not be {@code null}
  * @param resource the resource that will be removed. Will <strong>not</strong> reflect any
  *     updates made by {@link #performRemove(OperationContext, org.jboss.dmr.ModelNode,
  *     org.jboss.dmr.ModelNode)} as this method is invoked before that method is. Will not be
  *     {@code null}
  */
 protected void recordCapabilitiesAndRequirements(
     OperationContext context, ModelNode operation, Resource resource)
     throws OperationFailedException {
   for (RuntimeCapability capability : capabilities) {
     if (capability.isDynamicallyNamed()) {
       context.deregisterCapability(capability.getDynamicName(context.getCurrentAddressValue()));
     } else {
       context.deregisterCapability(capability.getName());
     }
   }
   ModelNode model = resource.getModel();
   ImmutableManagementResourceRegistration mrr = context.getResourceRegistration();
   for (String attr : mrr.getAttributeNames(PathAddress.EMPTY_ADDRESS)) {
     AttributeAccess aa = mrr.getAttributeAccess(PathAddress.EMPTY_ADDRESS, attr);
     if (aa != null) {
       AttributeDefinition ad = aa.getAttributeDefinition();
       if (ad != null && model.hasDefined(ad.getName())) {
         ad.removeCapabilityRequirements(context, model.get(ad.getName()));
       }
     }
   }
 }
    private void processCapabilityRequirement(
        OperationContext context, String attributeName, boolean remove, String... attributeValues) {
      String dependentName;
      if (dynamicDependent) {
        dependentName =
            RuntimeCapability.buildDynamicCapabilityName(
                baseDependentName, getDynamicDependentName(context.getCurrentAddress()));
      } else {
        dependentName = baseDependentName;
      }

      for (String attributeValue : attributeValues) {
        String requirementName =
            RuntimeCapability.buildDynamicCapabilityName(baseRequirementName, attributeValue);
        if (remove) {
          context.deregisterCapabilityRequirement(requirementName, dependentName);
        } else {
          context.registerAdditionalCapabilityRequirement(
              requirementName, dependentName, attributeName);
        }
      }
    }
Ejemplo n.º 6
0
  @Override
  protected void recordCapabilitiesAndRequirements(
      OperationContext context, ModelNode operation, Resource resource)
      throws OperationFailedException {
    super.recordCapabilitiesAndRequirements(context, operation, resource);

    ModelNode model = resource.getModel();
    if (CommonAttributes.JGROUPS_CHANNEL.resolveModelAttribute(context, model).isDefined()
        && !BroadcastGroupDefinition.JGROUPS_STACK
            .resolveModelAttribute(context, model)
            .isDefined()) {
      context.registerAdditionalCapabilityRequirement(
          JGroupsDefaultRequirement.CHANNEL_FACTORY.getName(),
          RuntimeCapability.buildDynamicCapabilityName(
              BroadcastGroupDefinition.CHANNEL_FACTORY_CAPABILITY.getName(),
              context.getCurrentAddressValue()),
          BroadcastGroupDefinition.JGROUPS_STACK.getName());
    }
  }
 /**
  * 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);
 }