KEYCLOAK-1990 KEYCLOAK-1991
This commit is contained in:
parent
1e3ec1983d
commit
4a472b8272
2 changed files with 36 additions and 1 deletions
|
@ -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());
|
||||
|
|
27
testsuite/integration/src/test/java/org/keycloak/testsuite/admin/RealmTest.java
Normal file → Executable file
27
testsuite/integration/src/test/java/org/keycloak/testsuite/admin/RealmTest.java
Normal file → Executable file
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue