org.jboss.modules.ModuleLoadException Java Examples

The following examples show how to use org.jboss.modules.ModuleLoadException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServiceModuleLoader.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public ModuleSpec findModule(ModuleIdentifier identifier) throws ModuleLoadException {
    ServiceController<ModuleDefinition> controller = (ServiceController<ModuleDefinition>) serviceContainer.getService(moduleSpecServiceName(identifier));
    if (controller == null) {
        ServerLogger.MODULE_SERVICE_LOGGER.debugf("Could not load module '%s' as corresponding module spec service '%s' was not found", identifier, identifier);
        return null;
    }
    UninterruptibleCountDownLatch latch = new UninterruptibleCountDownLatch(1);
    ModuleSpecLoadListener listener = new ModuleSpecLoadListener(latch);
    try {
        synchronized (controller) {
            final State state = controller.getState();
            if (state == State.UP || state == State.START_FAILED) {
                listener.done(controller, controller.getStartException());
            }
        }
        controller.addListener(listener);
    } finally {
        latch.countDown();
    }
    return listener.getModuleSpec();
}
 
Example #2
Source File: StandaloneXMLConfigProducer.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Produces
@XMLConfig
public URL fromSwarmApplicationModule() {
    try {
        Module app = Module.getBootModuleLoader().loadModule("thorntail.application");
        ClassLoader cl = app.getClassLoader();
        URL result = cl.getResource(STANDALONE_XML_FILE);
        if (result != null) {
            SwarmConfigMessages.MESSAGES.loadingStandaloneXml("'thorntail.application' module", result.toExternalForm());
        }
        return result;
    } catch (ModuleLoadException e) {
        SwarmConfigMessages.MESSAGES.errorLoadingModule(e);
    }
    return null;
}
 
Example #3
Source File: FaviconHandler.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
public Response toResponse(NotFoundException e) {
    if (e.getMessage().contains("favicon.ico")) {
        try {
            Module module = Module.getBootModuleLoader().loadModule(ModuleIdentifier.create("org.wildfly.swarm.undertow", "runtime"));
            ClassLoader cl = module.getClassLoader();
            final InputStream in = cl.getResourceAsStream("favicon.ico");
            if (in != null) {
                Response.ResponseBuilder builder = Response.ok();
                builder.entity(in);
                return builder.build();
            }
        } catch (ModuleLoadException e1) {
            throw e;
        }
    }

    // can't handle it, rethrow.
    throw e;
}
 
Example #4
Source File: CommandLine.java    From thorntail with Apache License 2.0 6 votes vote down vote up
public void displayConfigHelp(PrintStream out, String fraction) throws IOException, ModuleLoadException {
    ModuleClassLoader cl = Module.getBootModuleLoader().loadModule("thorntail.application").getClassLoader();
    Enumeration<URL> docs = cl.getResources("META-INF/configuration-meta.properties");

    Properties props = new Properties();

    while (docs.hasMoreElements()) {
        URL each = docs.nextElement();
        Properties fractionDocs = new Properties();
        fractionDocs.load(each.openStream());
        if (fraction.equals(ALL) || fraction.equals(fractionDocs.getProperty(FRACTION))) {
            fractionDocs.remove(FRACTION);
            props.putAll(fractionDocs);
        }
    }

    props.stringPropertyNames().stream()
            .sorted()
            .forEach(key -> {
                out.println("# " + key);
                out.println();
                out.println(formatDocs("    ", props.getProperty(key)));
                out.println();
            });
}
 
Example #5
Source File: CommandLine.java    From thorntail with Apache License 2.0 6 votes vote down vote up
public void dumpYaml(PrintStream out, String fraction) throws IOException, ModuleLoadException {
    ModuleClassLoader cl = Module.getBootModuleLoader().loadModule("thorntail.application").getClassLoader();
    Enumeration<URL> docs = cl.getResources("META-INF/configuration-meta.properties");

    Properties props = new Properties();

    while (docs.hasMoreElements()) {
        URL each = docs.nextElement();
        Properties fractionDocs = new Properties();
        fractionDocs.load(each.openStream());
        if (fraction.equals(ALL) || fraction.equals(fractionDocs.getProperty(FRACTION))) {
            fractionDocs.remove(FRACTION);
            props.putAll(fractionDocs);
        }
    }

    YamlDumper.dump(out, props);
}
 
Example #6
Source File: CommandLine.java    From thorntail with Apache License 2.0 6 votes vote down vote up
/**
 * Apply properties and configuration from the parsed commandline to a container.
 *
 * @param swarm The Swarm instance to apply configuration to.
 * @throws IOException If an error occurs resolving any URL.
 */
public void apply(Swarm swarm) throws IOException, ModuleLoadException {
    applyProperties(swarm);
    applyConfigurations(swarm);

    if (get(HELP)) {
        displayVersion(System.err);
        System.err.println();
        displayHelp(System.err);
        System.exit(0);
    }

    if (get(CONFIG_HELP) != null) {
        displayConfigHelp(System.err, get(CONFIG_HELP));
        System.exit(0);
    }

    if (get(YAML_HELP) != null) {
        dumpYaml(System.err, get(YAML_HELP));
        System.exit(0);
    }

    if (get(VERSION)) {
        displayVersion(System.err);
    }
}
 
Example #7
Source File: DaemonServiceActivator.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
@Override
public void start(StartContext context) throws StartException {
    try {
        final String artifactName = System.getProperty(BootstrapProperties.APP_ARTIFACT);
        if (artifactName == null) {
            throw new StartException("Failed to find artifact name under " + BootstrapProperties.APP_ARTIFACT);
        }

        final ModuleLoader serviceLoader = this.serviceLoader.getValue();
        final String moduleName = "deployment." + artifactName;
        final Module module = serviceLoader.loadModule(ModuleIdentifier.create(moduleName));
        if (module == null) {
            throw new StartException("Failed to find deployment module under " + moduleName);
        }

        //TODO: allow overriding the default port?
        this.server = Server.create("localhost", 12345, module.getClassLoader());
        this.server.start();
    } catch (ModuleLoadException | ServerLifecycleException e) {
        throw new StartException(e);
    }
}
 
Example #8
Source File: Container.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
private void createShrinkWrapDomain() throws ModuleLoadException {
    ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
    try {
        if (isFatJar()) {
            Thread.currentThread().setContextClassLoader(Container.class.getClassLoader());
            Module appModule = Module.getBootModuleLoader().loadModule(ModuleIdentifier.create("swarm.application"));
            Thread.currentThread().setContextClassLoader(appModule.getClassLoader());
        }
        this.domain = ShrinkWrap.getDefaultDomain();
        this.domain.getConfiguration().getExtensionLoader().addOverride(ZipExporter.class, ZipExporterImpl.class);
        this.domain.getConfiguration().getExtensionLoader().addOverride(JavaArchive.class, JavaArchiveImpl.class);
        this.domain.getConfiguration().getExtensionLoader().addOverride(WebArchive.class, WebArchiveImpl.class);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        Thread.currentThread().setContextClassLoader(originalCl);
    }
}
 
Example #9
Source File: RuntimeServer.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unused")
public RuntimeServer() {
    try {
        Module loggingModule = Module.getBootModuleLoader().loadModule(ModuleIdentifier.create("org.wildfly.swarm.logging", "runtime"));

        ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
        try {
            Thread.currentThread().setContextClassLoader(loggingModule.getClassLoader());
            System.setProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager");
            System.setProperty("org.jboss.logmanager.configurator", LoggingConfigurator.class.getName());
            //force logging init
            LogManager.getLogManager();
            BootstrapLogger.setBackingLoggerManager(new JBossLoggingManager());
        } finally {
            Thread.currentThread().setContextClassLoader(originalCl);
        }
    } catch (ModuleLoadException e) {
        System.err.println("[WARN] logging not available, logging will not be configured");
    }
}
 
