Merge pull request #642 from patriot1burke/master
import console from export
This commit is contained in:
commit
ca97e7ba35
8 changed files with 661 additions and 617 deletions
|
@ -18,6 +18,7 @@ import org.keycloak.models.UserModel;
|
|||
import org.keycloak.models.UserSessionProvider;
|
||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||
import org.keycloak.models.utils.RepresentationToModel;
|
||||
import org.keycloak.representations.idm.ApplicationRepresentation;
|
||||
import org.keycloak.representations.idm.RealmAuditRepresentation;
|
||||
import org.keycloak.representations.idm.RealmRepresentation;
|
||||
import org.keycloak.timer.TimerProvider;
|
||||
|
@ -115,6 +116,10 @@ public class RealmManager {
|
|||
return "realm-management";
|
||||
}
|
||||
|
||||
public String getRealmAdminApplicationName(RealmRepresentation realm) {
|
||||
return "realm-management";
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void setupRealmDefaults(RealmModel realm) {
|
||||
|
@ -208,21 +213,62 @@ public class RealmManager {
|
|||
if (id == null) {
|
||||
id = KeycloakModelUtils.generateId();
|
||||
}
|
||||
RealmModel realm = createRealm(id, rep.getRealm());
|
||||
importRealm(rep, realm);
|
||||
RealmModel realm = model.createRealm(id, rep.getRealm());
|
||||
realm.setName(rep.getRealm());
|
||||
|
||||
// setup defaults
|
||||
|
||||
setupRealmDefaults(realm);
|
||||
setupMasterAdminManagement(realm);
|
||||
if (!hasRealmAdminManagementApp(rep)) setupRealmAdminManagement(realm);
|
||||
if (!hasAccountManagementApp(rep)) setupAccountManagement(realm);
|
||||
if (!hasAdminConsoleApp(rep)) setupAdminConsole(realm);
|
||||
|
||||
RepresentationToModel.importRealm(session, rep, realm);
|
||||
|
||||
|
||||
if (realm.getAuditListeners().size() == 0) {
|
||||
realm.setAuditListeners(Collections.singleton("jboss-logging"));
|
||||
}
|
||||
|
||||
// Refresh periodic sync tasks for configured federationProviders
|
||||
List<UserFederationProviderModel> federationProviders = realm.getUserFederationProviders();
|
||||
UsersSyncManager usersSyncManager = new UsersSyncManager();
|
||||
for (final UserFederationProviderModel fedProvider : federationProviders) {
|
||||
usersSyncManager.refreshPeriodicSyncForProvider(session.getKeycloakSessionFactory(), session.getProvider(TimerProvider.class), fedProvider, realm.getId());
|
||||
}
|
||||
return realm;
|
||||
}
|
||||
|
||||
public void importRealm(RealmRepresentation rep, RealmModel newRealm) {
|
||||
RepresentationToModel.importRealm(session, rep, newRealm);
|
||||
|
||||
// Refresh periodic sync tasks for configured federationProviders
|
||||
List<UserFederationProviderModel> federationProviders = newRealm.getUserFederationProviders();
|
||||
UsersSyncManager usersSyncManager = new UsersSyncManager();
|
||||
for (final UserFederationProviderModel fedProvider : federationProviders) {
|
||||
usersSyncManager.refreshPeriodicSyncForProvider(session.getKeycloakSessionFactory(), session.getProvider(TimerProvider.class), fedProvider, newRealm.getId());
|
||||
private boolean hasRealmAdminManagementApp(RealmRepresentation rep) {
|
||||
if (rep.getApplications() == null) return false;
|
||||
for (ApplicationRepresentation app : rep.getApplications()) {
|
||||
if (app.getName().equals(getRealmAdminApplicationName(rep))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean hasAccountManagementApp(RealmRepresentation rep) {
|
||||
if (rep.getApplications() == null) return false;
|
||||
for (ApplicationRepresentation app : rep.getApplications()) {
|
||||
if (app.getName().equals(Constants.ACCOUNT_MANAGEMENT_APP)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean hasAdminConsoleApp(RealmRepresentation rep) {
|
||||
if (rep.getApplications() == null) return false;
|
||||
for (ApplicationRepresentation app : rep.getApplications()) {
|
||||
if (app.getName().equals(Constants.ADMIN_CONSOLE_APPLICATION)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query users based on a search string:
|
||||
|
|
|
@ -217,8 +217,7 @@ public class KeycloakApplication extends Application {
|
|||
return;
|
||||
}
|
||||
|
||||
RealmModel realm = manager.createRealm(rep.getId(), rep.getRealm());
|
||||
manager.importRealm(rep, realm);
|
||||
RealmModel realm = manager.importRealm(rep);
|
||||
|
||||
log.info("Imported realm " + realm.getName() + " from " + from);
|
||||
|
||||
|
|
|
@ -246,8 +246,7 @@ public class KeycloakServer {
|
|||
return;
|
||||
}
|
||||
manager.setContextPath("/auth");
|
||||
RealmModel realm = manager.createRealm(rep.getId(), rep.getRealm());
|
||||
manager.importRealm(rep, realm);
|
||||
RealmModel realm = manager.importRealm(rep);
|
||||
|
||||
info("Imported realm " + realm.getName());
|
||||
|
||||
|
|
|
@ -53,9 +53,9 @@ public class CompositeImportRoleTest {
|
|||
public static AbstractKeycloakRule keycloakRule = new AbstractKeycloakRule(){
|
||||
@Override
|
||||
protected void configure(KeycloakSession session, RealmManager manager, RealmModel adminRealm) {
|
||||
RealmModel realm = manager.createRealm("Test");
|
||||
RealmRepresentation representation = KeycloakServer.loadJson(getClass().getResourceAsStream("/testcomposite.json"), RealmRepresentation.class);
|
||||
manager.importRealm(representation, realm);
|
||||
representation.setId("Test");
|
||||
RealmModel realm = manager.importRealm(representation);
|
||||
|
||||
realmPublicKey = realm.getPublicKey();
|
||||
|
||||
|
|
|
@ -103,8 +103,8 @@ public class ExportImportTest {
|
|||
// Import "test-realm" realm
|
||||
try {
|
||||
RealmRepresentation rep = AbstractModelTest.loadJson("model/testrealm.json");
|
||||
RealmModel demoRealm = manager.createRealm("test-realm", rep.getRealm());
|
||||
manager.importRealm(rep, demoRealm);
|
||||
rep.setId("test-realm");
|
||||
RealmModel demoRealm = manager.importRealm(rep);
|
||||
} catch (IOException ioe) {
|
||||
throw new RuntimeException(ioe);
|
||||
}
|
||||
|
|
|
@ -24,8 +24,8 @@ public class CompositeRolesModelTest extends AbstractModelTest {
|
|||
super.before();
|
||||
RealmManager manager = realmManager;
|
||||
RealmRepresentation rep = AbstractModelTest.loadJson("model/testcomposites.json");
|
||||
RealmModel realm = manager.createRealm("TestComposites", rep.getRealm());
|
||||
manager.importRealm(rep, realm);
|
||||
rep.setId("TestComposites");
|
||||
RealmModel realm = manager.importRealm(rep);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -43,8 +43,8 @@ public class ImportTest extends AbstractModelTest {
|
|||
@Test
|
||||
public void install() throws Exception {
|
||||
RealmRepresentation rep = AbstractModelTest.loadJson("model/testrealm.json");
|
||||
RealmModel realm = realmManager.createRealm("demo", rep.getRealm());
|
||||
realmManager.importRealm(rep, realm);
|
||||
rep.setId("demo");
|
||||
RealmModel realm = realmManager.importRealm(rep);
|
||||
|
||||
// Commit after import
|
||||
commit();
|
||||
|
@ -216,8 +216,8 @@ public class ImportTest extends AbstractModelTest {
|
|||
public void install2() throws Exception {
|
||||
RealmManager manager = realmManager;
|
||||
RealmRepresentation rep = AbstractModelTest.loadJson("model/testrealm-demo.json");
|
||||
RealmModel realm = manager.createRealm("demo", rep.getRealm());
|
||||
manager.importRealm(rep, realm);
|
||||
rep.setId("demo");
|
||||
RealmModel realm =manager.importRealm(rep);
|
||||
|
||||
Assert.assertFalse(realm.isUpdateProfileOnInitialSocialLogin());
|
||||
Assert.assertEquals(600, realm.getAccessCodeLifespanUserAction());
|
||||
|
|
|
@ -69,8 +69,8 @@ public class ModelTest extends AbstractModelTest {
|
|||
private RealmModel importExport(RealmModel src, String copyName) {
|
||||
RealmRepresentation representation = ModelToRepresentation.toRepresentation(src);
|
||||
representation.setRealm(copyName);
|
||||
RealmModel copy = realmManager.createRealm(copyName);
|
||||
realmManager.importRealm(representation, copy);
|
||||
representation.setId(copyName);
|
||||
RealmModel copy = realmManager.importRealm(representation);
|
||||
return realmManager.getRealm(copy.getId());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue