static ModuleClassLoader getModuleClassLoader(final ModuleLoader loader, final String moduleSpec) throws ModuleLoadException { final Module module = loader.loadModule(ModuleIdentifier.fromString(moduleSpec)); return WildFlySecurityManager.isChecking() ? doPrivileged(new GetModuleClassLoaderAction(module)) : module.getClassLoader(); }
/** {@inheritDoc} */ public Class<?> resolveClass(final Unmarshaller unmarshaller, final String className, final long serialVersionUID) throws IOException, ClassNotFoundException { final String name = (String) unmarshaller.readObject(); if (name == null) { return Class.forName(className, false, MODULE_CLASS_LOADER); } final String slot = (String) unmarshaller.readObject(); final ModuleIdentifier identifier = ModuleIdentifier.create(name, slot); try { final ClassLoader classLoader; final Module module = moduleLoader.loadModule(identifier); if (System.getSecurityManager() == null) { classLoader = module.getClassLoader(); } else { classLoader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { @Override public ClassLoader run() { return module.getClassLoader(); } }); } return Class.forName(className, false, classLoader); } catch (ModuleLoadException e) { final InvalidClassException ce = new InvalidClassException(className, "Module load failed"); ce.initCause(e); throw ce; } }
if (! WildFlySecurityManager.isChecking()) { loader = getClass().getClassLoader(); } else { loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { @Override public ClassLoader run() { loadedContext = (Context) ctor.newInstance(newEnvironment); } else { Module module = Module.getBootModuleLoader().loadModule(ModuleIdentifier.fromString(initialContextModule)); loader = module.getClassLoader(); final ClassLoader currentClassLoader = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged(); try { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(loader); initialContextClass = Class.forName(initialContextClassName, true, loader); Constructor ctor = initialContextClass.getConstructor(Hashtable.class);
private static Class unwrapClass(ModelNode classModel) throws OperationFailedException { String className = classModel.get(NAME).asString(); String moduleName = classModel.get(MODULE).asString(); try { ModuleIdentifier moduleID = ModuleIdentifier.fromString(moduleName); Module module = Module.getCallerModuleLoader().loadModule(moduleID); Class<?> clazz = module.getClassLoader().loadClass(className); return clazz; } catch (Exception e) { throw ROOT_LOGGER.unableToLoadClassFromModule(className, moduleName); } } }
final String baseDir = WildFlySecurityManager.getPropertyPrivileged(JBOSS_DOMAIN_BASE_DIR, jbossHome + File.separator + "domain"); String controllerLogDir = WildFlySecurityManager.getPropertyPrivileged(JBOSS_DOMAIN_LOG_DIR, null); if (controllerLogDir == null) { controllerLogDir = baseDir + File.separator + "log"; WildFlySecurityManager.setPropertyPrivileged(JBOSS_DOMAIN_LOG_DIR, controllerLogDir); final String controllerCfgDir = WildFlySecurityManager.getPropertyPrivileged(JBOSS_DOMAIN_CONFIG_DIR, baseDir + File.separator + "configuration"); .setModuleLoader(ModuleLoader.forClass(getClass())) .setCommandArguments(cmds); } else { final ModelNode getNameOp = new ModelNode(); getNameOp.get(ClientConstants.OP).set(ClientConstants.READ_ATTRIBUTE_OPERATION); getNameOp.get(ClientConstants.NAME).set(Util.LOCAL_HOST_NAME);
protected void recoverServices(OperationContext context, ModelNode operation, ModelNode model) { final String driverName = model.require(DRIVER_NAME.getName()).asString(); final String moduleName = model.require(DRIVER_MODULE_NAME.getName()).asString(); final Integer majorVersion = model.hasDefined(DRIVER_MAJOR_VERSION.getName()) ? model.get(DRIVER_MAJOR_VERSION.getName()).asInt() : null; final Integer minorVersion = model.hasDefined(DRIVER_MINOR_VERSION.getName()) ? model.get(DRIVER_MINOR_VERSION.getName()).asInt() : null; final Module module; try { moduleId = ModuleIdentifier.fromString(moduleName); module = Module.getCallerModuleLoader().loadModule(moduleId); } catch (ModuleNotFoundException e) { context.getFailureDescription().set(ConnectorLogger.ROOT_LOGGER.missingDependencyInModuleDriver(moduleName, e.getMessage())); final ServiceLoader<Driver> serviceLoader = module.loadService(Driver.class); if (serviceLoader != null) for (Driver driver : serviceLoader) { final Class<? extends Driver> driverClass = module.getClassLoader().loadClass(driverClassName) .asSubclass(Driver.class); final Constructor<? extends Driver> constructor = driverClass.getConstructor();
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { final ModelNode address = operation.require(OP_ADDR); final String driverName = PathAddress.pathAddress(address).getLastElement().getValue(); if (operation.get(DRIVER_NAME.getName()).isDefined() && !driverName.equals(operation.get(DRIVER_NAME.getName()).asString())) { throw ConnectorLogger.ROOT_LOGGER.driverNameAndResourceNameNotEquals(operation.get(DRIVER_NAME.getName()).asString(), driverName); moduleId = ModuleIdentifier.create(moduleName, slot); module = Module.getCallerModuleLoader().loadModule(moduleId); } catch (ModuleNotFoundException e) { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.missingDependencyInModuleDriver(moduleName, e.getMessage()), e); Class<? extends DataSource> dsCls; try { dsCls = module.getClassLoader().loadClass(dataSourceClassName).asSubclass(DataSource.class); } catch (ClassNotFoundException | ClassCastException e) { throw SUBSYSTEM_DATASOURCES_LOGGER.failedToLoadDataSourceClass(dataSourceClassName, e); Class<? extends XADataSource> dsCls; try { dsCls = module.getClassLoader().loadClass(xaDataSourceClassName).asSubclass(XADataSource.class); } catch (ClassNotFoundException | ClassCastException e) { throw SUBSYSTEM_DATASOURCES_LOGGER.failedToLoadDataSourceClass(xaDataSourceClassName, e); } else { try { final Class<? extends Driver> driverClass = module.getClassLoader().loadClass(driverClassName) .asSubclass(Driver.class); final Constructor<? extends Driver> constructor = driverClass.getConstructor();
private ObjectFactory createObjectFactory(OperationContext context, ModelNode model) throws OperationFailedException { final ModuleIdentifier moduleID = ModuleIdentifier.fromString(NamingBindingResourceDefinition.MODULE.resolveModelAttribute(context, model).asString()); final String className = NamingBindingResourceDefinition.CLASS.resolveModelAttribute(context, model).asString(); final Module module; try { module = Module.getBootModuleLoader().loadModule(moduleID); } catch (ModuleNotFoundException e) { throw NamingLogger.ROOT_LOGGER.moduleNotFound(moduleID, e.getMessage()); } catch (ModuleLoadException e) { throw NamingLogger.ROOT_LOGGER.couldNotLoadModule(moduleID); } final ObjectFactory objectFactoryClassInstance; final ClassLoader cl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged(); try { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(module.getClassLoader()); final Class<?> clazz = module.getClassLoader().loadClass(className); objectFactoryClassInstance = (ObjectFactory) clazz.newInstance(); } catch (ClassNotFoundException e) { throw NamingLogger.ROOT_LOGGER.couldNotLoadClassFromModule(className, moduleID); } catch (InstantiationException e) { throw NamingLogger.ROOT_LOGGER.couldNotInstantiateClassInstanceFromModule(className, moduleID); } catch (IllegalAccessException e) { throw NamingLogger.ROOT_LOGGER.couldNotInstantiateClassInstanceFromModule(className, moduleID); } catch (ClassCastException e) { throw NamingLogger.ROOT_LOGGER.notAnInstanceOfObjectFactory(className, moduleID); } finally { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(cl); } return objectFactoryClassInstance; }
@Override public HttpHandler createHttpHandler(Predicate predicate, ModelNode model, HttpHandler next) { String expression = model.get(EXPRESSION.getName()).asString(); String moduleName = null; if (model.hasDefined(MODULE.getName())) { moduleName = model.get(MODULE.getName()).asString(); } ClassLoader classLoader; if (moduleName == null) { classLoader = getClass().getClassLoader(); } else { try { ModuleLoader moduleLoader = Module.getBootModuleLoader(); Module filterModule = moduleLoader.loadModule(ModuleIdentifier.fromString(moduleName)); classLoader = filterModule.getClassLoader(); } catch (ModuleLoadException e) { throw UndertowLogger.ROOT_LOGGER.couldNotLoadHandlerFromModule(expression, moduleName, e); } } List<PredicatedHandler> handlers = PredicatedHandlersParser.parse(expression, classLoader); UndertowLogger.ROOT_LOGGER.debugf("Creating http handler %s from module %s", expression, moduleName); if (predicate != null) { return Handlers.predicate(predicate, Handlers.predicates(handlers, next), next); } else { return Handlers.predicates(handlers, next); } }
if (node != null && node.isDefined()) { for (ModelNode permissionNode : node.asList()) { String permissionClass = CLASS.resolveModelAttribute(context, permissionNode).asString(); String permissionName = null; if (permissionNode.hasDefined(PERMISSION_NAME)) moduleName = 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);
private void addNeo4jCDIDependency(ModuleSpecification moduleSpecification, ModuleLoader moduleLoader, String nosqlDriverModuleName) { try { moduleLoader.loadModule(ModuleIdentifier.fromString(nosqlDriverModuleName)).getClassLoader().loadClass(NoSQLConstants.NEO4JDRIVERCLASS); } catch (ClassNotFoundException expected) { // ignore CNFE which just means that module is not a Neo4j module return; } catch (ModuleLoadException e) { throw new RuntimeException("could not load NoSQL driver module " + nosqlDriverModuleName, e); } // only reach this point if module is a Neo4j driver ModuleIdentifier mongoCDIExtensionModule = ModuleIdentifier.create(NoSQLConstants.NEO4JCDIEXTENSIONMODULE); addDependency(moduleSpecification, moduleLoader, mongoCDIExtensionModule); }
private Module getModule(ModelNode moduleNode) { Module module; if (moduleNode.isDefined()) { ModuleLoader moduleLoader = Module.getBootModuleLoader(); try { module = moduleLoader.loadModule(ModuleIdentifier.fromString(moduleNode.asString())); } catch (ModuleLoadException e) { throw ROOT_LOGGER.moduleCouldNotLoad(moduleNode.asString(), e); } } else { // fallback to caller module. module = Module.getCallerModule(); } return module; }
@Override public final P createProtocol(ProtocolStackConfiguration stackConfiguration) { // A "native" protocol is one that is not specified as a class name boolean nativeProtocol = this.moduleName.equals(AbstractProtocolResourceDefinition.Attribute.MODULE.getDefinition().getDefaultValue().asString()) && !this.name.startsWith(org.jgroups.conf.ProtocolConfiguration.protocol_prefix); String className = nativeProtocol ? String.join(".", org.jgroups.conf.ProtocolConfiguration.protocol_prefix, this.name) : this.name; try { Module module = this.loader.get().loadModule(this.moduleName); Class<? extends Protocol> protocolClass = module.getClassLoader().loadClass(className).asSubclass(Protocol.class); Map<String, String> properties = new HashMap<>(this.defaults.get().getProperties(protocolClass)); properties.putAll(this.properties); PrivilegedExceptionAction<Protocol> action = () -> { try { return protocolClass.newInstance().setProperties(properties); } catch (InstantiationException | IllegalAccessException e) { throw new IllegalStateException(e); } }; @SuppressWarnings("unchecked") P protocol = (P) WildFlySecurityManager.doUnchecked(action); this.accept(protocol); protocol.enableStats(this.statisticsEnabled != null ? this.statisticsEnabled : stackConfiguration.isStatisticsEnabled()); return protocol; } catch (Exception e) { throw new IllegalArgumentException(e); } } }
protected Class<?> getHandlerClass(String className, String moduleName) { ModuleLoader moduleLoader = Module.getBootModuleLoader(); try { Module filterModule = moduleLoader.loadModule(ModuleIdentifier.fromString(moduleName)); return filterModule.getClassLoader().loadClassLocal(className); } catch (ModuleLoadException | ClassNotFoundException e) { throw UndertowLogger.ROOT_LOGGER.couldNotLoadHandlerFromModule(className,moduleName,e); } }
static Class<? extends Protocol> findProtocolClass(OperationContext context, String protocolName, String moduleName) throws OperationFailedException { String className = protocolName; if (moduleName.equals(AbstractProtocolResourceDefinition.Attribute.MODULE.getDefinition().getDefaultValue().asString()) && !protocolName.startsWith(org.jgroups.conf.ProtocolConfiguration.protocol_prefix)) { className = String.join(".", org.jgroups.conf.ProtocolConfiguration.protocol_prefix, protocolName); } try { return Module.getContextModuleLoader().loadModule(moduleName).getClassLoader().loadClass(className).asSubclass(Protocol.class); } catch (ClassNotFoundException | ModuleLoadException e) { throw JGroupsLogger.ROOT_LOGGER.unableToLoadProtocolClass(className); } } }
protected void emitReady() throws Exception { Module module = Module.getBootModuleLoader().loadModule("swarm.container"); Class<?> messagesClass = module.getClassLoader().loadClass("org.wildfly.swarm.internal.SwarmMessages"); Field field = messagesClass.getDeclaredField("MESSAGES"); Object messages = field.get(null); Method ready = messages.getClass().getMethod("wildflySwarmIsReady"); ready.invoke(messages); }
private static Class<?> loadClass(String driverName, String moduleName, String className) throws IllegalArgumentException { try { Module module = Module.getCallerModuleLoader().loadModule(moduleName); AgroalLogger.DRIVER_LOGGER.debugf("loaded module '%s' for driver: %s", moduleName, driverName); Class<?> providerClass = module.getClassLoader().loadClass(className); AgroalLogger.DRIVER_LOGGER.driverLoaded(className, driverName); return providerClass; } catch (ModuleLoadException e) { throw AgroalLogger.DRIVER_LOGGER.loadModuleException(e, moduleName); } catch (ClassNotFoundException e) { throw AgroalLogger.DRIVER_LOGGER.loadClassException(e, className); } }
public void startBridge() throws Exception { final Module module; if (moduleName != null) { ModuleIdentifier moduleID = ModuleIdentifier.fromString(moduleName); module = Module.getContextModuleLoader().loadModule(moduleID); } else { module = Module.forClass(JMSBridgeService.class); } ClassLoader oldTccl= WildFlySecurityManager.getCurrentContextClassLoaderPrivileged(); try { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(module.getClassLoader()); setJMSBridgePasswordsFromCredentialSource(); bridge.start(); } finally { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl); } MessagingLogger.ROOT_LOGGER.startedService("JMS Bridge", bridgeName); }
className = CLASS.resolveModelAttribute(context, model).asString(); moduleName = MODULE.resolveModelAttribute(context, model).asString(); } else { className = type.getName(); final ModuleLoader moduleLoader = ModuleLoader.forClass(HandlerOperations.class); final ModuleIdentifier id = ModuleIdentifier.create(moduleName); try { final Class<?> actualClass = Class.forName(className, false, moduleLoader.loadModule(id).getClassLoader()); if (Appender.class.isAssignableFrom(actualClass)) {
static ClassLoader getClassLoader(final String moduleName) throws Exception { ModuleLoader moduleLoader = ModuleLoader.forClass(ModuleFinder.class); if (moduleLoader == null) { moduleLoader = Module.getBootModuleLoader(); } return moduleLoader.loadModule(ModuleIdentifier.fromString(moduleName)).getClassLoader(); } }