From 5d2bf6ea337380f74c2288fce5e1207fea6e07a4 Mon Sep 17 00:00:00 2001 From: mposolda Date: Mon, 6 Jun 2022 21:04:31 +0200 Subject: [PATCH] Cannot find ScriptEngine for JDK8 and Wildfly Closes #12247 --- .../scripting/DefaultScriptingProvider.java | 5 +++++ testsuite/utils/pom.xml | 21 ++++++++++++++----- .../provider/wildfly/WildflyPlatform.java | 15 +++++++++++-- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/services/src/main/java/org/keycloak/scripting/DefaultScriptingProvider.java b/services/src/main/java/org/keycloak/scripting/DefaultScriptingProvider.java index edad67081c..dc42513673 100644 --- a/services/src/main/java/org/keycloak/scripting/DefaultScriptingProvider.java +++ b/services/src/main/java/org/keycloak/scripting/DefaultScriptingProvider.java @@ -23,6 +23,7 @@ import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; +import org.jboss.logging.Logger; import org.keycloak.models.ScriptModel; import org.keycloak.platform.Platform; import org.keycloak.services.ServicesLogger; @@ -35,6 +36,8 @@ import org.keycloak.utils.ProxyClassLoader; */ public class DefaultScriptingProvider implements ScriptingProvider { + private static final Logger logger = Logger.getLogger(DefaultScriptingProvider.class); + private final DefaultScriptingProviderFactory factory; DefaultScriptingProvider(DefaultScriptingProviderFactory factory) { @@ -136,6 +139,8 @@ public class DefaultScriptingProvider implements ScriptingProvider { scriptClassLoader = DefaultScriptingProvider.class.getClassLoader(); } + logger.debugf("Using classloader %s to load script engine", scriptClassLoader); + Thread.currentThread().setContextClassLoader(scriptClassLoader); return new ScriptEngineManager().getEngineByMimeType(script.getMimeType()); } diff --git a/testsuite/utils/pom.xml b/testsuite/utils/pom.xml index cd3f2ca004..8f345ccc92 100755 --- a/testsuite/utils/pom.xml +++ b/testsuite/utils/pom.xml @@ -255,15 +255,26 @@ ${mssql.driver.version} - - - org.openjdk.nashorn - nashorn-core - + + + + jdk15 + + [15,) + + + + + org.openjdk.nashorn + nashorn-core + + + + keycloak-server diff --git a/wildfly/extensions/src/main/java/org/keycloak/provider/wildfly/WildflyPlatform.java b/wildfly/extensions/src/main/java/org/keycloak/provider/wildfly/WildflyPlatform.java index 4855b54cf6..e772efb992 100644 --- a/wildfly/extensions/src/main/java/org/keycloak/provider/wildfly/WildflyPlatform.java +++ b/wildfly/extensions/src/main/java/org/keycloak/provider/wildfly/WildflyPlatform.java @@ -35,6 +35,9 @@ public class WildflyPlatform implements PlatformProvider { // In this module, the attempt to load script engine will be done by default private static final String DEFAULT_SCRIPT_ENGINE_MODULE = "org.openjdk.nashorn.nashorn-core"; + // Module name for deployment of keycloak server + private static final String DEPLOYMENT_MODULE_NAME = "deployment.keycloak-server.war"; + Runnable shutdownHook; private File tmpDir; @@ -97,10 +100,18 @@ public class WildflyPlatform implements PlatformProvider { } catch (ModuleLoadException mle) { if (WildflyUtil.getJavaVersion() >= 15) { log.warnf("Cannot find script engine in the JBoss module '%s'. Please add JavaScript engine to the specified JBoss Module or make sure it is available on the classpath", engineModule); + return null; } else { - log.debugf("Cannot find script engine in the JBoss module '%s'. Will fallback to the default script engine", engineModule); + try { + Module module = Module.getContextModuleLoader().loadModule(ModuleIdentifier.fromString(DEPLOYMENT_MODULE_NAME)); + log.debugf("Cannot find script engine in the JBoss module '%s'. Will fallback to the default script engine available from the module '%s'", engineModule, DEPLOYMENT_MODULE_NAME); + return module.getClassLoader(); + } catch (ModuleLoadException mle2) { + // Should not happen + log.warnf("Cannot find script engine in the JBoss module '%s' and in the module '%s'. Please add JavaScript engine to the specified JBoss Module or make sure it is available on the classpath", engineModule, DEPLOYMENT_MODULE_NAME); + return null; + } } - return null; } } }