[KEYCLOAK-11679] - Creating keys right after master realm creation

This commit is contained in:
Pedro Igor 2020-05-27 09:27:13 -03:00 committed by Stian Thorgersen
parent b6060c52b7
commit ee83f8c16f
4 changed files with 9 additions and 11 deletions

View file

@ -63,13 +63,13 @@ class KeycloakProcessor {
*/ */
@Record(ExecutionTime.STATIC_INIT) @Record(ExecutionTime.STATIC_INIT)
@BuildStep @BuildStep
void configureBuiltInProviders(KeycloakRecorder recorder, BuildProducer<BeanContainerListenerBuildItem> container) { void configureBuiltInProviders(KeycloakRecorder recorder) {
container.produce(new BeanContainerListenerBuildItem(recorder.configSessionFactory(loadBuiltInFactories()))); recorder.configSessionFactory(loadBuiltInFactories());
} }
private Map<Spi, Set<Class<? extends ProviderFactory>>> loadBuiltInFactories() { private Map<Spi, Set<Class<? extends ProviderFactory>>> loadBuiltInFactories() {
ProviderManager pm = new ProviderManager( ProviderManager pm = new ProviderManager(
KeycloakDeploymentInfo.create().services(), getClass().getClassLoader(), Config.scope().getArray("providers")); KeycloakDeploymentInfo.create().services(), Thread.currentThread().getContextClassLoader(), Config.scope().getArray("providers"));
Map<Spi, Set<Class<? extends ProviderFactory>>> result = new HashMap<>(); Map<Spi, Set<Class<? extends ProviderFactory>>> result = new HashMap<>();
for (Spi spi : pm.loadSpis()) { for (Spi spi : pm.loadSpis()) {

View file

@ -95,7 +95,7 @@ public final class QuarkusKeycloakSessionFactory extends DefaultKeycloakSessionF
private ProviderLoader createUserProviderLoader() { private ProviderLoader createUserProviderLoader() {
return UserProviderLoader return UserProviderLoader
.create(KeycloakDeploymentInfo.create().services(), getClass().getClassLoader()); .create(KeycloakDeploymentInfo.create().services(), Thread.currentThread().getContextClassLoader());
} }
private ProviderFactory lookupProviderFactory(Class<? extends ProviderFactory> factoryClazz) { private ProviderFactory lookupProviderFactory(Class<? extends ProviderFactory> factoryClazz) {

View file

@ -60,6 +60,7 @@ import org.keycloak.models.UserModel;
import org.keycloak.models.UserProvider; import org.keycloak.models.UserProvider;
import org.keycloak.models.dblock.DBLockManager; import org.keycloak.models.dblock.DBLockManager;
import org.keycloak.models.dblock.DBLockProvider; import org.keycloak.models.dblock.DBLockProvider;
import org.keycloak.models.utils.DefaultKeyProviders;
import org.keycloak.models.utils.KeycloakModelUtils; import org.keycloak.models.utils.KeycloakModelUtils;
import org.keycloak.models.utils.RepresentationToModel; import org.keycloak.models.utils.RepresentationToModel;
import org.keycloak.provider.ServerInfoAwareProviderFactory; import org.keycloak.provider.ServerInfoAwareProviderFactory;
@ -380,6 +381,8 @@ public class QuarkusJpaConnectionProviderFactory implements JpaConnectionProvide
if (createMasterRealm) { if (createMasterRealm) {
applianceBootstrap.createMasterRealm(); applianceBootstrap.createMasterRealm();
//TODO: Remove this to reduce startup time. See https://issues.redhat.com/browse/KEYCLOAK-14308.
DefaultKeyProviders.createProviders(session.getContext().getRealm());
} }
session.getTransactionManager().commit(); session.getTransactionManager().commit();

View file

@ -62,12 +62,7 @@ public class KeycloakRecorder {
}; };
} }
public BeanContainerListener configSessionFactory(Map<Spi, Set<Class<? extends ProviderFactory>>> factories) { public void configSessionFactory(Map<Spi, Set<Class<? extends ProviderFactory>>> factories) {
return new BeanContainerListener() {
@Override
public void created(BeanContainer container) {
QuarkusKeycloakSessionFactory.setInstance(new QuarkusKeycloakSessionFactory(factories)); QuarkusKeycloakSessionFactory.setInstance(new QuarkusKeycloakSessionFactory(factories));
} }
};
}
} }