Merge pull request #1738 from gerbermichi/locale

KEYCLOAK-1962 update realm overwrites supported locales with empty list
This commit is contained in:
Stian Thorgersen 2015-10-16 10:21:20 +02:00
commit a6556a49c2
3 changed files with 38 additions and 4 deletions

View file

@ -629,12 +629,16 @@ public class RealmRepresentation {
} }
public Set<String> getSupportedLocales() { public Set<String> getSupportedLocales() {
if(supportedLocales == null){
supportedLocales = new HashSet<String>();
}
return supportedLocales; return supportedLocales;
} }
public void addSupportedLocales(String locale) {
if(supportedLocales == null){
supportedLocales = new HashSet<>();
}
supportedLocales.add(locale);
}
public void setSupportedLocales(Set<String> supportedLocales) { public void setSupportedLocales(Set<String> supportedLocales) {
this.supportedLocales = supportedLocales; this.supportedLocales = supportedLocales;
} }

View file

@ -212,7 +212,10 @@ public class ModelToRepresentation {
} }
rep.setInternationalizationEnabled(realm.isInternationalizationEnabled()); rep.setInternationalizationEnabled(realm.isInternationalizationEnabled());
rep.getSupportedLocales().addAll(realm.getSupportedLocales()); if(realm.getSupportedLocales() != null){
rep.setSupportedLocales(new HashSet<String>());
rep.getSupportedLocales().addAll(realm.getSupportedLocales());
}
rep.setDefaultLocale(realm.getDefaultLocale()); rep.setDefaultLocale(realm.getDefaultLocale());
if (internal) { if (internal) {
exportAuthenticationFlows(realm, rep); exportAuthenticationFlows(realm, rep);

View file

@ -15,6 +15,8 @@ import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.HashSet;
import java.util.Arrays;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
@ -102,6 +104,31 @@ public class RealmTest extends AbstractClientTest {
assertEquals(Boolean.FALSE, rep.isEditUsernameAllowed()); 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 @Test
public void getRealmRepresentation() { public void getRealmRepresentation() {
RealmRepresentation rep = realm.toRepresentation(); RealmRepresentation rep = realm.toRepresentation();