Beispiel #1
0
  @Override
  public void performRuntime(final OperationContext context, ModelNode operation, ModelNode model)
      throws OperationFailedException {
    // Compensating is remove
    final ModelNode address = operation.require(OP_ADDR);
    final String name = PathAddress.pathAddress(address).getLastElement().getValue();
    final String archiveOrModuleName;
    if (!model.hasDefined(ARCHIVE.getName()) && !model.hasDefined(MODULE.getName())) {
      throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired();
    }
    if (model.get(ARCHIVE.getName()).isDefined()) {
      archiveOrModuleName = model.get(ARCHIVE.getName()).asString();
    } else {
      archiveOrModuleName = model.get(MODULE.getName()).asString();
    }

    ModifiableResourceAdapter resourceAdapter =
        RaOperationUtil.buildResourceAdaptersObject(name, context, operation, archiveOrModuleName);
    List<ServiceController<?>> newControllers = new ArrayList<ServiceController<?>>();
    if (model.get(ARCHIVE.getName()).isDefined()) {
      RaOperationUtil.installRaServices(context, name, resourceAdapter, newControllers);
    } else {
      RaOperationUtil.installRaServicesAndDeployFromModule(
          context, name, resourceAdapter, archiveOrModuleName, newControllers);
      if (context.isBooting()) {
        context.addStep(
            new OperationStepHandler() {
              public void execute(final OperationContext context, ModelNode operation)
                  throws OperationFailedException {

                // Next lines activate configuration on module deployed rar
                // in case there is 2 different resource-adapter config using same module deployed
                // rar
                // a Deployment sercivice could be already present and need a restart to consider
                // also this
                // newly added configuration
                ServiceName restartedServiceName =
                    RaOperationUtil.restartIfPresent(context, archiveOrModuleName, name);
                if (restartedServiceName == null) {
                  RaOperationUtil.activate(context, name, archiveOrModuleName);
                }
                context.completeStep(
                    new OperationContext.RollbackHandler() {
                      @Override
                      public void handleRollback(OperationContext context, ModelNode operation) {
                        try {
                          RaOperationUtil.removeIfActive(context, archiveOrModuleName, name);
                        } catch (OperationFailedException e) {

                        }
                      }
                    });
              }
            },
            OperationContext.Stage.RUNTIME);
      }
    }
  }
 @Override
 protected void validateReferencedNewValueExisits(OperationContext context, ModelNode value)
     throws OperationFailedException {
   final Resource root = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS, false);
   // Don't do this on boot since the domain model is not populated yet
   if (!context.isBooting()
       && root.getChild(PathElement.pathElement(SERVER_GROUP, value.asString())) == null) {
     throw HostControllerMessages.MESSAGES.noServerGroupCalled(value.asString());
   }
 }
  @Override
  protected void updateModel(OperationContext context, ModelNode operation)
      throws OperationFailedException {
    context.removeResource(PathAddress.EMPTY_ADDRESS);

    if (validateAuthentication && !context.isBooting()) {
      ModelNode validationOp = AuthenticationValidatingHandler.createOperation(operation);
      context.addStep(
          validationOp, AuthenticationValidatingHandler.INSTANCE, OperationContext.Stage.MODEL);
    } // else we know the SecurityRealmAddHandler is part of this overall set of ops and it added
    // AuthenticationValidatingHandler
    if (validateRbac) {
      RbacSanityCheckOperation.addOperation(context);
    }
  }
 /**
  * Add a step triggering the {@linkplain
  * org.jboss.as.controller.OperationContext#reloadRequired()} in case the the cache service is
  * installed, since the transport-config operations need a reload/restart and can't be applied to
  * the runtime directly.
  *
  * @param context the operation context
  */
 void reloadRequiredStep(final OperationContext context) {
   if (context.getProcessType().isServer() && !context.isBooting()) {
     context.addStep(
         new OperationStepHandler() {
           @Override
           public void execute(final OperationContext context, final ModelNode operation)
               throws OperationFailedException {
             // add some condition here if reload needs to be conditional on context
             // e.g. if a service is not installed, don't do a reload
             context.reloadRequired();
             context.completeStep();
           }
         },
         OperationContext.Stage.RUNTIME);
   }
 }
 @Override
 protected boolean requiresRuntime(OperationContext context) {
   // On boot, the parent add will pick up these changes
   return !context.isBooting();
 }
  protected void performRuntime(
      OperationContext context,
      ModelNode operation,
      ModelNode model,
      ServiceVerificationHandler verificationHandler,
      List<ServiceController<?>> newControllers) {

    log.info("Activating Naming Subsystem");

    NamingContext.initializeNamingManager();

    final ServiceBasedNamingStore namingStore =
        new ServiceBasedNamingStore(
            context.getServiceRegistry(false), ContextNames.JAVA_CONTEXT_SERVICE_NAME);

    // Create the Naming Service
    final ServiceTarget target = context.getServiceTarget();
    newControllers.add(
        target
            .addService(NamingService.SERVICE_NAME, new NamingService(namingStore))
            .addAliases(ContextNames.JAVA_CONTEXT_SERVICE_NAME)
            .setInitialMode(ServiceController.Mode.ACTIVE)
            .addListener(verificationHandler)
            .install());

    // Create the java:global namespace
    final ServiceBasedNamingStore globalNamingStore =
        new ServiceBasedNamingStore(
            context.getServiceRegistry(false), ContextNames.GLOBAL_CONTEXT_SERVICE_NAME);
    newControllers.add(
        target
            .addService(
                ContextNames.GLOBAL_CONTEXT_SERVICE_NAME, new NamingStoreService(globalNamingStore))
            .setInitialMode(ServiceController.Mode.ACTIVE)
            .addListener(verificationHandler)
            .install());

    // Create the java:jboss vendor namespace
    final ServiceBasedNamingStore jbossNamingStore =
        new ServiceBasedNamingStore(
            context.getServiceRegistry(false), ContextNames.JBOSS_CONTEXT_SERVICE_NAME);
    newControllers.add(
        target
            .addService(
                ContextNames.JBOSS_CONTEXT_SERVICE_NAME, new NamingStoreService(jbossNamingStore))
            .setInitialMode(ServiceController.Mode.ACTIVE)
            .addListener(verificationHandler)
            .install());

    NamespaceContextSelector.setDefault(
        new NamespaceContextSelector() {
          public Context getContext(String identifier) {
            final NamingStore namingStore;
            if (identifier.equals("global")) {
              namingStore = globalNamingStore;
            } else if (identifier.equals("jboss")) {
              namingStore = jbossNamingStore;
            } else {
              namingStore = null;
            }
            if (namingStore != null) {
              try {
                return (Context) namingStore.lookup(EMPTY_NAME);
              } catch (NamingException e) {
                throw new IllegalStateException(e);
              }
            } else {
              return null;
            }
          }
        });

    // Provide the {@link InitialContext} as OSGi service
    newControllers.add(InitialContextFactoryService.addService(target, verificationHandler));

    newControllers.add(
        target
            .addService(JndiViewExtensionRegistry.SERVICE_NAME, new JndiViewExtensionRegistry())
            .install());

    if (context.isBooting()) {
      context.addStep(
          new AbstractDeploymentChainStep() {
            protected void execute(DeploymentProcessorTarget processorTarget) {
              processorTarget.addDeploymentProcessor(
                  Phase.INSTALL,
                  Phase.INSTALL_JNDI_DEPENDENCY_SETUP,
                  new JndiNamingDependencySetupProcessor());
              processorTarget.addDeploymentProcessor(
                  Phase.INSTALL,
                  Phase.INSTALL_JNDI_DEPENDENCIES,
                  new JndiNamingDependencyProcessor());
            }
          },
          OperationContext.Stage.RUNTIME);
    }
  }
 @Override
 protected boolean requiresRuntime(OperationContext context) {
   return !context.isBooting();
 }
  static void launchServices(
      final OperationContext context,
      final PathAddress pathAddress,
      final ModelNode model,
      final ServiceVerificationHandler verificationHandler,
      final List<ServiceController<?>> newControllers)
      throws OperationFailedException {
    Handler newHandler = new Handler();

    ModelNode classNameNode = HandlerResourceDefinition.CLASS.resolveModelAttribute(context, model);
    ModelNode codeNode = HandlerResourceDefinition.CODE.resolveModelAttribute(context, model);
    String typeName;

    if (classNameNode.isDefined()) {
      typeName = classNameNode.asString();
    } else if (codeNode.isDefined()) {
      typeName = HandlerTypeEnum.forType(codeNode.asString());
    } else {
      throw PicketLinkLogger.ROOT_LOGGER.federationHandlerTypeNotProvided();
    }

    newHandler.setClazz(typeName);

    ModelNode handler = Resource.Tools.readModel(context.readResourceFromRoot(pathAddress));

    if (handler.hasDefined(COMMON_HANDLER_PARAMETER.getName())) {
      for (Property handlerParameter :
          handler.get(COMMON_HANDLER_PARAMETER.getName()).asPropertyList()) {
        String paramName = handlerParameter.getName();
        String paramValue =
            HandlerParameterResourceDefinition.VALUE
                .resolveModelAttribute(context, handlerParameter.getValue())
                .asString();

        KeyValueType kv = new KeyValueType();

        kv.setKey(paramName);
        kv.setValue(paramValue);

        newHandler.add(kv);
      }
    }

    SAMLHandlerService service = new SAMLHandlerService(newHandler);
    PathElement providerAlias = pathAddress.subAddress(0, pathAddress.size() - 1).getLastElement();

    ServiceTarget serviceTarget = context.getServiceTarget();
    ServiceBuilder<SAMLHandlerService> serviceBuilder =
        serviceTarget.addService(
            createServiceName(providerAlias.getValue(), newHandler.getClazz()), service);
    ServiceName serviceName;

    if (providerAlias.getKey().equals(IDENTITY_PROVIDER.getName())) {
      serviceName = IdentityProviderService.createServiceName(providerAlias.getValue());
    } else {
      serviceName = ServiceProviderService.createServiceName(providerAlias.getValue());
    }

    serviceBuilder.addDependency(
        serviceName, EntityProviderService.class, service.getEntityProviderService());

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

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

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

    if (!context.isBooting()) {
      // a reload is required to get the chain properly updated with the domain model state.
      context.reloadRequired();
    }
  }