@Override
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {
    if (context.isNormalServer()
        && context.getServiceRegistry(false).getService(ModClusterService.NAME) != null) {
      context.addStep(
          new OperationStepHandler() {
            @Override
            public void execute(OperationContext context, ModelNode operation)
                throws OperationFailedException {
              ServiceController<?> controller =
                  context.getServiceRegistry(false).getService(ModClusterService.NAME);
              ModCluster modcluster = (ModCluster) controller.getValue();
              Map<InetSocketAddress, String> map = modcluster.getProxyInfo();
              ROOT_LOGGER.debugf("Mod_cluster ProxyInfo %s", map);
              if (!map.isEmpty()) {
                final ModelNode result = new ModelNode();
                Object[] addr = map.keySet().toArray();
                for (int i = 0; i < addr.length; i++) {
                  InetSocketAddress address = (InetSocketAddress) addr[i];
                  result.add(address.getHostName() + ":" + address.getPort());
                  result.add(map.get(addr[i]));
                }
                context.getResult().set(result);
              }

              context.stepCompleted();
            }
          },
          OperationContext.Stage.RUNTIME);
    }

    context.stepCompleted();
  }
 static void reloadRequiredStep(final OperationContext context) {
   if (context.isNormalServer()) {
     context.addStep(
         new OperationStepHandler() {
           @Override
           public void execute(final OperationContext context, final ModelNode operation)
               throws OperationFailedException {
             final ServiceName hqServiceName =
                 MessagingServices.getHornetQServiceName(
                     PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
             final ServiceController<?> controller =
                 context.getServiceRegistry(false).getService(hqServiceName);
             OperationContext.RollbackHandler rh;
             if (controller != null) {
               context.reloadRequired();
               rh = OperationContext.RollbackHandler.REVERT_RELOAD_REQUIRED_ROLLBACK_HANDLER;
             } else {
               rh = OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER;
             }
             context.completeStep(rh);
           }
         },
         OperationContext.Stage.RUNTIME);
   }
 }
Exemple #3
0
  @Override
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {
    if (context.isNormalServer()
        && context.getServiceRegistry(false).getService(ModClusterService.NAME) != null) {
      context.addStep(
          new OperationStepHandler() {
            @Override
            public void execute(OperationContext context, ModelNode operation)
                throws OperationFailedException {
              ServiceController<?> controller =
                  context.getServiceRegistry(false).getService(ModClusterService.NAME);
              ModCluster modcluster = (ModCluster) controller.getValue();
              ROOT_LOGGER.debugf("add-proxy: %s", operation);

              Proxy proxy = new Proxy(operation);
              modcluster.addProxy(proxy.host, proxy.port);

              // TODO AS7-5695 handle rollback
              context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
            }
          },
          OperationContext.Stage.RUNTIME);
    }

    context.stepCompleted();
  }
  @Override
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {
    if (context.isNormalServer()
        && context.getServiceRegistry(false).getService(ModClusterService.NAME) != null) {
      context.addStep(
          new OperationStepHandler() {
            @Override
            public void execute(OperationContext context, ModelNode operation)
                throws OperationFailedException {
              ServiceController<?> controller =
                  context.getServiceRegistry(false).getService(ModClusterService.NAME);
              final ModCluster modcluster = (ModCluster) controller.getValue();
              ROOT_LOGGER.debugf("remove-proxy: %s", operation);

              final Proxy proxy = new Proxy(operation);
              modcluster.removeProxy(proxy.host, proxy.port);

              context.completeStep(
                  new OperationContext.RollbackHandler() {
                    @Override
                    public void handleRollback(OperationContext context, ModelNode operation) {
                      // TODO What if mod_cluster was never aware of this proxy?
                      modcluster.addProxy(proxy.host, proxy.port);
                    }
                  });
            }
          },
          OperationContext.Stage.RUNTIME);
    }

    context.stepCompleted();
  }
  @Override
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {
    if (context.isNormalServer()
        && context.getServiceRegistry(false).getService(ModClusterService.NAME) != null) {
      context.addStep(
          new OperationStepHandler() {
            @Override
            public void execute(OperationContext context, ModelNode operation)
                throws OperationFailedException {
              ServiceController<?> controller =
                  context.getServiceRegistry(false).getService(ModClusterService.NAME);
              ModCluster modcluster = (ModCluster) controller.getValue();
              ROOT_LOGGER.debugf("remove-proxy: %s", operation);

              Proxy proxy = new Proxy(operation);
              modcluster.removeProxy(proxy.host, proxy.port);

              context.completeStep();
            }
          },
          OperationContext.Stage.RUNTIME);
    }

    context.completeStep();
  }
 private boolean isRemoveService(OperationContext context) {
   if (context.isNormalServer()) {
     if (context.isResourceServiceRestartAllowed()) {
       context.removeService(MBeanServerService.SERVICE_NAME);
       return true;
     }
   }
   return false;
 }
  @Override
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {
    if (context.isNormalServer()
        && context.getServiceRegistry(false).getService(ContainerEventHandlerService.SERVICE_NAME)
            != null) {
      context.addStep(
          new OperationStepHandler() {
            @Override
            public void execute(OperationContext context, ModelNode operation)
                throws OperationFailedException {
              ServiceController<?> controller =
                  context
                      .getServiceRegistry(false)
                      .getService(ContainerEventHandlerService.SERVICE_NAME);
              final ModClusterServiceMBean service = (ModClusterServiceMBean) controller.getValue();
              ROOT_LOGGER.debugf("stop-context: %s", operation);
              final ContextHost contexthost = new ContextHost(operation);

              try {
                service.stopContext(
                    contexthost.webhost,
                    contexthost.webcontext,
                    contexthost.waittime,
                    TimeUnit.SECONDS);
              } catch (IllegalArgumentException e) {
                throw new OperationFailedException(
                    new ModelNode()
                        .set(
                            ModClusterLogger.ROOT_LOGGER.ContextOrHostNotFound(
                                contexthost.webhost, contexthost.webcontext)));
              }

              context.completeStep(
                  new OperationContext.RollbackHandler() {
                    @Override
                    public void handleRollback(OperationContext context, ModelNode operation) {
                      // TODO We're assuming that the context was previously enabled, but it could
                      // have been disabled
                      service.enableContext(contexthost.webhost, contexthost.webcontext);
                    }
                  });
            }
          },
          OperationContext.Stage.RUNTIME);
    }

    context.stepCompleted();
  }
  @Override
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {
    if (context.isNormalServer()
        && context.getServiceRegistry(false).getService(ModClusterService.NAME) != null) {
      context.addStep(
          new OperationStepHandler() {
            @Override
            public void execute(OperationContext context, ModelNode operation)
                throws OperationFailedException {
              ServiceController<?> controller =
                  context.getServiceRegistry(false).getService(ModClusterService.NAME);
              ModCluster modcluster = (ModCluster) controller.getValue();
              modcluster.disable();
              context.completeStep();
            }
          },
          OperationContext.Stage.RUNTIME);
    }

    context.completeStep();
  }
  protected void installServices(
      final OperationContext context,
      final String realmName,
      final ModelNode model,
      final ServiceVerificationHandler verificationHandler,
      final List<ServiceController<?>> newControllers)
      throws OperationFailedException {
    final ModelNode plugIns = model.hasDefined(PLUG_IN) ? model.get(PLUG_IN) : null;
    final ModelNode authentication =
        model.hasDefined(AUTHENTICATION) ? model.get(AUTHENTICATION) : null;
    final ModelNode authorization =
        model.hasDefined(AUTHORIZATION) ? model.get(AUTHORIZATION) : null;
    final ModelNode serverIdentities =
        model.hasDefined(SERVER_IDENTITY) ? model.get(SERVER_IDENTITY) : null;

    final ServiceTarget serviceTarget = context.getServiceTarget();

    final boolean mapGroupsToRoles =
        SecurityRealmResourceDefinition.MAP_GROUPS_TO_ROLES
            .resolveModelAttribute(context, model)
            .asBoolean();
    final SecurityRealmService securityRealmService =
        new SecurityRealmService(realmName, mapGroupsToRoles);
    final ServiceName realmServiceName = SecurityRealm.ServiceUtil.createServiceName(realmName);
    ServiceBuilder<?> realmBuilder =
        serviceTarget.addService(realmServiceName, securityRealmService);

    final boolean shareLdapConnections =
        shareLdapConnection(context, authentication, authorization);
    ModelNode authTruststore = null;
    if (plugIns != null) {
      addPlugInLoaderService(realmName, plugIns, serviceTarget, newControllers);
    }
    InjectedSetValue<CallbackHandlerService> injectorSet =
        securityRealmService.getCallbackHandlerService();
    if (authentication != null) {
      // Authentication can have a truststore defined at the same time as a username/password based
      // mechanism.
      //
      // In this case it is expected certificate based authentication will first occur with a
      // fallback to username/password
      // based authentication.
      if (authentication.hasDefined(TRUSTSTORE)) {
        authTruststore = authentication.require(TRUSTSTORE);
        addClientCertService(
            realmName, serviceTarget, newControllers, realmBuilder, injectorSet.injector());
      }
      if (authentication.hasDefined(LOCAL)) {
        addLocalService(
            context,
            authentication.require(LOCAL),
            realmName,
            serviceTarget,
            newControllers,
            realmBuilder,
            injectorSet.injector());
      }
      if (authentication.hasDefined(JAAS)) {
        addJaasService(
            context,
            authentication.require(JAAS),
            realmName,
            serviceTarget,
            newControllers,
            context.isNormalServer(),
            realmBuilder,
            injectorSet.injector());
      } else if (authentication.hasDefined(LDAP)) {
        addLdapService(
            context,
            authentication.require(LDAP),
            realmName,
            serviceTarget,
            newControllers,
            realmBuilder,
            injectorSet.injector(),
            shareLdapConnections);
      } else if (authentication.hasDefined(PLUG_IN)) {
        addPlugInAuthenticationService(
            context,
            authentication.require(PLUG_IN),
            realmName,
            securityRealmService,
            serviceTarget,
            newControllers,
            realmBuilder,
            injectorSet.injector());
      } else if (authentication.hasDefined(PROPERTIES)) {
        addPropertiesAuthenticationService(
            context,
            authentication.require(PROPERTIES),
            realmName,
            serviceTarget,
            newControllers,
            realmBuilder,
            injectorSet.injector());
      } else if (authentication.hasDefined(USERS)) {
        addUsersService(
            context,
            authentication.require(USERS),
            realmName,
            serviceTarget,
            newControllers,
            realmBuilder,
            injectorSet.injector());
      }
    }
    if (authorization != null) {
      if (authorization.hasDefined(PROPERTIES)) {
        addPropertiesAuthorizationService(
            context,
            authorization.require(PROPERTIES),
            realmName,
            serviceTarget,
            newControllers,
            realmBuilder,
            securityRealmService.getSubjectSupplementalInjector());
      } else if (authorization.hasDefined(PLUG_IN)) {
        addPlugInAuthorizationService(
            context,
            authorization.require(PLUG_IN),
            realmName,
            serviceTarget,
            newControllers,
            realmBuilder,
            securityRealmService.getSubjectSupplementalInjector());
      } else if (authorization.hasDefined(LDAP)) {
        addLdapAuthorizationService(
            context,
            authorization.require(LDAP),
            realmName,
            serviceTarget,
            newControllers,
            realmBuilder,
            securityRealmService.getSubjectSupplementalInjector(),
            shareLdapConnections);
      }
    }

    ModelNode ssl = null;
    if (serverIdentities != null) {
      if (serverIdentities.hasDefined(SSL)) {
        ssl = serverIdentities.require(SSL);
      }
      if (serverIdentities.hasDefined(SECRET)) {
        addSecretService(
            context,
            serverIdentities.require(SECRET),
            realmName,
            serviceTarget,
            newControllers,
            realmBuilder,
            securityRealmService.getSecretCallbackFactory());
      }
    }

    if (ssl != null || authTruststore != null) {
      addSSLService(
          context,
          ssl,
          authTruststore,
          realmName,
          serviceTarget,
          newControllers,
          realmBuilder,
          securityRealmService.getSSLIdentityInjector());
    }

    realmBuilder.setInitialMode(Mode.ACTIVE);
    ServiceController<?> sc = realmBuilder.install();
    if (newControllers != null) {
      newControllers.add(sc);
    }
  }