Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.hibernate.jpa.boot.internal.PersistenceXmlParser;
import org.hibernate.jpa.boot.spi.Bootstrap;
import org.keycloak.connections.jpa.entityprovider.JpaEntityProvider;
import org.keycloak.utils.ProxyClassLoader;
import org.keycloak.models.KeycloakSession;

import jakarta.persistence.EntityManager;
Expand Down Expand Up @@ -74,16 +73,15 @@ public static EntityManagerFactory createEntityManagerFactory(KeycloakSession se
// to find and load the extra provided entities.
persistenceUnit.setTransactionType(txType);
persistenceUnit.setValidationMode(ValidationMode.NONE.name());
return Bootstrap.getEntityManagerFactoryBuilder(persistenceUnit, properties,
new ProxyClassLoader(providedEntities)).build();
return Bootstrap.getEntityManagerFactoryBuilder(persistenceUnit, properties).build();
}
}
throw new RuntimeException("Persistence unit '" + unitName + "' not found");
}

/**
* Get a list of all provided entities by looping over all configured entity providers.
*
*
* @param session the keycloak session
* @return a list of all provided entities (can be an empty list)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.concurrent.atomic.AtomicBoolean;

import org.jboss.logging.Logger;
import org.keycloak.Config;
import org.keycloak.platform.PlatformProvider;
import org.keycloak.quarkus.runtime.Environment;

Expand Down Expand Up @@ -103,9 +102,4 @@ public File getTmpDirectory() {
return tmpDir;
}

@Override
public ClassLoader getScriptEngineClassLoader(Config.Scope scriptProviderConfig) {
// It is fine to return null assuming that nashorn and it's dependencies are included on the classpath (usually "providers" directory)
return null;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public interface PlatformProvider {

String name();

default void onStartup(Runnable runnable) {

}
Expand All @@ -41,17 +41,4 @@ default void onShutdown(Runnable runnable) {
*/
File getTmpDirectory();


/**
* Returns classloader to load script engine. Classloader should contain the implementation of {@link javax.script.ScriptEngineFactory}
* and it's definition inside META-INF/services of the jar file(s), which will be provided by this classloader.
*
* This method can return null and in that case, the default Keycloak services classloader will be used for load script engine. Note that java versions earlier than 15 always contain
* the "nashorn" script engine by default on the classpath (it is part of the Java platform itself) and hence for them it is always fine to return null (unless you want to override default engine)
*
* @param scriptProviderConfig Configuration scope of the "default" provider of "scripting" SPI. It can contain some config properties for the classloader (EG. file path)
* @return classloader or null
*/
ClassLoader getScriptEngineClassLoader(Config.Scope scriptProviderConfig);

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.keycloak.models.ScriptModel;
import org.keycloak.platform.Platform;
import org.keycloak.services.ServicesLogger;
import org.keycloak.utils.ProxyClassLoader;

/**
* A {@link ScriptingProvider} that uses a {@link ScriptEngineManager} to evaluate scripts with a {@link ScriptEngine}.
Expand Down Expand Up @@ -128,24 +127,6 @@ private ScriptEngine getPreparedScriptEngine(ScriptModel script) {
* Looks-up a {@link ScriptEngine} based on the MIME-type provided by the given {@link Script}.
*/
private ScriptEngine lookupScriptEngineFor(ScriptModel script) {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
try {
ClassLoader scriptClassLoader = Platform.getPlatform().getScriptEngineClassLoader(factory.getConfig());

// Also need to use classloader of keycloak services itself to be able to use keycloak classes in the scripts
if (scriptClassLoader != null) {
scriptClassLoader = new ProxyClassLoader(scriptClassLoader, DefaultScriptingProvider.class.getClassLoader());
} else {
scriptClassLoader = DefaultScriptingProvider.class.getClassLoader();
}

logger.debugf("Using classloader %s to load script engine", scriptClassLoader);

Thread.currentThread().setContextClassLoader(scriptClassLoader);
return new ScriptEngineManager().getEngineByMimeType(script.getMimeType());
}
finally {
Thread.currentThread().setContextClassLoader(cl);
}
return new ScriptEngineManager().getEngineByMimeType(script.getMimeType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.nio.file.Files;

import org.jboss.logging.Logger;
import org.keycloak.Config;
import org.keycloak.common.Profile;
import org.keycloak.common.profile.PropertiesFileProfileConfigResolver;
import org.keycloak.common.profile.PropertiesProfileConfigResolver;
Expand Down Expand Up @@ -87,9 +86,4 @@ public File getTmpDirectory() {
return tmpDir;
}

@Override
public ClassLoader getScriptEngineClassLoader(Config.Scope scriptProviderConfig) {
// It is fine to return null as nashorn should be automatically included on the classpath of testsuite utils
return null;
}
}