Example #10
Source File: LoggerContext.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void activate() {
    final Module logModule;
    try {
        logModule = moduleLoader.loadModule(MODULE_ID_LOGGING);
    } catch (final ModuleLoadException mle) {
        throw EmbeddedLogger.ROOT_LOGGER.moduleLoaderError(mle, MODULE_ID_LOGGING, moduleLoader);
    }

    final ModuleClassLoader logModuleClassLoader = logModule.getClassLoader();
    final ClassLoader tccl = getTccl();
    try {
        setTccl(logModuleClassLoader);
        loggerToRestore = Module.getModuleLogger();
        Module.setModuleLogger(new JBossLoggingModuleLogger());
    } finally {
        // Reset TCCL
        setTccl(tccl);
    }
}
 
Example #11
Source File: LoggerContext.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void restore() {
    final Module logModule;
    try {
        logModule = moduleLoader.loadModule(MODULE_ID_LOGGING);
    } catch (final ModuleLoadException mle) {
        throw EmbeddedLogger.ROOT_LOGGER.moduleLoaderError(mle, MODULE_ID_LOGGING, moduleLoader);
    }

    final ModuleClassLoader logModuleClassLoader = logModule.getClassLoader();
    final ClassLoader tccl = getTccl();
    try {
        setTccl(logModuleClassLoader);
        final ModuleLogger loggerToRestore = this.loggerToRestore;
        if (loggerToRestore == null) {
            Module.setModuleLogger(NoopModuleLogger.getInstance());
        } else {
            Module.setModuleLogger(loggerToRestore);
        }
    } finally {
        // Reset TCCL
        setTccl(tccl);
    }
}
 
Example #12
Source File: PlugInLoaderService.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private List<PlugInProvider> loadPlugInProvider(final String name) {
    synchronized (cachedProviders) {
        List<PlugInProvider> response;
        if (cachedProviders.containsKey(name)) {
            response = cachedProviders.get(name);
        } else {
            List<PlugInProvider> providers = new LinkedList<PlugInProvider>();
            try {
                for (PlugInProvider current : Module.loadServiceFromCallerModuleLoader(ModuleIdentifier.fromString(name),
                        PlugInProvider.class)) {
                    providers.add(current);
                }
            } catch (ModuleLoadException e) {
                throw DomainManagementLogger.ROOT_LOGGER.unableToLoadPlugInProviders(name, e.getMessage());
            }
            if (providers.size() > 0) {
                cachedProviders.put(name, providers);
                response = providers;
            } else {
                throw DomainManagementLogger.ROOT_LOGGER.noPlugInProvidersLoaded(name);
            }
        }
        return response;
    }
}
 
Example #13
Source File: LoggingDependencyDeploymentProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void deploy(final DeploymentPhaseContext phaseContext) {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();
    // Add the logging modules
    for (String moduleId : DUP_INJECTED_LOGGING_MODULES) {
        try {
            LoggingLogger.ROOT_LOGGER.tracef("Adding module '%s' to deployment '%s'", moduleId, deploymentUnit.getName());
            moduleLoader.loadModule(moduleId);
            moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, moduleId, false, false, false, false));
        } catch (ModuleLoadException ex) {
            LoggingLogger.ROOT_LOGGER.debugf("Module not found: %s", moduleId);
        }
    }
}
 
Example #14
Source File: Main.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void runBootableJar(Path jbossHome, List<String> arguments, Long unzipTime) throws Exception {
    final String modulePath = jbossHome.resolve(JBOSS_MODULES_DIR_NAME).toAbsolutePath().toString();
    ModuleLoader moduleLoader = setupModuleLoader(modulePath);
    final Module bootableJarModule;
    try {
        bootableJarModule = moduleLoader.loadModule(MODULE_ID_JAR_RUNTIME);
    } catch (final ModuleLoadException mle) {
        throw new Exception(mle);
    }

    final ModuleClassLoader moduleCL = bootableJarModule.getClassLoader();
    final Class<?> bjFactoryClass;
    try {
        bjFactoryClass = moduleCL.loadClass(BOOTABLE_JAR);
    } catch (final ClassNotFoundException cnfe) {
        throw new Exception(cnfe);
    }
    Method runMethod;
    try {
        runMethod = bjFactoryClass.getMethod(BOOTABLE_JAR_RUN_METHOD, Path.class, List.class, ModuleLoader.class, ModuleClassLoader.class, Long.class);
    } catch (final NoSuchMethodException nsme) {
        throw new Exception(nsme);
    }
    runMethod.invoke(null, jbossHome, arguments, moduleLoader, moduleCL, unzipTime);
}
 
