bug5171: avoid concurrent modification exception when deleting user

This commit is contained in:
Axel Uhl committed 2020-01-07 11:01:59 +01:00
1 parent ece66bd731
commit aacc30ef55
1 file changed
+4 -2
@@ -1203,7 +1203,6 @@ public class SecurityServiceImpl implements ReplicableSecurityService, ClearStat
// remove all permissions the user has
accessControlStore.removeAllOwnershipsFor(userToDelete);
store.removeAllQualifiedRolesForUser(userToDelete);
final String defaultTenantNameForUsername = getDefaultTenantNameForUsername(username);
final UserGroup defaultTenantUserGroup = getUserGroupByName(defaultTenantNameForUsername);
if (defaultTenantUserGroup != null) {
@@ -1218,7 +1217,10 @@ public class SecurityServiceImpl implements ReplicableSecurityService, ClearStat
}
}
// also remove from all usergroups
for (UserGroup userGroup : userToDelete.getUserGroups()) {
final Iterable<UserGroup> userGroups = userToDelete.getUserGroups();
final Collection<UserGroup> userGroupsToLoopOver = new ArrayList<>();
Util.addAll(userGroups, userGroupsToLoopOver); // avoid concurrent modification exception
for (UserGroup userGroup : userGroupsToLoopOver) {
if (userGroup != defaultTenantUserGroup) { // the defaultTenantUserGroup has already been deleted above
internalRemoveUserFromUserGroup(userGroup.getId(), userToDelete.getName());
}