KEYCLOAK-20343 Add message bundle to export/import

Closes #20343
This commit is contained in:
todor 2023-06-30 13:00:20 +03:00 committed by Alexander Schwartz
parent 262cc33ebd
commit 897965f604
7 changed files with 46 additions and 0 deletions

View file

@ -123,6 +123,7 @@ public class RealmRepresentation {
protected Integer otpPolicyPeriod; protected Integer otpPolicyPeriod;
protected Boolean otpPolicyCodeReusable; protected Boolean otpPolicyCodeReusable;
protected List<String> otpSupportedApplications; protected List<String> otpSupportedApplications;
protected Map<String, Map<String, String>> localizationTexts;
// WebAuthn 2-factor properties below // WebAuthn 2-factor properties below
@ -1025,6 +1026,14 @@ public class RealmRepresentation {
this.otpSupportedApplications = otpSupportedApplications; this.otpSupportedApplications = otpSupportedApplications;
} }
public Map<String, Map<String, String>> getLocalizationTexts() {
return localizationTexts;
}
public void setLocalizationTexts(Map<String, Map<String, String>> localizationTexts) {
this.localizationTexts = localizationTexts;
}
public Boolean isOtpPolicyCodeReusable() { public Boolean isOtpPolicyCodeReusable() {
return otpPolicyCodeReusable; return otpPolicyCodeReusable;
} }

View file

@ -252,6 +252,9 @@ public class ExportUtils {
MultivaluedHashMap<String, ComponentExportRepresentation> components = exportComponents(realm, realm.getId()); MultivaluedHashMap<String, ComponentExportRepresentation> components = exportComponents(realm, realm.getId());
rep.setComponents(components); rep.setComponents(components);
// Message Bundle
rep.setLocalizationTexts(realm.getRealmLocalizationTexts());
return rep; return rep;
} }

View file

@ -276,6 +276,12 @@ public class LegacyExportImportManager implements ExportImportManager {
if (rep.getAccountTheme() != null) newRealm.setAccountTheme(rep.getAccountTheme()); if (rep.getAccountTheme() != null) newRealm.setAccountTheme(rep.getAccountTheme());
if (rep.getAdminTheme() != null) newRealm.setAdminTheme(rep.getAdminTheme()); if (rep.getAdminTheme() != null) newRealm.setAdminTheme(rep.getAdminTheme());
if (rep.getEmailTheme() != null) newRealm.setEmailTheme(rep.getEmailTheme()); if (rep.getEmailTheme() != null) newRealm.setEmailTheme(rep.getEmailTheme());
if (rep.getLocalizationTexts() != null) {
Map<String, Map<String, String>> localizationTexts = rep.getLocalizationTexts();
for (Map.Entry<String, Map<String, String>> entry: localizationTexts.entrySet()) {
newRealm.createOrUpdateRealmLocalizationTexts(entry.getKey(), entry.getValue());
}
}
// todo remove this stuff as its all deprecated // todo remove this stuff as its all deprecated
if (rep.getRequiredCredentials() != null) { if (rep.getRequiredCredentials() != null) {

View file

@ -283,6 +283,12 @@ public class MapExportImportManager implements ExportImportManager {
if (rep.getAccountTheme() != null) newRealm.setAccountTheme(rep.getAccountTheme()); if (rep.getAccountTheme() != null) newRealm.setAccountTheme(rep.getAccountTheme());
if (rep.getAdminTheme() != null) newRealm.setAdminTheme(rep.getAdminTheme()); if (rep.getAdminTheme() != null) newRealm.setAdminTheme(rep.getAdminTheme());
if (rep.getEmailTheme() != null) newRealm.setEmailTheme(rep.getEmailTheme()); if (rep.getEmailTheme() != null) newRealm.setEmailTheme(rep.getEmailTheme());
if (rep.getLocalizationTexts() != null) {
Map<String, Map<String, String>> localizationTexts = rep.getLocalizationTexts();
for (Map.Entry<String, Map<String, String>> entry: localizationTexts.entrySet()) {
newRealm.createOrUpdateRealmLocalizationTexts(entry.getKey(), entry.getValue());
}
}
// todo remove this stuff as its all deprecated // todo remove this stuff as its all deprecated
if (rep.getRequiredCredentials() != null) { if (rep.getRequiredCredentials() != null) {

View file

@ -105,10 +105,12 @@ public class ExportImportTest extends AbstractKeycloakTest {
testRealm1.getSmtpServer().put("password", "secret"); testRealm1.getSmtpServer().put("password", "secret");
setEventsConfig(testRealm1); setEventsConfig(testRealm1);
setLocalizationTexts(testRealm1);
testRealms.add(testRealm1); testRealms.add(testRealm1);
RealmRepresentation testRealm2 = loadJson(getClass().getResourceAsStream("/model/testrealm.json"), RealmRepresentation.class); RealmRepresentation testRealm2 = loadJson(getClass().getResourceAsStream("/model/testrealm.json"), RealmRepresentation.class);
testRealm2.setId("test-realm"); testRealm2.setId("test-realm");
setLocalizationTexts(testRealm2);
testRealms.add(testRealm2); testRealms.add(testRealm2);
} }
@ -146,6 +148,15 @@ public class ExportImportTest extends AbstractKeycloakTest {
.build(); .build();
} }
private void setLocalizationTexts(RealmRepresentation realm) {
Map<String, Map<String, String>> localizationTexts = new HashMap<>();
Map<String, String> enMap = new HashMap<>();
enMap.put("key1", "value1");
enMap.put("key2", "value2");
localizationTexts.put("en", enMap);
realm.setLocalizationTexts(localizationTexts);
}
@After @After
public void clearExportImportProps() throws LifecycleException { public void clearExportImportProps() throws LifecycleException {
clearExportImportProperties(); clearExportImportProperties();

View file

@ -430,6 +430,11 @@ public class ExportImportUtil {
assertAuthorizationSettingsOtherApp(realmRsc); assertAuthorizationSettingsOtherApp(realmRsc);
assertAuthorizationSettingsTestAppAuthz(realmRsc); assertAuthorizationSettingsTestAppAuthz(realmRsc);
} }
// Test Message Bundle
Map<String, String> localizations = adminClient.realm(realm.getRealm()).localization().getRealmLocalizationTexts("en");
Assert.assertEquals("value1", localizations.get("key1"));
Assert.assertEquals("value2", localizations.get("key2"));
} }

View file

@ -13,6 +13,12 @@
"requiredCredentials": [ "password" ], "requiredCredentials": [ "password" ],
"defaultRoles": [ "foo", "bar" ], "defaultRoles": [ "foo", "bar" ],
"verifyEmail" : "true", "verifyEmail" : "true",
"localizationTexts" : {
"en" : {
"key1" : "value1",
"key2" : "value2"
}
},
"smtpServer": { "smtpServer": {
"from": "auto@keycloak.org", "from": "auto@keycloak.org",
"host": "localhost", "host": "localhost",