From baafb670f77688aedabf91dee513279f98823c93 Mon Sep 17 00:00:00 2001 From: Daniel Fesenmeyer Date: Tue, 19 Dec 2023 10:22:26 +0100 Subject: [PATCH] Bugfix for: Removing all group attributes no longer works with keycloak-admin-client (java) Closes #25677 Signed-off-by: Daniel Fesenmeyer --- .../idm/GroupRepresentation.java | 2 -- .../testsuite/admin/group/GroupTest.java | 25 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/keycloak/representations/idm/GroupRepresentation.java b/core/src/main/java/org/keycloak/representations/idm/GroupRepresentation.java index e83fab0ecc..d55129a929 100755 --- a/core/src/main/java/org/keycloak/representations/idm/GroupRepresentation.java +++ b/core/src/main/java/org/keycloak/representations/idm/GroupRepresentation.java @@ -17,7 +17,6 @@ package org.keycloak.representations.idm; -import com.fasterxml.jackson.annotation.JsonInclude; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -30,7 +29,6 @@ import java.util.stream.Collectors; * @author Bill Burke * @version $Revision: 1 $ */ -@JsonInclude(JsonInclude.Include.NON_EMPTY) public class GroupRepresentation { // For an individual group these are the sufficient minimum fields // to identify a group and operate on it in a basic way diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/group/GroupTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/group/GroupTest.java index 18e37b58d8..6f257a1667 100755 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/group/GroupTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/group/GroupTest.java @@ -1250,6 +1250,31 @@ public class GroupTest extends AbstractGroupTest { } } + @Test + public void removeAllGroupAttributes() { + final var realm = adminClient.realms().realm("test"); + final var groupName = "remove-all-attributes-group"; + + final Map> initialAttributes = Map.of("test-key", List.of("test-val")); + final var groupToCreate = + GroupBuilder.create().name(groupName).attributes(initialAttributes).build(); + final var groupsResource = realm.groups(); + try (final Response response = groupsResource.add(groupToCreate)) { + final var groupId = ApiUtil.getCreatedId(response); + + final var groupResource = groupsResource.group(groupId); + final var createdGroup = groupResource.toRepresentation(); + assertThat(createdGroup.getAttributes(), equalTo(initialAttributes)); + + final var groupToUpdate = + GroupBuilder.create().name(groupName).attributes(Collections.emptyMap()).build(); + groupResource.update(groupToUpdate); + + final var updatedGroup = groupResource.toRepresentation(); + assertThat(updatedGroup.getAttributes(), anEmptyMap()); + } + } + @Test public void testBriefRepresentationOnGroupMembers() { RealmResource realm = adminClient.realms().realm("test");