Merge pull request #4049 from stianst/KEYCLOAK-4738
KEYCLOAK-4738 Make sure script engine always uses correct classloader
This commit is contained in:
commit
2a8b2aabb9
2 changed files with 21 additions and 8 deletions
|
@ -110,7 +110,13 @@ public class DefaultScriptingProvider implements ScriptingProvider {
|
||||||
* Looks-up a {@link ScriptEngine} based on the MIME-type provided by the given {@link Script}.
|
* Looks-up a {@link ScriptEngine} based on the MIME-type provided by the given {@link Script}.
|
||||||
*/
|
*/
|
||||||
private ScriptEngine lookupScriptEngineFor(ScriptModel script) {
|
private ScriptEngine lookupScriptEngineFor(ScriptModel script) {
|
||||||
return scriptEngineManager.getEngineByMimeType(script.getMimeType());
|
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||||
|
try {
|
||||||
|
Thread.currentThread().setContextClassLoader(DefaultScriptingProvider.class.getClassLoader());
|
||||||
|
return scriptEngineManager.getEngineByMimeType(script.getMimeType());
|
||||||
|
} finally {
|
||||||
|
Thread.currentThread().setContextClassLoader(cl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -29,9 +29,13 @@ public class DefaultScriptingProviderFactory implements ScriptingProviderFactory
|
||||||
|
|
||||||
static final String ID = "script-based-auth";
|
static final String ID = "script-based-auth";
|
||||||
|
|
||||||
|
private ScriptEngineManager scriptEngineManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScriptingProvider create(KeycloakSession session) {
|
public ScriptingProvider create(KeycloakSession session) {
|
||||||
return new DefaultScriptingProvider(ScriptEngineManagerHolder.SCRIPT_ENGINE_MANAGER);
|
lazyInit();
|
||||||
|
|
||||||
|
return new DefaultScriptingProvider(scriptEngineManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -54,11 +58,14 @@ public class DefaultScriptingProviderFactory implements ScriptingProviderFactory
|
||||||
return ID;
|
return ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private void lazyInit() {
|
||||||
* Holder class for lazy initialization of {@link ScriptEngineManager}.
|
if (scriptEngineManager == null) {
|
||||||
*/
|
synchronized (this) {
|
||||||
private static class ScriptEngineManagerHolder {
|
if (scriptEngineManager == null) {
|
||||||
|
scriptEngineManager = new ScriptEngineManager();
|
||||||
private static final ScriptEngineManager SCRIPT_ENGINE_MANAGER = new ScriptEngineManager();
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue