parent
73c3517436
commit
5d2bf6ea33
3 changed files with 34 additions and 7 deletions
|
@ -23,6 +23,7 @@ import javax.script.ScriptEngine;
|
||||||
import javax.script.ScriptEngineManager;
|
import javax.script.ScriptEngineManager;
|
||||||
import javax.script.ScriptException;
|
import javax.script.ScriptException;
|
||||||
|
|
||||||
|
import org.jboss.logging.Logger;
|
||||||
import org.keycloak.models.ScriptModel;
|
import org.keycloak.models.ScriptModel;
|
||||||
import org.keycloak.platform.Platform;
|
import org.keycloak.platform.Platform;
|
||||||
import org.keycloak.services.ServicesLogger;
|
import org.keycloak.services.ServicesLogger;
|
||||||
|
@ -35,6 +36,8 @@ import org.keycloak.utils.ProxyClassLoader;
|
||||||
*/
|
*/
|
||||||
public class DefaultScriptingProvider implements ScriptingProvider {
|
public class DefaultScriptingProvider implements ScriptingProvider {
|
||||||
|
|
||||||
|
private static final Logger logger = Logger.getLogger(DefaultScriptingProvider.class);
|
||||||
|
|
||||||
private final DefaultScriptingProviderFactory factory;
|
private final DefaultScriptingProviderFactory factory;
|
||||||
|
|
||||||
DefaultScriptingProvider(DefaultScriptingProviderFactory factory) {
|
DefaultScriptingProvider(DefaultScriptingProviderFactory factory) {
|
||||||
|
@ -136,6 +139,8 @@ public class DefaultScriptingProvider implements ScriptingProvider {
|
||||||
scriptClassLoader = DefaultScriptingProvider.class.getClassLoader();
|
scriptClassLoader = DefaultScriptingProvider.class.getClassLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.debugf("Using classloader %s to load script engine", scriptClassLoader);
|
||||||
|
|
||||||
Thread.currentThread().setContextClassLoader(scriptClassLoader);
|
Thread.currentThread().setContextClassLoader(scriptClassLoader);
|
||||||
return new ScriptEngineManager().getEngineByMimeType(script.getMimeType());
|
return new ScriptEngineManager().getEngineByMimeType(script.getMimeType());
|
||||||
}
|
}
|
||||||
|
|
|
@ -255,15 +255,26 @@
|
||||||
<version>${mssql.driver.version}</version>
|
<version>${mssql.driver.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Nashorn -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.openjdk.nashorn</groupId>
|
|
||||||
<artifactId>nashorn-core</artifactId>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
<profiles>
|
<profiles>
|
||||||
|
|
||||||
|
<!-- Nashorn script engine needs to be manually added for the new Java versions as it is not part of the JDK anymore -->
|
||||||
|
<profile>
|
||||||
|
<id>jdk15</id>
|
||||||
|
<activation>
|
||||||
|
<jdk>[15,)</jdk>
|
||||||
|
</activation>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openjdk.nashorn</groupId>
|
||||||
|
<artifactId>nashorn-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</profile>
|
||||||
|
|
||||||
<profile>
|
<profile>
|
||||||
<id>keycloak-server</id>
|
<id>keycloak-server</id>
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -35,6 +35,9 @@ public class WildflyPlatform implements PlatformProvider {
|
||||||
// In this module, the attempt to load script engine will be done by default
|
// 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";
|
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;
|
Runnable shutdownHook;
|
||||||
|
|
||||||
private File tmpDir;
|
private File tmpDir;
|
||||||
|
@ -97,10 +100,18 @@ public class WildflyPlatform implements PlatformProvider {
|
||||||
} catch (ModuleLoadException mle) {
|
} catch (ModuleLoadException mle) {
|
||||||
if (WildflyUtil.getJavaVersion() >= 15) {
|
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);
|
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 {
|
} 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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue