parent
22d093f5c0
commit
7c6f173d3a
3 changed files with 28 additions and 12 deletions
|
@ -138,6 +138,7 @@ public class LegacyExportImportManager implements ExportImportManager {
|
||||||
this.session = session;
|
this.session = session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void exportRealm(RealmModel realm, ExportOptions options, ExportAdapter callback) {
|
public void exportRealm(RealmModel realm, ExportOptions options, ExportAdapter callback) {
|
||||||
callback.setType(MediaType.APPLICATION_JSON);
|
callback.setType(MediaType.APPLICATION_JSON);
|
||||||
callback.writeToOutputStream(outputStream -> {
|
callback.writeToOutputStream(outputStream -> {
|
||||||
|
@ -409,11 +410,7 @@ public class LegacyExportImportManager implements ExportImportManager {
|
||||||
if (rep.getGroups() != null) {
|
if (rep.getGroups() != null) {
|
||||||
importGroups(newRealm, rep);
|
importGroups(newRealm, rep);
|
||||||
if (rep.getDefaultGroups() != null) {
|
if (rep.getDefaultGroups() != null) {
|
||||||
for (String path : rep.getDefaultGroups()) {
|
KeycloakModelUtils.setDefaultGroups(session, newRealm, rep.getDefaultGroups().stream());
|
||||||
GroupModel found = KeycloakModelUtils.findGroupByPath(session, newRealm, path);
|
|
||||||
if (found == null) throw new RuntimeException("default group in realm rep doesn't exist: " + path);
|
|
||||||
newRealm.addDefaultGroup(found);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -728,6 +725,9 @@ public class LegacyExportImportManager implements ExportImportManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rep.getDefaultGroups() != null) {
|
||||||
|
KeycloakModelUtils.setDefaultGroups(session, realm, rep.getDefaultGroups().stream());
|
||||||
|
}
|
||||||
if (rep.getDisplayName() != null) realm.setDisplayName(rep.getDisplayName());
|
if (rep.getDisplayName() != null) realm.setDisplayName(rep.getDisplayName());
|
||||||
if (rep.getDisplayNameHtml() != null) realm.setDisplayNameHtml(rep.getDisplayNameHtml());
|
if (rep.getDisplayNameHtml() != null) realm.setDisplayNameHtml(rep.getDisplayNameHtml());
|
||||||
if (rep.isEnabled() != null) realm.setEnabled(rep.isEnabled());
|
if (rep.isEnabled() != null) realm.setEnabled(rep.isEnabled());
|
||||||
|
|
|
@ -414,11 +414,7 @@ public class MapExportImportManager implements ExportImportManager {
|
||||||
if (rep.getGroups() != null) {
|
if (rep.getGroups() != null) {
|
||||||
importGroups(newRealm, rep);
|
importGroups(newRealm, rep);
|
||||||
if (rep.getDefaultGroups() != null) {
|
if (rep.getDefaultGroups() != null) {
|
||||||
for (String path : rep.getDefaultGroups()) {
|
KeycloakModelUtils.setDefaultGroups(session, newRealm, rep.getDefaultGroups().stream());
|
||||||
GroupModel found = KeycloakModelUtils.findGroupByPath(session, newRealm, path);
|
|
||||||
if (found == null) throw new RuntimeException("default group in realm rep doesn't exist: " + path);
|
|
||||||
newRealm.addDefaultGroup(found);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1018,6 +1014,9 @@ public class MapExportImportManager implements ExportImportManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rep.getDefaultGroups() != null) {
|
||||||
|
KeycloakModelUtils.setDefaultGroups(session, realm, rep.getDefaultGroups().stream());
|
||||||
|
}
|
||||||
if (rep.getDisplayName() != null) realm.setDisplayName(rep.getDisplayName());
|
if (rep.getDisplayName() != null) realm.setDisplayName(rep.getDisplayName());
|
||||||
if (rep.getDisplayNameHtml() != null) realm.setDisplayNameHtml(rep.getDisplayNameHtml());
|
if (rep.getDisplayNameHtml() != null) realm.setDisplayNameHtml(rep.getDisplayNameHtml());
|
||||||
if (rep.isEnabled() != null) realm.setEnabled(rep.isEnabled());
|
if (rep.isEnabled() != null) realm.setEnabled(rep.isEnabled());
|
||||||
|
|
|
@ -1072,4 +1072,21 @@ public final class KeycloakModelUtils {
|
||||||
public static boolean isUsernameCaseSensitive(RealmModel realm) {
|
public static boolean isUsernameCaseSensitive(RealmModel realm) {
|
||||||
return realm.getAttribute(REALM_ATTR_USERNAME_CASE_SENSITIVE, REALM_ATTR_USERNAME_CASE_SENSITIVE_DEFAULT);
|
return realm.getAttribute(REALM_ATTR_USERNAME_CASE_SENSITIVE, REALM_ATTR_USERNAME_CASE_SENSITIVE_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the default groups on the realm
|
||||||
|
* @param session
|
||||||
|
* @param realm
|
||||||
|
* @param groups
|
||||||
|
* @throws RuntimeException if a group does not exist
|
||||||
|
*/
|
||||||
|
public static void setDefaultGroups(KeycloakSession session, RealmModel realm, Stream<String> groups) {
|
||||||
|
realm.getDefaultGroupsStream().collect(Collectors.toList()).forEach(realm::removeDefaultGroup);
|
||||||
|
groups.forEach(path -> {
|
||||||
|
GroupModel found = KeycloakModelUtils.findGroupByPath(session, realm, path);
|
||||||
|
if (found == null) throw new RuntimeException("default group in realm rep doesn't exist: " + path);
|
||||||
|
realm.addDefaultGroup(found);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue