diff --git a/server-spi/src/main/java/org/keycloak/models/GroupModel.java b/server-spi/src/main/java/org/keycloak/models/GroupModel.java index 1c90192025..243f47b45f 100755 --- a/server-spi/src/main/java/org/keycloak/models/GroupModel.java +++ b/server-spi/src/main/java/org/keycloak/models/GroupModel.java @@ -123,7 +123,7 @@ public interface GroupModel extends RoleMapperModel { * @return Stream of {@link GroupModel}. Never returns {@code null}. */ default Stream getSubGroupsStream(String search, Boolean exact, Integer firstResult, Integer maxResults) { - Stream allSubgorupsGroups = getSubGroupsStream().filter(group -> { + Stream allSubgroupsGroups = getSubGroupsStream().filter(group -> { if (search == null || search.isEmpty()) return true; if (Boolean.TRUE.equals(exact)) { return group.getName().equals(search); @@ -134,14 +134,14 @@ public interface GroupModel extends RoleMapperModel { // Copied over from StreamsUtil from server-spi-private which is not available here if (firstResult != null && firstResult > 0) { - allSubgorupsGroups = allSubgorupsGroups.skip(firstResult); + allSubgroupsGroups = allSubgroupsGroups.skip(firstResult); } if (maxResults != null && maxResults >= 0) { - allSubgorupsGroups = allSubgorupsGroups.limit(maxResults); + allSubgroupsGroups = allSubgroupsGroups.limit(maxResults); } - return allSubgorupsGroups; + return allSubgroupsGroups; } /** diff --git a/services/src/main/java/org/keycloak/services/resources/admin/GroupResource.java b/services/src/main/java/org/keycloak/services/resources/admin/GroupResource.java index 576f3ee2f8..b3471464bb 100755 --- a/services/src/main/java/org/keycloak/services/resources/admin/GroupResource.java +++ b/services/src/main/java/org/keycloak/services/resources/admin/GroupResource.java @@ -61,6 +61,8 @@ import java.util.Set; import java.util.stream.Stream; import org.keycloak.utils.GroupUtils; +import static org.keycloak.utils.StreamsUtil.paginatedStream; + /** * @resource Groups * @author Bill Burke @@ -162,8 +164,9 @@ public class GroupResource { @QueryParam("briefRepresentation") @DefaultValue("false") Boolean briefRepresentation) { this.auth.groups().requireView(group); boolean canViewGlobal = auth.groups().canView(); - return group.getSubGroupsStream(first, max) - .filter(g -> canViewGlobal || auth.groups().canView(g)) + return paginatedStream( + group.getSubGroupsStream() + .filter(g -> canViewGlobal || auth.groups().canView(g)), first, max) .map(g -> GroupUtils.populateSubGroupCount(g, GroupUtils.toRepresentation(auth.groups(), g, !briefRepresentation))); }