Example #15
Source File: DeferredExtensionContext.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private XMLStreamException loadModule(final String moduleName, final XMLMapper xmlMapper) throws XMLStreamException {
    // Register element handlers for this extension
    try {
        final Module module = moduleLoader.loadModule(ModuleIdentifier.fromString(moduleName));
        boolean initialized = false;
        for (final Extension extension : module.loadService(Extension.class)) {
            ClassLoader oldTccl = WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(extension.getClass());
            try {
                extensionRegistry.initializeParsers(extension, moduleName, xmlMapper);
            } finally {
                WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
            }
            if (!initialized) {
                initialized = true;
            }
        }
        if (!initialized) {
            throw ControllerLogger.ROOT_LOGGER.notFound("META-INF/services/", Extension.class.getName(), module.getName());
        }
        return null;
    } catch (final ModuleLoadException e) {
        throw ControllerLogger.ROOT_LOGGER.failedToLoadModule(e);
    }
}
 
Example #16
Source File: CompositeIndexProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Index calculateModuleIndex(final Module module) throws ModuleLoadException, IOException {
    final Indexer indexer = new Indexer();
    final PathFilter filter = PathFilters.getDefaultImportFilter();
    final Iterator<Resource> iterator = module.iterateResources(filter);
    while (iterator.hasNext()) {
        Resource resource = iterator.next();
        if(resource.getName().endsWith(".class")) {
            try (InputStream in = resource.openStream()) {
                indexer.index(in);
            } catch (Exception e) {
                ServerLogger.DEPLOYMENT_LOGGER.cannotIndexClass(resource.getName(), resource.getURL().toExternalForm(), e);
            }
        }
    }
    return indexer.complete();
}
 
Example #17
Source File: ClassLoadingAttributeDefinitions.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static ClassLoader resolveClassLoader(String module) throws ModuleLoadException {
    Module current = Module.getCallerModule();
    if (module != null && current != null) {
        ModuleIdentifier mi = ModuleIdentifier.fromString(module);
        current = current.getModule(mi);
    }

    return current != null ? current.getClassLoader() : ClassLoadingAttributeDefinitions.class.getClassLoader();
}
 
Example #18
Source File: Swarm.java    From thorntail with Apache License 2.0 5 votes vote down vote up
private void initializeConfigFilters() throws ModuleLoadException, IOException, ClassNotFoundException {
    if (isFatJar()) {
        initializeConfigFiltersFatJar();
    } else {
        initializeConfigFiltersClassPath();
    }
}
 
Example #19
Source File: ConfigViewFactory.java    From thorntail with Apache License 2.0 5 votes vote down vote up
public static ConfigViewFactory defaultFactory(Properties properties, Map<String, String> environment) throws ModuleLoadException {
    return new ConfigViewFactory(
            properties,
            environment,
            new FilesystemConfigLocator(),
            ClassLoaderConfigLocator.system(),
            ClassLoaderConfigLocator.forApplication()
    );
}
 
Example #20
Source File: EmbeddedProcessFactory.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void setupVfsModule(final ModuleLoader moduleLoader) {
    final ModuleIdentifier vfsModuleID = ModuleIdentifier.create(MODULE_ID_VFS);
    final Module vfsModule;
    try {
        vfsModule = moduleLoader.loadModule(vfsModuleID);
    } catch (final ModuleLoadException mle) {
        throw EmbeddedLogger.ROOT_LOGGER.moduleLoaderError(mle,MODULE_ID_VFS, moduleLoader);
    }
    Module.registerURLStreamHandlerFactoryModule(vfsModule);
}
 
