mirror of
https://github.com/keycloak/keycloak.git
synced 2026-01-06 06:49:53 -06:00
Filter subgroups before paginating
Closes #27512 Signed-off-by: Peter Keuter <github@peterkeuter.nl>
This commit is contained in:
@@ -123,7 +123,7 @@ public interface GroupModel extends RoleMapperModel {
|
||||
* @return Stream of {@link GroupModel}. Never returns {@code null}.
|
||||
*/
|
||||
default Stream<GroupModel> getSubGroupsStream(String search, Boolean exact, Integer firstResult, Integer maxResults) {
|
||||
Stream<GroupModel> allSubgorupsGroups = getSubGroupsStream().filter(group -> {
|
||||
Stream<GroupModel> 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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)));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user