From e55ba5dcdc254b281ec97551aaafa39e55b1cdf9 Mon Sep 17 00:00:00 2001 From: Michal Hajas Date: Thu, 8 Feb 2024 16:24:39 +0100 Subject: [PATCH] Make sure pagination is used even when first is null for getGroups endpoint Closes #25731 Signed-off-by: Michal Hajas --- .../services/resources/admin/GroupsResource.java | 6 ++---- .../keycloak/testsuite/admin/group/GroupTest.java | 14 +++++++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/services/src/main/java/org/keycloak/services/resources/admin/GroupsResource.java b/services/src/main/java/org/keycloak/services/resources/admin/GroupsResource.java index 241c9679ed..2cda94850f 100755 --- a/services/src/main/java/org/keycloak/services/resources/admin/GroupsResource.java +++ b/services/src/main/java/org/keycloak/services/resources/admin/GroupsResource.java @@ -100,13 +100,11 @@ public class GroupsResource { stream = ModelToRepresentation.searchGroupModelsByAttributes(session, realm, attributes, firstResult, maxResults); } else if (Objects.nonNull(search)) { stream = session.groups().searchForGroupByNameStream(realm, search.trim(), exact, firstResult, maxResults); - } else if(Objects.nonNull(firstResult) && Objects.nonNull(maxResults)) { - stream = session.groups().getTopLevelGroupsStream(realm, firstResult, maxResults); } else { - stream = session.groups().getTopLevelGroupsStream(realm); + stream = session.groups().getTopLevelGroupsStream(realm, firstResult, maxResults); } - if(populateHierarchy) { + if (populateHierarchy) { return GroupUtils.populateGroupHierarchyFromSubGroups(session, realm, stream, !briefRepresentation, groupsEvaluator); } boolean canViewGlobal = groupsEvaluator.canView(); 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 cd3dbe9825..5aa9b6b381 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 @@ -1149,9 +1149,21 @@ public class GroupTest extends AbstractGroupTest { List allGroups = realm.groups().groups(); assertEquals(20, allGroups.size()); - List slice = realm.groups().groups(5, 7); + List slice = realm.groups().groups(0, 7); assertEquals(7, slice.size()); + slice = realm.groups().groups(null, 7); + assertEquals(7, slice.size()); + + slice = realm.groups().groups(10, null); + assertEquals(10, slice.size()); + + slice = realm.groups().groups(5, 7); + assertEquals(7, slice.size()); + + slice = realm.groups().groups(15, 7); + assertEquals(5, slice.size()); + List search = realm.groups().groups("group1",0,20); assertEquals(11, search.size()); for(GroupRepresentation group : search) {