Example #21
Source File: ConsoleMode.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static ResourceHandlerDefinition createConsoleHandler(String slot, String resource) throws ModuleLoadException {
    final ClassPathResourceManager cpresource = new ClassPathResourceManager(getClassLoader(Module.getCallerModuleLoader(), ERROR_MODULE, slot), "");
    final io.undertow.server.handlers.resource.ResourceHandler handler = new io.undertow.server.handlers.resource.ResourceHandler(cpresource)
            .setAllowed(not(path("META-INF")))
            .setResourceManager(cpresource)
            .setDirectoryListingEnabled(false)
            .setCachable(Predicates.<HttpServerExchange>falsePredicate());

    //we also need to setup the default resource redirect
    PredicateHandler predicateHandler = new PredicateHandler(path("/"), new RedirectHandler(ExchangeAttributes.constant(CONTEXT + resource)), handler);
    return new ResourceHandlerDefinition(CONTEXT, resource, predicateHandler);
}
 
Example #22
Source File: AbstractSingleModuleFinder.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public ModuleSpec findModule(ModuleIdentifier identifier, ModuleLoader delegateLoader) throws ModuleLoadException {
    if (!identifier.getName().equals(this.moduleName) || !identifier.getSlot().equals(this.moduleSlot)) {
        return null;
    }

    ModuleSpec.Builder builder = ModuleSpec.build(identifier);
    buildModule(builder, delegateLoader);
    return builder.create();
}
 
Example #23
Source File: SecurityManagerSubsystemAdd.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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.
 */
private List<PermissionFactory> retrievePermissionSet(final OperationContext context, final ModelNode node) throws OperationFailedException {

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

    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))
                permissionName = NAME.resolveModelAttribute(context, permissionNode).asString();
            String permissionActions = null;
            if (permissionNode.hasDefined(PERMISSION_ACTIONS))
                permissionActions = ACTIONS.resolveModelAttribute(context, permissionNode).asString();
            String moduleName = null;
            if(permissionNode.hasDefined(PERMISSION_MODULE)) {
                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);
                }
            }

            permissions.add(new LoadedPermissionFactory(cl,
                    permissionClass, permissionName, permissionActions));
        }
    }
    return permissions;
}
 
Example #24
Source File: ApplyExtensionsHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void initializeExtension(String module, ManagementResourceRegistration rootRegistration) throws OperationFailedException {
    try {
        for (final Extension extension : Module.loadServiceFromCallerModuleLoader(ModuleIdentifier.fromString(module), Extension.class)) {
            ClassLoader oldTccl = SecurityActions.setThreadContextClassLoader(extension.getClass());
            try {
                extension.initializeParsers(extensionRegistry.getExtensionParsingContext(module, null));
                extension.initialize(extensionRegistry.getExtensionContext(module, rootRegistration, ExtensionRegistryType.SLAVE));
            } finally {
                SecurityActions.setThreadContextClassLoader(oldTccl);
            }
        }
    } catch (ModuleLoadException e) {
        throw DomainControllerLogger.ROOT_LOGGER.failedToLoadModule(e, module);
    }
}
 
Example #25
Source File: ArtifactManager.java    From thorntail with Apache License 2.0 5 votes vote down vote up
public JavaArchive artifact(String gav, String asName) throws IOException, ModuleLoadException {
    final File file = findFile(gav);

    if (file == null) {
        throw SwarmMessages.MESSAGES.artifactNotFound(gav);
    }

    return ShrinkWrap.create(ZipImporter.class, asName == null ? file.getName() : asName)
            .importFrom(file)
            .as(JavaArchive.class);
}
 
Example #26
Source File: Server.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void setupVfsModule(final ModuleLoader moduleLoader) {
    final Module vfsModule;
    try {
        vfsModule = moduleLoader.loadModule(MODULE_ID_VFS);
    } catch (final ModuleLoadException mle) {
        throw BootableJarLogger.ROOT_LOGGER.moduleLoaderError(mle, MODULE_ID_VFS, moduleLoader);
    }
    Module.registerURLStreamHandlerFactoryModule(vfsModule);
}
 
