import console from export
This commit is contained in:
parent
7c8edb5d11
commit
e99afec7ec
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.UserSessionProvider;
|
||||||
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.representations.idm.ApplicationRepresentation;
|
||||||
import org.keycloak.representations.idm.RealmAuditRepresentation;
|
import org.keycloak.representations.idm.RealmAuditRepresentation;
|
||||||
import org.keycloak.representations.idm.RealmRepresentation;
|
import org.keycloak.representations.idm.RealmRepresentation;
|
||||||
import org.keycloak.timer.TimerProvider;
|
import org.keycloak.timer.TimerProvider;
|
||||||
|
@ -115,6 +116,10 @@ public class RealmManager {
|
||||||
return "realm-management";
|
return "realm-management";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getRealmAdminApplicationName(RealmRepresentation realm) {
|
||||||
|
return "realm-management";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected void setupRealmDefaults(RealmModel realm) {
|
protected void setupRealmDefaults(RealmModel realm) {
|
||||||
|
@ -208,20 +213,61 @@ public class RealmManager {
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
id = KeycloakModelUtils.generateId();
|
id = KeycloakModelUtils.generateId();
|
||||||
}
|
}
|
||||||
RealmModel realm = createRealm(id, rep.getRealm());
|
RealmModel realm = model.createRealm(id, rep.getRealm());
|
||||||
importRealm(rep, realm);
|
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;
|
return realm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void importRealm(RealmRepresentation rep, RealmModel newRealm) {
|
private boolean hasRealmAdminManagementApp(RealmRepresentation rep) {
|
||||||
RepresentationToModel.importRealm(session, rep, newRealm);
|
if (rep.getApplications() == null) return false;
|
||||||
|
for (ApplicationRepresentation app : rep.getApplications()) {
|
||||||
// Refresh periodic sync tasks for configured federationProviders
|
if (app.getName().equals(getRealmAdminApplicationName(rep))) {
|
||||||
List<UserFederationProviderModel> federationProviders = newRealm.getUserFederationProviders();
|
return true;
|
||||||
UsersSyncManager usersSyncManager = new UsersSyncManager();
|
}
|
||||||
for (final UserFederationProviderModel fedProvider : federationProviders) {
|
|
||||||
usersSyncManager.refreshPeriodicSyncForProvider(session.getKeycloakSessionFactory(), session.getProvider(TimerProvider.class), fedProvider, newRealm.getId());
|
|
||||||
}
|
}
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -217,8 +217,7 @@ public class KeycloakApplication extends Application {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RealmModel realm = manager.createRealm(rep.getId(), rep.getRealm());
|
RealmModel realm = manager.importRealm(rep);
|
||||||
manager.importRealm(rep, realm);
|
|
||||||
|
|
||||||
log.info("Imported realm " + realm.getName() + " from " + from);
|
log.info("Imported realm " + realm.getName() + " from " + from);
|
||||||
|
|
||||||
|
|
|
@ -246,8 +246,7 @@ public class KeycloakServer {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
manager.setContextPath("/auth");
|
manager.setContextPath("/auth");
|
||||||
RealmModel realm = manager.createRealm(rep.getId(), rep.getRealm());
|
RealmModel realm = manager.importRealm(rep);
|
||||||
manager.importRealm(rep, realm);
|
|
||||||
|
|
||||||
info("Imported realm " + realm.getName());
|
info("Imported realm " + realm.getName());
|
||||||
|
|
||||||
|
|
|
@ -53,9 +53,9 @@ public class CompositeImportRoleTest {
|
||||||
public static AbstractKeycloakRule keycloakRule = new AbstractKeycloakRule(){
|
public static AbstractKeycloakRule keycloakRule = new AbstractKeycloakRule(){
|
||||||
@Override
|
@Override
|
||||||
protected void configure(KeycloakSession session, RealmManager manager, RealmModel adminRealm) {
|
protected void configure(KeycloakSession session, RealmManager manager, RealmModel adminRealm) {
|
||||||
RealmModel realm = manager.createRealm("Test");
|
|
||||||
RealmRepresentation representation = KeycloakServer.loadJson(getClass().getResourceAsStream("/testcomposite.json"), RealmRepresentation.class);
|
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();
|
realmPublicKey = realm.getPublicKey();
|
||||||
|
|
||||||
|
|
|
@ -103,8 +103,8 @@ public class ExportImportTest {
|
||||||
// Import "test-realm" realm
|
// Import "test-realm" realm
|
||||||
try {
|
try {
|
||||||
RealmRepresentation rep = AbstractModelTest.loadJson("model/testrealm.json");
|
RealmRepresentation rep = AbstractModelTest.loadJson("model/testrealm.json");
|
||||||
RealmModel demoRealm = manager.createRealm("test-realm", rep.getRealm());
|
rep.setId("test-realm");
|
||||||
manager.importRealm(rep, demoRealm);
|
RealmModel demoRealm = manager.importRealm(rep);
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
throw new RuntimeException(ioe);
|
throw new RuntimeException(ioe);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,8 @@ public class CompositeRolesModelTest extends AbstractModelTest {
|
||||||
super.before();
|
super.before();
|
||||||
RealmManager manager = realmManager;
|
RealmManager manager = realmManager;
|
||||||
RealmRepresentation rep = AbstractModelTest.loadJson("model/testcomposites.json");
|
RealmRepresentation rep = AbstractModelTest.loadJson("model/testcomposites.json");
|
||||||
RealmModel realm = manager.createRealm("TestComposites", rep.getRealm());
|
rep.setId("TestComposites");
|
||||||
manager.importRealm(rep, realm);
|
RealmModel realm = manager.importRealm(rep);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -43,8 +43,8 @@ public class ImportTest extends AbstractModelTest {
|
||||||
@Test
|
@Test
|
||||||
public void install() throws Exception {
|
public void install() throws Exception {
|
||||||
RealmRepresentation rep = AbstractModelTest.loadJson("model/testrealm.json");
|
RealmRepresentation rep = AbstractModelTest.loadJson("model/testrealm.json");
|
||||||
RealmModel realm = realmManager.createRealm("demo", rep.getRealm());
|
rep.setId("demo");
|
||||||
realmManager.importRealm(rep, realm);
|
RealmModel realm = realmManager.importRealm(rep);
|
||||||
|
|
||||||
// Commit after import
|
// Commit after import
|
||||||
commit();
|
commit();
|
||||||
|
@ -216,8 +216,8 @@ public class ImportTest extends AbstractModelTest {
|
||||||
public void install2() throws Exception {
|
public void install2() throws Exception {
|
||||||
RealmManager manager = realmManager;
|
RealmManager manager = realmManager;
|
||||||
RealmRepresentation rep = AbstractModelTest.loadJson("model/testrealm-demo.json");
|
RealmRepresentation rep = AbstractModelTest.loadJson("model/testrealm-demo.json");
|
||||||
RealmModel realm = manager.createRealm("demo", rep.getRealm());
|
rep.setId("demo");
|
||||||
manager.importRealm(rep, realm);
|
RealmModel realm =manager.importRealm(rep);
|
||||||
|
|
||||||
Assert.assertFalse(realm.isUpdateProfileOnInitialSocialLogin());
|
Assert.assertFalse(realm.isUpdateProfileOnInitialSocialLogin());
|
||||||
Assert.assertEquals(600, realm.getAccessCodeLifespanUserAction());
|
Assert.assertEquals(600, realm.getAccessCodeLifespanUserAction());
|
||||||
|
|
|
@ -69,8 +69,8 @@ public class ModelTest extends AbstractModelTest {
|
||||||
private RealmModel importExport(RealmModel src, String copyName) {
|
private RealmModel importExport(RealmModel src, String copyName) {
|
||||||
RealmRepresentation representation = ModelToRepresentation.toRepresentation(src);
|
RealmRepresentation representation = ModelToRepresentation.toRepresentation(src);
|
||||||
representation.setRealm(copyName);
|
representation.setRealm(copyName);
|
||||||
RealmModel copy = realmManager.createRealm(copyName);
|
representation.setId(copyName);
|
||||||
realmManager.importRealm(representation, copy);
|
RealmModel copy = realmManager.importRealm(representation);
|
||||||
return realmManager.getRealm(copy.getId());
|
return realmManager.getRealm(copy.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue