Merge pull request #5194 from pedroigor/KEYCLOAK-7322
[KEYCLOAK-7322] - NPE when removing group from representation
This commit is contained in:
commit
1634bef28a
2 changed files with 20 additions and 6 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue