Skip to content

Commit 98612bb

Browse files
shawkinsahus1
andauthored
fix: adding group import handling similar to users
closes: #41235 Signed-off-by: Steve Hawkins <[email protected]> Signed-off-by: Alexander Schwartz <[email protected]> Co-authored-by: Alexander Schwartz <[email protected]>
1 parent d354b2c commit 98612bb

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

model/storage-private/src/main/java/org/keycloak/storage/datastore/DefaultExportImportManager.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public class DefaultExportImportManager implements ExportImportManager {
150150
private final KeycloakSession session;
151151
private static final Logger logger = Logger.getLogger(DefaultExportImportManager.class);
152152

153-
public static class UserBatcher implements Consumer<KeycloakSession> {
153+
public static class Batcher implements Consumer<KeycloakSession> {
154154
private int count;
155155

156156
@Override
@@ -466,7 +466,7 @@ public void importRealm(RealmRepresentation rep, RealmModel newRealm, Runnable u
466466
// run in a batch to mimic the behavior of directory based import
467467
// this is using nested entity managers to keep the parent context clean
468468
EntityManagers.runInBatch(session, () -> {
469-
UserBatcher onUserAdded = new UserBatcher();
469+
Batcher onUserAdded = new Batcher();
470470
if (rep.getUsers() != null) {
471471
for (UserRepresentation userRep : rep.getUsers()) {
472472
createUser(newRealm, userRep);
@@ -804,10 +804,10 @@ public void updateRealm(RealmRepresentation rep, RealmModel realm) {
804804
if (rep.isPermanentLockout() != null) realm.setPermanentLockout(rep.isPermanentLockout());
805805
if (rep.getMaxTemporaryLockouts() != null) realm.setMaxTemporaryLockouts(checkNonNegativeNumber(rep.getMaxTemporaryLockouts(),"Maximum temporary lockouts"));
806806
if (rep.getBruteForceStrategy() != null) realm.setBruteForceStrategy(rep.getBruteForceStrategy());
807-
if (rep.getMaxFailureWaitSeconds() != null) realm.setMaxFailureWaitSeconds(checkNonNegativeNumber(rep.getMaxFailureWaitSeconds(),"Maximum failure wait seconds"));
807+
if (rep.getMaxFailureWaitSeconds() != null) realm.setMaxFailureWaitSeconds(checkNonNegativeNumber(rep.getMaxFailureWaitSeconds(),"Maximum failure wait seconds"));
808808
if (rep.getMinimumQuickLoginWaitSeconds() != null) realm.setMinimumQuickLoginWaitSeconds(checkNonNegativeNumber(rep.getMinimumQuickLoginWaitSeconds(),"Minimum quick login wait seconds"));
809-
if (rep.getWaitIncrementSeconds() != null) realm.setWaitIncrementSeconds(checkNonNegativeNumber(rep.getWaitIncrementSeconds(),"Wait increment seconds"));
810-
if (rep.getQuickLoginCheckMilliSeconds() != null) realm.setQuickLoginCheckMilliSeconds(checkNonNegativeNumber(rep.getQuickLoginCheckMilliSeconds().intValue(), "Quick login check milliseconds"));
809+
if (rep.getWaitIncrementSeconds() != null) realm.setWaitIncrementSeconds(checkNonNegativeNumber(rep.getWaitIncrementSeconds(),"Wait increment seconds"));
810+
if (rep.getQuickLoginCheckMilliSeconds() != null) realm.setQuickLoginCheckMilliSeconds(checkNonNegativeNumber(rep.getQuickLoginCheckMilliSeconds().intValue(), "Quick login check milliseconds"));
811811
if (rep.getMaxDeltaTimeSeconds() != null) realm.setMaxDeltaTimeSeconds(checkNonNegativeNumber(rep.getMaxDeltaTimeSeconds(),"Maximum delta time seconds"));
812812
if (rep.getFailureFactor() != null) realm.setFailureFactor(checkNonNegativeNumber(rep.getFailureFactor(),"Failure factor"));
813813
if (rep.isRegistrationAllowed() != null) realm.setRegistrationAllowed(rep.isRegistrationAllowed());
@@ -1266,14 +1266,20 @@ protected static void importComponents(RealmModel newRealm, MultivaluedHashMap<S
12661266
}
12671267
}
12681268

1269-
public static void importGroups(RealmModel realm, RealmRepresentation rep) {
1269+
public void importGroups(RealmModel realm, RealmRepresentation rep) {
12701270
List<GroupRepresentation> groups = rep.getGroups();
12711271
if (groups == null) return;
12721272

1273-
GroupModel parent = null;
1274-
for (GroupRepresentation group : groups) {
1275-
importGroup(realm, parent, group);
1276-
}
1273+
1274+
EntityManagers.runInBatch(session, () -> {
1275+
Batcher batcher = new Batcher();
1276+
GroupModel parent = null;
1277+
for (GroupRepresentation group : groups) {
1278+
importGroup(realm, parent, group);
1279+
batcher.accept(session);
1280+
}
1281+
}, true);
1282+
12771283
}
12781284

12791285
private static WebAuthnPolicy getWebAuthnPolicyTwoFactor(RealmRepresentation rep) {

model/storage-services/src/main/java/org/keycloak/exportimport/dir/DirImportProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private void importUsers(final String realmName, File[] userFiles, boolean feder
167167
@Override
168168
protected void runExportImportTask(KeycloakSession session) throws IOException {
169169
session.getContext().setRealm(session.realms().getRealmByName(realmName));
170-
ImportUtils.importUsersFromStream(session, realmName, JsonSerialization.mapper, fis, federated, new DefaultExportImportManager.UserBatcher());
170+
ImportUtils.importUsersFromStream(session, realmName, JsonSerialization.mapper, fis, federated, new DefaultExportImportManager.Batcher());
171171
logger.infof("Imported %susers from %s", federated?"federated ":"", userFile.getAbsolutePath());
172172
}
173173
}.runTask(factory, Mode.BATCHED);

0 commit comments

Comments
 (0)