diff --git a/core/src/main/java/org/keycloak/representations/idm/RealmRepresentation.java b/core/src/main/java/org/keycloak/representations/idm/RealmRepresentation.java index 43bed913a6..387ab7e783 100755 --- a/core/src/main/java/org/keycloak/representations/idm/RealmRepresentation.java +++ b/core/src/main/java/org/keycloak/representations/idm/RealmRepresentation.java @@ -629,12 +629,16 @@ public class RealmRepresentation { } public Set getSupportedLocales() { - if(supportedLocales == null){ - supportedLocales = new HashSet(); - } return supportedLocales; } + public void addSupportedLocales(String locale) { + if(supportedLocales == null){ + supportedLocales = new HashSet<>(); + } + supportedLocales.add(locale); + } + public void setSupportedLocales(Set supportedLocales) { this.supportedLocales = supportedLocales; } diff --git a/model/api/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java b/model/api/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java index c2a8a178be..084d012107 100755 --- a/model/api/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java +++ b/model/api/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java @@ -212,7 +212,10 @@ public class ModelToRepresentation { } rep.setInternationalizationEnabled(realm.isInternationalizationEnabled()); - rep.getSupportedLocales().addAll(realm.getSupportedLocales()); + if(realm.getSupportedLocales() != null){ + rep.setSupportedLocales(new HashSet()); + rep.getSupportedLocales().addAll(realm.getSupportedLocales()); + } rep.setDefaultLocale(realm.getDefaultLocale()); if (internal) { exportAuthenticationFlows(realm, rep); 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 index 8c41dfa2ef..bb3351542e 100644 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/admin/RealmTest.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/admin/RealmTest.java @@ -15,6 +15,8 @@ import java.io.IOException; import java.util.Collections; import java.util.LinkedList; import java.util.List; +import java.util.HashSet; +import java.util.Arrays; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -102,6 +104,31 @@ public class RealmTest extends AbstractClientTest { assertEquals(Boolean.FALSE, rep.isEditUsernameAllowed()); } + @Test + public void updateRealmWithNewRepresentation() { + // first change + RealmRepresentation rep = new RealmRepresentation(); + rep.setEditUsernameAllowed(true); + rep.setSupportedLocales(new HashSet<>(Arrays.asList("en", "de"))); + + realm.update(rep); + + rep = realm.toRepresentation(); + + assertEquals(Boolean.TRUE, rep.isEditUsernameAllowed()); + assertEquals(2, rep.getSupportedLocales().size()); + + // second change + rep = new RealmRepresentation(); + rep.setEditUsernameAllowed(false); + + realm.update(rep); + + rep = realm.toRepresentation(); + assertEquals(Boolean.FALSE, rep.isEditUsernameAllowed()); + assertEquals(2, rep.getSupportedLocales().size()); + } + @Test public void getRealmRepresentation() { RealmRepresentation rep = realm.toRepresentation();