Merge pull request #5194 from pedroigor/KEYCLOAK-7322

[KEYCLOAK-7322] - NPE when removing group from representation
This commit is contained in:
Pedro Igor 2018-05-15 06:05:54 -03:00 committed by GitHub
commit 1634bef28a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 6 deletions

View file

@ -17,6 +17,7 @@
package org.keycloak.representations.idm.authorization;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
/**
@ -76,12 +77,12 @@ public class GroupPolicyRepresentation extends AbstractPolicyRepresentation {
public void removeGroup(String... ids) {
if (groups != null) {
for (final String id : ids) {
if (!groups.remove(id)) {
for (GroupDefinition group : new HashSet<>(groups)) {
if (group.getPath().startsWith(id)) {
groups.remove(group);
}
for (String id : ids) {
Iterator<GroupDefinition> iterator = groups.iterator();
while (iterator.hasNext()) {
GroupDefinition group = iterator.next();
if (id.equals(group.getId()) || (group.getPath() != null && group.getPath().equals(id))) {
iterator.remove();
}
}
}

View file

@ -150,6 +150,19 @@ public class GroupPolicyManagementTest extends AbstractPolicyManagementTest {
}
}
@Test
public void testRemoveWithoutPath() {
GroupPolicyRepresentation representation = new GroupPolicyRepresentation();
representation.setName("Delete Group Path Policy");
representation.setGroupsClaim("groups");
representation.addGroup("Group A");
representation.removeGroup("Group A");
assertTrue(representation.getGroups().isEmpty());
}
@Test
public void testGenericConfig() {
AuthorizationResource authorization = getClient().authorization();