Example #27
Source File: ArtifactManager.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
public JavaArchive artifact(String gav, String asName) throws IOException, ModuleLoadException {
    final File file = findFile(gav);

    if (file == null) {
        throw new RuntimeException("Artifact not found.");
    }

    return ShrinkWrap.create(ZipImporter.class, asName == null ? file.getName() : asName)
            .importFrom(file)
            .as(JavaArchive.class);
}
 
Example #28
Source File: ModuleLoadingResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static List<String> findResourcePaths(String moduleName) throws ModuleLoadException, ReflectiveOperationException, IOException, URISyntaxException {
    ModuleLoader moduleLoader = Module.getCallerModuleLoader();
    ModuleLoaderMXBean loader = ModuleInfoHandler.INSTANCE.getMxBean(moduleLoader);
    moduleLoader.loadModule(ModuleIdentifier.fromString(moduleName));

    List<String> result = new LinkedList<>();
    for (ResourceLoaderInfo rl : loader.getResourceLoaders(moduleName)){
        if (rl.getLocation() != null) {
            URL url = new URL(rl.getLocation());

            switch (url.getProtocol()){

                case "jar": {
                    JarURLConnection jarConnection = (JarURLConnection)url.openConnection();
                    result.add(jarConnection.getJarFile().getName());

                    break;
                }
                default: {
                    result.add(new File(url.getFile() ).toString());
                }
            }
        }
    }

    return result;
}
 
Example #29
Source File: KeycloakThemesCustomizer.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Override
public void customize() throws ModuleLoadException, IOException {
    // KC iterates over the well-known folder and class-path theme provides when loading the themes.
    // When only a 'modules' property is set, KC still loads a FolderThemeResolver with a null 'dir' property.
    // Setting a 'dir' property to the current folder is a workaround to avoid FolderThemeResolver failing with
    // NPE for the class-path provider be able to load the themes resources.

    if (!this.keycloakServer.subresources().themes().isEmpty()) {
        this.keycloakServer.subresources().themes().stream().filter((t) -> t.modules() != null && t.dir() == null)
            .forEach((t) -> {
            t.dir(".");
        });
        if (combineDefaultAndCustomThemes.get()) {
            Theme<?> theme = this.keycloakServer.subresources().themes().get(0);
            theme.modules().add(0, "org.keycloak.keycloak-themes");
        }
    } else {

        this.keycloakServer.theme("defaults", (theme) -> {
            theme.module("org.keycloak.keycloak-themes")
                .staticmaxage(2592000L)
                .cachethemes(true)
                .cachetemplates(true)
                .dir(".");
        });
    }

}
 
Example #30
Source File: MPJWTLoginModuleCustomizer.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Override
public void customize() throws ModuleLoadException, IOException {
    final String realm = mpJwtFraction.getJwtRealm().get();
    if (!realm.isEmpty() && securityFraction.subresources().securityDomain(realm) == null) {
        securityFraction.securityDomain(realm, (domain) -> {
            domain.jaspiAuthentication((auth) -> {
                auth.loginModuleStack("roles-lm-stack", (stack) -> {
                    stack.loginModule("0", (module) -> {
                        module.code("org.wildfly.swarm.microprofile.jwtauth.deployment.auth.jaas.JWTLoginModule");
                        module.flag(Flag.REQUIRED);
                        if (mpJwtFraction.getRolesPropertiesMap() != null) {
                            module.moduleOption("rolesProperties", "autogenerated-roles.properties");
                        } else if (!mpJwtFraction.getRolesPropertiesFile().get().isEmpty()) {
                            module.moduleOption("rolesProperties", mpJwtFraction.getRolesPropertiesFile().get());
                        }
                    });
                });
                auth.authModule("http", (module) -> {
                    module.code("org.wildfly.extension.undertow.security.jaspi.modules.HTTPSchemeServerAuthModule");
                    module.module("org.wildfly.extension.undertow");
                    module.flag(Flag.REQUIRED);
                    module.loginModuleStackRef("roles-lm-stack");
                });
            });
        });
    }
}