Filter subgroups before paginating
Closes #27512 Signed-off-by: Peter Keuter <github@peterkeuter.nl>
This commit is contained in:
parent
7ffba27336
commit
e26a261e4e
2 changed files with 9 additions and 6 deletions
|
@ -123,7 +123,7 @@ public interface GroupModel extends RoleMapperModel {
|
||||||
* @return Stream of {@link GroupModel}. Never returns {@code null}.
|
* @return Stream of {@link GroupModel}. Never returns {@code null}.
|
||||||
*/
|
*/
|
||||||
default Stream<GroupModel> getSubGroupsStream(String search, Boolean exact, Integer firstResult, Integer maxResults) {
|
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 (search == null || search.isEmpty()) return true;
|
||||||
if (Boolean.TRUE.equals(exact)) {
|
if (Boolean.TRUE.equals(exact)) {
|
||||||
return group.getName().equals(search);
|
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
|
// Copied over from StreamsUtil from server-spi-private which is not available here
|
||||||
if (firstResult != null && firstResult > 0) {
|
if (firstResult != null && firstResult > 0) {
|
||||||
allSubgorupsGroups = allSubgorupsGroups.skip(firstResult);
|
allSubgroupsGroups = allSubgroupsGroups.skip(firstResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maxResults != null && maxResults >= 0) {
|
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 java.util.stream.Stream;
|
||||||
import org.keycloak.utils.GroupUtils;
|
import org.keycloak.utils.GroupUtils;
|
||||||
|
|
||||||
|
import static org.keycloak.utils.StreamsUtil.paginatedStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @resource Groups
|
* @resource Groups
|
||||||
* @author Bill Burke
|
* @author Bill Burke
|
||||||
|
@ -162,8 +164,9 @@ public class GroupResource {
|
||||||
@QueryParam("briefRepresentation") @DefaultValue("false") Boolean briefRepresentation) {
|
@QueryParam("briefRepresentation") @DefaultValue("false") Boolean briefRepresentation) {
|
||||||
this.auth.groups().requireView(group);
|
this.auth.groups().requireView(group);
|
||||||
boolean canViewGlobal = auth.groups().canView();
|
boolean canViewGlobal = auth.groups().canView();
|
||||||
return group.getSubGroupsStream(first, max)
|
return paginatedStream(
|
||||||
.filter(g -> canViewGlobal || auth.groups().canView(g))
|
group.getSubGroupsStream()
|
||||||
|
.filter(g -> canViewGlobal || auth.groups().canView(g)), first, max)
|
||||||
.map(g -> GroupUtils.populateSubGroupCount(g, GroupUtils.toRepresentation(auth.groups(), g, !briefRepresentation)));
|
.map(g -> GroupUtils.populateSubGroupCount(g, GroupUtils.toRepresentation(auth.groups(), g, !briefRepresentation)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue