Creating MongoDBSessionFactory in KeycloakApplication via reflection to avoid compile-time dependency on mongo module
This commit is contained in:
parent
453e1c5cf7
commit
6ac643c45b
2 changed files with 14 additions and 4 deletions
|
@ -1,7 +1,6 @@
|
|||
package org.keycloak.services.resources;
|
||||
|
||||
import org.keycloak.SkeletonKeyContextResolver;
|
||||
import org.keycloak.models.mongo.keycloak.adapters.MongoDBSessionFactory;
|
||||
import org.keycloak.services.managers.TokenManager;
|
||||
import org.keycloak.models.KeycloakSessionFactory;
|
||||
import org.keycloak.models.picketlink.PicketlinkKeycloakSession;
|
||||
|
@ -23,6 +22,8 @@ import javax.persistence.Persistence;
|
|||
import javax.servlet.ServletContext;
|
||||
import javax.ws.rs.core.Application;
|
||||
import javax.ws.rs.core.Context;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -76,7 +77,15 @@ public class KeycloakApplication extends Application {
|
|||
int port = PropertiesManager.getMongoPort();
|
||||
String dbName = PropertiesManager.getMongoDbName();
|
||||
boolean dropDatabaseOnStartup = PropertiesManager.dropDatabaseOnStartup();
|
||||
return new MongoDBSessionFactory(host, port, dbName, dropDatabaseOnStartup);
|
||||
|
||||
// Create MongoDBSessionFactory via reflection now
|
||||
try {
|
||||
Class<? extends KeycloakSessionFactory> mongoDBSessionFactoryClass = (Class<? extends KeycloakSessionFactory>)Class.forName("org.keycloak.models.mongo.keycloak.adapters.MongoDBSessionFactory");
|
||||
Constructor<? extends KeycloakSessionFactory> constr = mongoDBSessionFactoryClass.getConstructor(String.class, int.class, String.class, boolean.class);
|
||||
return constr.newInstance(host, port, dbName, dropDatabaseOnStartup);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public KeycloakSessionFactory getFactory() {
|
||||
|
|
|
@ -7,8 +7,6 @@ import org.apache.jorphan.logging.LoggingManager;
|
|||
import org.apache.log.Logger;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.mongo.keycloak.adapters.RealmAdapter;
|
||||
import org.keycloak.services.resources.KeycloakApplication;
|
||||
import org.keycloak.services.utils.PropertiesManager;
|
||||
|
||||
/**
|
||||
|
@ -45,6 +43,8 @@ public class RemoveUsersWorker implements Worker {
|
|||
|
||||
@Override
|
||||
public void run(SampleResult result, KeycloakSession identitySession) {
|
||||
throw new IllegalStateException("Not yet supported");
|
||||
/*
|
||||
int userNumber = ++userCounterInRealm;
|
||||
int totalUserNumber = totalUserCounter.incrementAndGet();
|
||||
|
||||
|
@ -63,6 +63,7 @@ public class RemoveUsersWorker implements Worker {
|
|||
|
||||
int labelC = ((totalUserNumber - 1) / NUMBER_OF_USERS_IN_EACH_REPORT) * NUMBER_OF_USERS_IN_EACH_REPORT;
|
||||
result.setSampleLabel("ReadUsers " + (labelC + 1) + "-" + (labelC + NUMBER_OF_USERS_IN_EACH_REPORT));
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue