/**
   * Loads/caches the persistence provider adapter
   *
   * @param adapterModule may specify the adapter module name (can be null to use noop provider)
   * @return the persistence provider adaptor for the provider class
   * @throws ModuleLoadException
   */
  public static PersistenceProviderAdaptor loadPersistenceAdapterModule(String adapterModule)
      throws ModuleLoadException {
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();

    if (adapterModule == null) {
      return noopAdaptor;
    }

    PersistenceProviderAdaptor persistenceProviderAdaptor = null;

    Module module = moduleLoader.loadModule(ModuleIdentifier.fromString(adapterModule));
    final ServiceLoader<PersistenceProviderAdaptor> serviceLoader =
        module.loadService(PersistenceProviderAdaptor.class);
    if (serviceLoader != null) {
      for (PersistenceProviderAdaptor adaptor : serviceLoader) {
        if (persistenceProviderAdaptor != null) {
          throw MESSAGES.multipleAdapters(adapterModule);
        }
        persistenceProviderAdaptor = adaptor;
        JPA_LOGGER.debugf("loaded persistence provider adapter %s", adapterModule);
      }
      if (persistenceProviderAdaptor != null) {
        persistenceProviderAdaptor.injectJtaManager(JtaManagerImpl.getInstance());
      }
    }
    return persistenceProviderAdaptor;
  }
  public void start() {
    final Xnio xnio;
    try {
      // Do what org.jboss.as.remoting.XnioUtil does
      xnio =
          Xnio.getInstance(
              null,
              Module.getModuleFromCallerModuleLoader(
                      ModuleIdentifier.fromString("org.jboss.xnio.nio"))
                  .getClassLoader());
    } catch (Exception e) {
      throw new IllegalStateException(e.getLocalizedMessage());
    }
    try {
      // TODO make this configurable
      worker =
          xnio.createWorker(
              OptionMap.builder()
                  .set(Options.WORKER_IO_THREADS, 4)
                  .set(Options.CONNECTION_HIGH_WATER, 1000000)
                  .set(Options.CONNECTION_LOW_WATER, 1000000)
                  .set(Options.WORKER_TASK_CORE_THREADS, 10)
                  .set(Options.WORKER_TASK_MAX_THREADS, 12)
                  .set(Options.TCP_NODELAY, true)
                  .set(Options.CORK, true)
                  .getMap());

      Builder serverOptionsBuilder =
          OptionMap.builder().set(Options.TCP_NODELAY, true).set(Options.REUSE_ADDRESSES, true);
      ChannelListener acceptListener = ChannelListeners.openListenerAdapter(openListener);
      if (httpAddress != null) {
        normalServer =
            worker.createStreamConnectionServer(
                httpAddress, acceptListener, serverOptionsBuilder.getMap());
        normalServer.resumeAccepts();
      }
      if (secureAddress != null) {
        SSLContext sslContext = securityRealm.getSSLContext();
        Set<AuthMechanism> supportedMechanisms =
            securityRealm.getSupportedAuthenticationMechanisms();
        if (supportedMechanisms.contains(AuthMechanism.CLIENT_CERT)) {
          if (supportedMechanisms.contains(AuthMechanism.DIGEST)
              || supportedMechanisms.contains(AuthMechanism.PLAIN)) {
            // Username / Password auth is possible so don't mandate a client certificate.
            serverOptionsBuilder.set(SSL_CLIENT_AUTH_MODE, REQUESTED);
          } else {
            serverOptionsBuilder.set(SSL_CLIENT_AUTH_MODE, REQUIRED);
          }
        }
        OptionMap secureOptions = serverOptionsBuilder.getMap();
        XnioSsl xnioSsl = new JsseXnioSsl(worker.getXnio(), secureOptions, sslContext);
        secureServer =
            xnioSsl.createSslConnectionServer(worker, secureAddress, acceptListener, secureOptions);
        secureServer.resumeAccepts();
      }
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
Exemplo n.º 3
0
 /** {@inheritDoc} */
 @Override
 protected String installExtension(String module, OperationContext context) {
   try {
     for (Extension extension :
         Module.loadServiceFromCurrent(ModuleIdentifier.fromString(module), Extension.class)) {
       extension.initialize(extensionContext);
     }
     return null;
   } catch (ModuleLoadException e) {
     return e.getLocalizedMessage();
   }
 }
  public void start() {
    final Xnio xnio;
    try {
      // Do what org.jboss.as.remoting.XnioUtil does
      xnio =
          Xnio.getInstance(
              null,
              Module.getModuleFromCallerModuleLoader(
                      ModuleIdentifier.fromString("org.jboss.xnio.nio"))
                  .getClassLoader());
    } catch (Exception e) {
      throw new IllegalStateException(e.getLocalizedMessage());
    }
    try {
      // TODO make this configurable
      worker =
          xnio.createWorker(
              OptionMap.builder()
                  .set(Options.WORKER_IO_THREADS, 2)
                  .set(Options.WORKER_TASK_CORE_THREADS, 5)
                  .set(Options.WORKER_TASK_MAX_THREADS, 10)
                  .set(Options.TCP_NODELAY, true)
                  .set(Options.CORK, true)
                  .getMap());

      Builder serverOptionsBuilder =
          OptionMap.builder().set(Options.TCP_NODELAY, true).set(Options.REUSE_ADDRESSES, true);
      ChannelListener acceptListener = ChannelListeners.openListenerAdapter(openListener);
      if (httpAddress != null) {
        normalServer =
            worker.createStreamConnectionServer(
                httpAddress, acceptListener, serverOptionsBuilder.getMap());
        normalServer.resumeAccepts();
      }
      if (secureAddress != null) {
        if (sslClientAuthMode != null) {
          serverOptionsBuilder.set(SSL_CLIENT_AUTH_MODE, sslClientAuthMode);
        }
        OptionMap secureOptions = serverOptionsBuilder.getMap();
        XnioSsl xnioSsl = new UndertowXnioSsl(worker.getXnio(), secureOptions, sslContext);
        secureServer =
            xnioSsl.createSslConnectionServer(worker, secureAddress, acceptListener, secureOptions);
        secureServer.resumeAccepts();
      }
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
  /**
   * This method retrieves all security permissions contained within the specified node.
   *
   * @param context the {@link OperationContext} used to resolve the permission attributes.
   * @param node the {@link ModelNode} that might contain security permissions metadata.
   * @return a {@link List} containing the retrieved permissions. They are wrapped as {@link
   *     PermissionFactory} instances.
   * @throws OperationFailedException if an error occurs while retrieving the security permissions.
   */
  protected List<PermissionFactory> retrievePermissionSet(
      final OperationContext context, final ModelNode node) throws OperationFailedException {

    final List<PermissionFactory> permissions = new ArrayList<PermissionFactory>();

    if (node != null && node.isDefined()) {
      for (ModelNode permissionNode : node.asList()) {
        String permissionClass =
            DeploymentPermissionsResourceDefinition.CLASS
                .resolveModelAttribute(context, permissionNode)
                .asString();
        String permissionName = null;
        if (permissionNode.hasDefined(PERMISSION_NAME))
          permissionName =
              DeploymentPermissionsResourceDefinition.NAME
                  .resolveModelAttribute(context, permissionNode)
                  .asString();
        String permissionActions = null;
        if (permissionNode.hasDefined(PERMISSION_ACTIONS))
          permissionActions =
              DeploymentPermissionsResourceDefinition.ACTIONS
                  .resolveModelAttribute(context, permissionNode)
                  .asString();
        String moduleName = null;
        if (permissionNode.hasDefined(PERMISSION_MODULE)) {
          moduleName =
              DeploymentPermissionsResourceDefinition.MODULE
                  .resolveModelAttribute(context, permissionNode)
                  .asString();
        }
        ClassLoader cl = WildFlySecurityManager.getClassLoaderPrivileged(this.getClass());
        if (moduleName != null) {
          try {
            cl =
                Module.getBootModuleLoader()
                    .loadModule(ModuleIdentifier.fromString(moduleName))
                    .getClassLoader();
          } catch (ModuleLoadException e) {
            throw new OperationFailedException(e);
          }
        }

        permissions.add(
            new LoadedPermissionFactory(cl, permissionClass, permissionName, permissionActions));
      }
    }
    return permissions;
  }
Exemplo n.º 6
0
 static ModuleClassLoader getModuleClassLoader(final String moduleSpec)
     throws ModuleLoadException {
   if (System.getSecurityManager() != null) {
     try {
       return AccessController.doPrivileged(
           new PrivilegedExceptionAction<ModuleClassLoader>() {
             public ModuleClassLoader run() throws ModuleLoadException {
               ModuleLoader loader = Module.getCallerModuleLoader();
               ModuleIdentifier identifier = ModuleIdentifier.fromString(moduleSpec);
               return loader.loadModule(identifier).getClassLoader();
             }
           });
     } catch (PrivilegedActionException pae) {
       throw new ModuleLoadException(pae);
     }
   } else {
     ModuleLoader loader = Module.getCallerModuleLoader();
     ModuleIdentifier identifier = ModuleIdentifier.fromString(moduleSpec);
     return loader.loadModule(identifier).getClassLoader();
   }
 }
Exemplo n.º 7
0
  @Override
  public ClassLoader getClassLoader(ClassLoader fallbackLoader, String... classpathEntries) {
    List<ClassLoader> delegatingLoaders = new ArrayList<ClassLoader>();
    if (classpathEntries != null) {
      // each classpath entry is interpreted as a module identifier
      for (String moduleIdString : classpathEntries) {
        if (!StringUtil.isBlank(moduleIdString)) {
          try {
            ModuleIdentifier moduleIdentifier = ModuleIdentifier.fromString(moduleIdString);
            delegatingLoaders.add(moduleLoader().loadModule(moduleIdentifier).getClassLoader());
          } catch (IllegalArgumentException e) {
            LOG.warnv(
                "The string (classpath entry) is not a valid module identifier: {0}",
                moduleIdString);
          } catch (ModuleLoadException e) {
            LOG.warnv(
                "Cannot load module from (from classpath entry) with identifier: {0}",
                moduleIdString);
          }
        }
      }
    }
    ClassLoader currentLoader = getClass().getClassLoader();
    if (fallbackLoader != null && !fallbackLoader.equals(currentLoader)) {
      // if the parent of fallback is the same as the current loader, just use that
      if (fallbackLoader.getParent().equals(currentLoader)) {
        currentLoader = fallbackLoader;
      } else {
        delegatingLoaders.add(fallbackLoader);
      }
    }

    return delegatingLoaders.isEmpty()
        ? currentLoader
        : new DelegatingClassLoader(currentLoader, delegatingLoaders);
  }
Exemplo n.º 8
0
  Collection<ServiceController<?>> installRuntimeServices(
      OperationContext context,
      ModelNode operation,
      ModelNode containerModel,
      ModelNode cacheModel,
      ServiceVerificationHandler verificationHandler)
      throws OperationFailedException {

    // get all required addresses, names and service names
    PathAddress cacheAddress = getCacheAddressFromOperation(operation);
    PathAddress containerAddress = getCacheContainerAddressFromOperation(operation);
    String cacheName = cacheAddress.getLastElement().getValue();
    String containerName = containerAddress.getLastElement().getValue();

    // get model attributes
    ModelNode resolvedValue = null;
    final String jndiName =
        ((resolvedValue = CommonAttributes.JNDI_NAME.resolveModelAttribute(context, cacheModel))
                .isDefined())
            ? resolvedValue.asString()
            : null;
    final ServiceController.Mode initialMode =
        StartMode.valueOf(
                CommonAttributes.START.resolveModelAttribute(context, cacheModel).asString())
            .getMode();

    final ModuleIdentifier moduleId =
        (resolvedValue = CommonAttributes.CACHE_MODULE.resolveModelAttribute(context, cacheModel))
                .isDefined()
            ? ModuleIdentifier.fromString(resolvedValue.asString())
            : null;

    // create a list for dependencies which may need to be added during processing
    List<Dependency<?>> dependencies = new LinkedList<Dependency<?>>();
    // Infinispan Configuration to hold the operation data
    ConfigurationBuilder builder =
        new ConfigurationBuilder().read(getDefaultConfiguration(this.mode));

    // process cache configuration ModelNode describing overrides to defaults
    processModelNode(context, containerName, cacheModel, builder, dependencies);

    // get container Model to pick up the value of the default cache of the container
    // AS7-3488 make default-cache no required attribute
    String defaultCache =
        CommonAttributes.DEFAULT_CACHE.resolveModelAttribute(context, containerModel).asString();

    ServiceTarget target = context.getServiceTarget();
    Configuration config = builder.build();

    Collection<ServiceController<?>> controllers = new ArrayList<ServiceController<?>>(3);

    // install the cache configuration service (configures a cache)
    controllers.add(
        this.installCacheConfigurationService(
            target,
            containerName,
            cacheName,
            defaultCache,
            moduleId,
            builder,
            config,
            dependencies,
            verificationHandler));
    log.debugf(
        "Cache configuration service for %s installed for container %s", cacheName, containerName);

    // now install the corresponding cache service (starts a configured cache)
    controllers.add(
        this.installCacheService(
            target,
            containerName,
            cacheName,
            defaultCache,
            initialMode,
            config,
            verificationHandler));

    // install a name service entry for the cache
    controllers.add(
        this.installJndiService(target, containerName, cacheName, jndiName, verificationHandler));
    log.debugf("Cache service for cache %s installed for container %s", cacheName, containerName);

    return controllers;
  }
Exemplo n.º 9
0
  Collection<ServiceController<?>> installRuntimeServices(
      OperationContext context,
      ModelNode operation,
      ModelNode containerModel,
      ServiceVerificationHandler verificationHandler)
      throws OperationFailedException {

    final PathAddress address = getCacheContainerAddressFromOperation(operation);
    final String name = address.getLastElement().getValue();
    final ServiceTarget target = context.getServiceTarget();

    // pick up the attribute values from the model
    ModelNode resolvedValue = null;
    // make default cache non required (AS7-3488)
    final String defaultCache =
        (resolvedValue =
                    CacheContainerResourceDefinition.DEFAULT_CACHE.resolveModelAttribute(
                        context, containerModel))
                .isDefined()
            ? resolvedValue.asString()
            : null;
    final String jndiName =
        (resolvedValue =
                    CacheContainerResourceDefinition.JNDI_NAME.resolveModelAttribute(
                        context, containerModel))
                .isDefined()
            ? resolvedValue.asString()
            : null;
    final String listenerExecutor =
        (resolvedValue =
                    CacheContainerResourceDefinition.LISTENER_EXECUTOR.resolveModelAttribute(
                        context, containerModel))
                .isDefined()
            ? resolvedValue.asString()
            : null;
    final String evictionExecutor =
        (resolvedValue =
                    CacheContainerResourceDefinition.EVICTION_EXECUTOR.resolveModelAttribute(
                        context, containerModel))
                .isDefined()
            ? resolvedValue.asString()
            : null;
    final String replicationQueueExecutor =
        (resolvedValue =
                    CacheContainerResourceDefinition.REPLICATION_QUEUE_EXECUTOR
                        .resolveModelAttribute(context, containerModel))
                .isDefined()
            ? resolvedValue.asString()
            : null;
    final ServiceController.Mode initialMode =
        StartMode.valueOf(
                CacheContainerResourceDefinition.START
                    .resolveModelAttribute(context, containerModel)
                    .asString())
            .getMode();
    final boolean statistics =
        CacheContainerResourceDefinition.STATISTICS_ENABLED
            .resolveModelAttribute(context, containerModel)
            .asBoolean();

    ServiceName[] aliases = null;
    if (containerModel.hasDefined(ModelKeys.ALIASES)) {
      List<ModelNode> list = operation.get(ModelKeys.ALIASES).asList();
      aliases = new ServiceName[list.size()];
      for (int i = 0; i < list.size(); i++) {
        aliases[i] = EmbeddedCacheManagerService.getServiceName(list.get(i).asString());
      }
    }

    final ModuleIdentifier moduleId =
        (resolvedValue =
                    CacheContainerResourceDefinition.MODULE.resolveModelAttribute(
                        context, containerModel))
                .isDefined()
            ? ModuleIdentifier.fromString(resolvedValue.asString())
            : null;

    // if we have a transport defined, pick up the transport-related attributes and install a
    // channel
    final Transport transportConfig =
        containerModel.hasDefined(ModelKeys.TRANSPORT)
                && containerModel.get(ModelKeys.TRANSPORT).hasDefined(ModelKeys.TRANSPORT_NAME)
            ? new Transport()
            : null;

    String stack = null;
    String transportExecutor = null;

    Collection<ServiceController<?>> controllers = new LinkedList<>();

    if (transportConfig != null) {
      ModelNode transport = containerModel.get(ModelKeys.TRANSPORT, ModelKeys.TRANSPORT_NAME);

      stack =
          (resolvedValue =
                      TransportResourceDefinition.STACK.resolveModelAttribute(context, transport))
                  .isDefined()
              ? resolvedValue.asString()
              : null;
      // if cluster is not defined, use the cache container name as the default
      final String cluster =
          (resolvedValue =
                      TransportResourceDefinition.CLUSTER.resolveModelAttribute(context, transport))
                  .isDefined()
              ? resolvedValue.asString()
              : name;
      long lockTimeout =
          TransportResourceDefinition.LOCK_TIMEOUT
              .resolveModelAttribute(context, transport)
              .asLong();
      transportExecutor =
          (resolvedValue =
                      TransportResourceDefinition.EXECUTOR.resolveModelAttribute(
                          context, transport))
                  .isDefined()
              ? resolvedValue.asString()
              : null;

      // initialise the Transport
      transportConfig.setClusterName(cluster);
      transportConfig.setLockTimeout(lockTimeout);

      controllers.addAll(
          this.installChannelServices(target, name, cluster, stack, verificationHandler));

      // register the protocol metrics by adding a step
      ChannelInstanceResourceDefinition.addChannelProtocolMetricsRegistrationStep(
          context, cluster, stack);

      for (ChannelServiceProvider provider :
          ServiceLoader.load(
              ChannelServiceProvider.class, ChannelServiceProvider.class.getClassLoader())) {
        log.debugf("Installing %s for channel %s", provider.getClass().getSimpleName(), cluster);
        controllers.addAll(provider.install(target, name, moduleId));
      }
    }

    // install the cache container configuration service
    controllers.add(
        this.installContainerConfigurationService(
            target,
            name,
            defaultCache,
            statistics,
            moduleId,
            stack,
            transportConfig,
            transportExecutor,
            listenerExecutor,
            evictionExecutor,
            replicationQueueExecutor,
            verificationHandler));

    // install a cache container service
    controllers.add(
        this.installContainerService(
            target, name, aliases, transportConfig, initialMode, verificationHandler));

    // install a name service entry for the cache container
    controllers.add(this.installJndiService(target, name, jndiName, verificationHandler));

    controllers.add(
        this.installKeyAffinityServiceFactoryService(target, name, verificationHandler));

    controllers.add(
        this.installGlobalComponentRegistryService(
            target, name, transportConfig, verificationHandler));

    log.debugf("%s cache container installed", name);
    return controllers;
  }