[KEYCLOAK-7239] Fixed ConcurrentModificationException while importing from LDAP with "ignoreMissingGroups" checked.

Fixed test so that now it checks this use case.
This commit is contained in:
Lubos.Palisek 2018-04-26 14:08:19 +02:00 committed by Marek Posolda
parent 5a56a822b0
commit 2bab2acf5b
2 changed files with 7 additions and 4 deletions

View file

@ -21,6 +21,7 @@ import org.jboss.logging.Logger;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@ -109,13 +110,15 @@ public class GroupTreeResolver {
}
for (Group group : groups) {
for (String child : group.getChildrenNames()) {
Iterator<String> iterator = group.getChildrenNames().iterator();
while (iterator.hasNext()) {
String child = iterator.next();
List<String> list = result.get(child);
if (list != null) {
list.add(group.getGroupName());
} else if(ignoreMissingGroups){
} else if (ignoreMissingGroups) {
// Need to remove the missing group
group.getChildrenNames().remove(child);
iterator.remove();
logger.debug("Group '" + child + "' referenced as member of group '" + group.getGroupName() + "' doesn't exists. Ignoring.");
} else {
throw new GroupTreeResolveException("Group '" + child + "' referenced as member of group '" + group.getGroupName() + "' doesn't exists");

View file

@ -110,7 +110,7 @@ public class GroupTreeResolverTest {
@Test
public void testGroupResolvingMissingGroup() throws GroupTreeResolver.GroupTreeResolveException {
GroupTreeResolver.Group group1 = new GroupTreeResolver.Group("group1", "group2");
GroupTreeResolver.Group group2 = new GroupTreeResolver.Group("group2", "group3");
GroupTreeResolver.Group group2 = new GroupTreeResolver.Group("group2", "group3", "group5");
GroupTreeResolver.Group group4 = new GroupTreeResolver.Group("group4");
List<GroupTreeResolver.Group> groups = Arrays.asList(group1, group2, group4);