From 4a472b8272218b2496f5e8cceee5fcc219f9220b Mon Sep 17 00:00:00 2001 From: Bill Burke Date: Wed, 6 Jan 2016 10:02:56 -0500 Subject: [PATCH] KEYCLOAK-1990 KEYCLOAK-1991 --- .../models/utils/RepresentationToModel.java | 10 ++++++- .../keycloak/testsuite/admin/RealmTest.java | 27 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) mode change 100644 => 100755 testsuite/integration/src/test/java/org/keycloak/testsuite/admin/RealmTest.java diff --git a/model/api/src/main/java/org/keycloak/models/utils/RepresentationToModel.java b/model/api/src/main/java/org/keycloak/models/utils/RepresentationToModel.java index 3b2cfdc5db..f40f9628c9 100755 --- a/model/api/src/main/java/org/keycloak/models/utils/RepresentationToModel.java +++ b/model/api/src/main/java/org/keycloak/models/utils/RepresentationToModel.java @@ -1,5 +1,6 @@ package org.keycloak.models.utils; +import org.keycloak.Config; import org.keycloak.models.ClientTemplateModel; import org.keycloak.models.Constants; import org.keycloak.common.util.Base64; @@ -593,9 +594,16 @@ public class RepresentationToModel { } } + public static void renameRealm(RealmModel realm, String name) { + if (name.equals(realm.getName())) return; + ClientModel masterApp = realm.getMasterAdminClient(); + masterApp.setClientId(KeycloakModelUtils.getMasterRealmAdminApplicationClientId(name)); + realm.setName(name); + } + public static void updateRealm(RealmRepresentation rep, RealmModel realm) { if (rep.getRealm() != null) { - realm.setName(rep.getRealm()); + renameRealm(realm, rep.getRealm()); } if (rep.getDisplayName() != null) realm.setDisplayName(rep.getDisplayName()); if (rep.getDisplayNameHtml() != null) realm.setDisplayNameHtml(rep.getDisplayNameHtml()); diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/admin/RealmTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/admin/RealmTest.java old mode 100644 new mode 100755 index b2fb326c5d..4f0936be4a --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/admin/RealmTest.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/admin/RealmTest.java @@ -99,6 +99,33 @@ public class RealmTest extends AbstractClientTest { ServerInfoResource serverInfoResource = Keycloak.getInstance("http://localhost:8081/auth", "master", "admin", "admin", Constants.ADMIN_CLI_CLIENT_ID).serverInfo(); serverInfoResource.getInfo(); + } + + /** + * KEYCLOAK-1990 1991 + * @throws Exception + */ + @Test + public void renameRealmTest() throws Exception { + Keycloak keycloak = Keycloak.getInstance("http://localhost:8081/auth", "master", "admin", "admin", Constants.ADMIN_CLI_CLIENT_ID); + RealmRepresentation realm1 = new RealmRepresentation(); + realm1.setRealm("test-immutable"); + keycloak.realms().create(realm1); + realm1 = keycloak.realms().realm("test-immutable").toRepresentation(); + realm1.setRealm("test-immutable-old"); + keycloak.realms().realm("test-immutable").update(realm1); + realm1 = keycloak.realms().realm("test-immutable-old").toRepresentation(); + + RealmRepresentation realm2 = new RealmRepresentation(); + realm2.setRealm("test-immutable"); + keycloak.realms().create(realm2); + realm2 = keycloak.realms().realm("test-immutable").toRepresentation(); + + keycloak.realms().realm("test-immutable-old").remove(); + + + + } @Test