diff --git a/rest/admin-ui-ext/src/main/java/org/keycloak/admin/ui/rest/GroupsResource.java b/rest/admin-ui-ext/src/main/java/org/keycloak/admin/ui/rest/GroupsResource.java index d9b307992b..bbfa03664a 100644 --- a/rest/admin-ui-ext/src/main/java/org/keycloak/admin/ui/rest/GroupsResource.java +++ b/rest/admin-ui-ext/src/main/java/org/keycloak/admin/ui/rest/GroupsResource.java @@ -57,15 +57,12 @@ public class GroupsResource { @QueryParam("exact") @DefaultValue("false") boolean exact) { this.auth.groups().requireList(); final Stream stream; - if (!"".equals(search)) { - if (global) { - stream = session.groups().searchForGroupByNameStream(realm, search, exact, first, max); - } else { - stream = this.realm.getTopLevelGroupsStream().filter(g -> g.getName().contains(search)).skip(first).limit(max); - } + if (global) { + stream = session.groups().searchForGroupByNameStream(realm, search.trim(), exact, first, max); } else { - stream = this.realm.getTopLevelGroupsStream(first, max); + stream = this.realm.getTopLevelGroupsStream().filter(g -> g.getName().contains(search)).skip(first).limit(max); } + return stream.map(g -> toGroupHierarchy(g, search, exact)); }