Add Groups resource type and scopes to authorization schema
Tier 2 hard java · local · real merged PR from keycloak/keycloak #37038
Ground-truth defects
Incorrect permission check in canManage() method
In getGroupIdsWithViewPermission, hasPermission is called with groupResource.getId() and the same groupResource.getId() is added to granted, but hasPermission resolves resources by name (treating the argument as a group id) and the GroupPermissionEvaluator contract says this method returns group IDs that are later used as UserModel.GROUPS and in getUsersCount group filters. This mismatch means per-group VIEW_MEMBERS/MANAGE_MEMBERS permissions may not yield the expected group IDs for filtering and counts, and evaluation may effectively only look at the type-level 'all-groups' resource; consider revisiting whether this should operate on the underlying group ids (resource names) instead so it aligns with the JPA queries and the interface contract.
Both group list endpoints drop the hoisted global permission check (`boolean canViewGlobal = groupsEvaluator.canView()`) and filter with a per-group `groupsEvaluator::canView`. Under fine-grained admin permissions v2 that per-group call falls through to a resource lookup and a full uncached policy evaluation, so one evaluation becomes one per group; the subgroup endpoint is worse because it fetches subgroups unbounded and paginates only after filtering.
The change under review
diff (truncated — full diff)
@@ -144,16 +144,12 @@ public final Stream<BruteUser> searchUser(@QueryParam("search") String search, private Stream<BruteUser> searchForUser(Map<String, String> attributes, RealmModel realm, UserPermissionEvaluator usersEvaluator, Boolean briefRepresentation, Integer firstResult, Integer maxResults, Boolean includeServiceAccounts) { attributes.put(UserModel.INCLUDE_SERVICE_ACCOUNT, includeServiceAccounts.toString()); - if (!auth.users().canView()) { - Set<String> groupModels = auth.groups().getGroupsWithViewPermission(); - - if (!groupModels.isEmpty()) { - session.setAttribute(UserModel.GROUPS, groupModels); - } + Set<String> groupIds = auth.groups().getGroupIdsWithViewPermission(); + if (!groupIds.isEmpty()) { + session.setAttribute(UserModel.GROUPS, groupIds); } - Stream<UserModel> userModels = session.users().searchForUserStream(realm, attributes, firstResult, maxResults); - return toRepresentation(realm, usersEvaluator, briefRepresentation, userModels); + return toRepresentation(realm, usersEvaluator, briefRepresentation, session.users().searchForUserStream(realm, attributes, firstResult, maxResults)); } private Stream<BruteUser> toRepresentation(RealmModel realm, UserPermissionEvaluator usersEvaluator, @@ -33,6 +33,7 @@ import org.keycloak.models.ClientModel; import org.keycloak.models.ClientProvider; import org.keycloak.models.Constants; +import org.keycloak.models.GroupModel; import org.keycloak.models.KeycloakSession; import org.keycloak.models.ModelException; import org.keycloak.models.ModelIllegalStateException; @@ -50,27 +51,42 @@ import org.keycloak.representations.idm.authorization.ScopeRepresentation; public class AdminPermissionsSchema extends AuthorizationSchema { - - public static final String USERS_RESOURCE_TYPE = "Users"; + public static final String CLIENTS_RESOURCE_TYPE = "Clients"; + public static final String GROUPS_RESOURCE_TYPE = "Groups"; + public static final String USERS_RESOURCE_TYPE = "Users"; - //scopes + // common scopes public static final String MANAGE = "manage"; public static final String VIEW = "view"; - public static final String IMPERSONATE = "impersonate"; - public static final String MAP_ROLES = "map-roles"; - public static final String MANAGE_GROUP_MEMBERSHIP = "manage-group-membership"; + + // client specific scopes public static final String CONFIGURE = "configure"; public static final String MAP_ROLES_CLIENT_SCOPE = "map-roles-client-scope"; public static final String MAP_ROLES_COMPOSITE = "map-roles-composite"; - public static final ResourceType USERS = new ResourceType(USERS_RESOURCE_TYPE, Set.of(MANAGE, VIEW, IMPERSONATE, MAP_ROLES, MANAGE_GROUP_MEMBERSHIP)); + // group specific scopes + public static final String MANAGE_MEMBERSHIP = "manage-membership"; + public static final String MANAGE_MEMBERS = "manage-members"; + public static final String VIEW_MEMBERS = "view-members"; + + // user specific scopes + public static final String IMPERSONATE = "impersonate"; + public static final String MAP_ROLES = "map-roles"; + public static final String MANAGE_GROUP_MEMBERSHIP = "manage-group-membership"; + public static final ResourceType CLIENTS = new ResourceType(CLIENTS_RESOURCE_TYPE, Set.of(CONFIGURE, MANAGE, MAP_ROLES, MAP_ROLES_CLIENT_SCOPE, MAP_ROLES_COMPOSITE, VIEW)); + public static final ResourceType GROUPS = new ResourceType(GROUPS_RESOURCE_TYPE, Set.of(MANAGE, VIEW, MANAGE_MEMBERSHIP, MANAGE_MEMBERS, VIEW_MEMBERS)); + public static final ResourceType USERS = new ResourceType(USERS_RESOURCE_TYPE, Set.of(MANAGE, VIEW, IMPERSONATE, MAP_ROLES, MANAGE_GROUP_MEMBERSHIP)); public static final AdminPermissionsSchema SCHEMA = new AdminPermissionsSchema(); private AdminPermissionsSchema() { - super(Map.of(USERS_RESOURCE_TYPE, USERS, CLIENTS_RESOURCE_TYPE, CLIENTS)); + super(Map.of( + CLIENTS_RESOURCE_TYPE, CLIENTS, + GROUPS_RESOURCE_TYPE, GROUPS, + USERS_RESOURCE_TYPE, USERS + )); } public Resource getOrCreateResource(KeycloakSession session, ResourceServer resourceServer, String policyType, String resourceType, String id) { @@ -86,12 +102,13 @@ public Resource getOrCreateResource(KeycloakSession session, ResourceServer reso return resource; } - String name = null; + String name; - if (USERS.getType().equals(resourceType)) { - name = resolveUser(session, id); - } else if (CLIENTS.getType().equals(resourceType)) { - name = resolveClient(session, id); + switch (resourceType) { + case CLIENTS_RESOURCE_TYPE -> name = resolveClient(session, id); + case GROUPS_RESOURCE_TYPE -> name = resolveGroup(session, id); + case USERS_RESOURCE_TYPE -> name = resolveUser(session, id); + default -> throw new IllegalStateException("Resource type [" + resourceType + "] not found."); } if (name == null) { @@ -161,6 +178,13 @@ public void throwExceptionIfAdminPermissionClient(KeycloakSession session, Strin } } + private String resolveGroup(KeycloakSession session, String id) { + RealmModel realm = session.getContext().getRealm(); + GroupModel group = session.groups().getGroupById(realm, id); + + return group == null ? null : group.getId(); + } + private String resolveUser(KeycloakSession session, String id) { RealmModel realm = session.getContext().getRealm(); UserModel user = session.users().getUserById(realm, id); @@ -173,10 +173,6 @@ public static GroupRepresentation toRepresentation(GroupModel group, boolean ful return rep; } - public static Stream<GroupModel> searchGroupModelsByAttributes(KeycloakSession session, RealmModel realm, Map<String,String> attributes, Integer first, Integer max) { - return session.groups().searchGroupsByAttributes(realm, attributes, first, max); - } - @Deprecated public static Stream<GroupRepresentation> toGroupHierarchy(KeycloakSession session, RealmModel realm, boolean full) { return session.groups().getTopLevelGroupsStream(realm, null, null) @@ -174,10 +174,9 @@ public Stream<GroupRepresentation> getSubGroups( @Parameter(description = "The maximum number of results that are to be returned. Defaults to 10") @QueryParam("max") @DefaultValue("10") Integer max, @Parameter(description = "Boolean which defines whether brief groups representations are returned or not (default: false)") @QueryParam("briefRepresentation") @DefaultValue("false") Boolean briefRepresentation) { this.auth.groups().requireView(group); - boolean canViewGlobal = auth.groups().canView(); return paginatedStream( group.getSubGroupsStream(search, exact, -1, -1) - .filter(g -> canViewGlobal || auth.groups().canView(g)), first, max) + .filter(auth.groups()::canView), first, max) .map(g -> GroupUtils.populateSubGroupCount(g, GroupUtils.toRepresentation(auth.groups(), g, !briefRepresentation))); } @@ -204,7 +203,7 @@ public Response addChild(GroupRepresentation rep) { try { Response.ResponseBuilder builder = Response.status(204); - GroupModel child = null; + GroupModel child; if (rep.getId() != null) { child = realm.getGroupById(rep.getId()); if (child == null) { @@ -47,7 +47,6 @@ import org.keycloak.models.KeycloakSession; import org.keycloak.models.ModelDuplicateException; import org.keycloak.models.RealmModel; -import org.keycloak.models.utils.ModelToRepresentation; import org.keycloak.organization.utils.Organizations; import org.keycloak.representations.idm.GroupRepresentation; import org.keycloak.services.ErrorResponse; @@ -100,7 +99,7 @@ public Stream<GroupRepresentation> getGroups(@QueryParam("search") String search Stream<GroupModel> stream; if (Objects.nonNull(searchQuery)) { Map<String, String> attributes = SearchQueryUtils.getFields(searchQuery); - stream = ModelToRepresentation.searchGroupModelsByAttributes(session, realm, attributes, firstResult, maxResults); + stream = session.groups().searchGroupsByAttributes(realm, attributes, firstResult, maxResults); } else if (Objects.nonNull(search)) { stream = session.groups().searchForGroupByNameStream(realm, search.trim(), exact, firstResult, maxResults); } else { @@ -110,9 +109,8 @@ public Stream<GroupRepresentation> getGroups(@QueryParam("search") String search if (populateHierarchy) { return GroupUtils.populateGroupHierarchyFromSubGroups(session, realm, stream, !briefRepresentation, groupsEvaluator); } - boolean canViewGlobal = groupsEvaluator.canView(); - return stream - .filter(g -> canViewGlobal || groupsEvaluator.canView(g)) + + return stream.filter(groupsEvaluator::canView) .map(g -> GroupUtils.populateSubGroupCount(g, GroupUtils.toRepresentation(groupsEvaluator, g, !briefRepresentation))); } @@ -71,7 +71,6 @@ import java.util.Optional; import java.util.Properties; import java.util.Set; -import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -396,7 +395,7 @@ public Integer getUsersCount( } else if (userPermissionEvaluator.canView()) { return session.users().getUsersCount(realm, search.trim()); } else { - return session.users().getUsersCount(realm, search.trim(), auth.groups().getGroupsWithViewPermission()); + return session.users().getUsersCount(realm, search.trim(), auth.groups().getGroupIdsWithViewPermission()); } } else if (last != null || first != null || email != null || username != null || emailVerified != null || enabled != null || !searchAttributes.isEmpty()) { Map<String, String> parameters = new HashMap<>(); @@ -423,12 +422,12 @@ public Integer getUsersCount( if (userPermissionEvaluator.canView()) { return session.users().getUsersCount(realm, parameters); } else { - return session.users().getUsersCount(realm, parameters, auth.groups().getGroupsWithViewPermission()); + return session.users().getUsersCount(realm, parameters, auth.groups().getGroupIdsWithViewPermission()); } } else if (userPermissionEvaluator.canView()) { return session.users().getUsersCount(realm); } else { - return session.users().getUsersCount(realm, auth.groups().getGroupsWithViewPermission()); + return session.users().getUsersCount(realm, auth.groups().getGroupIdsWithViewPermission()); } } @@ -446,16 +445,12 @@ public UserProfileResource userProfile() { private Stream<UserRepresentation> searchForUser(Map<String, String> attributes, RealmModel realm, UserPermissionEvaluator usersEvaluator, Boolean briefRepresentation, Integer firstResult, Integer maxResults, Boolean includeServiceAccounts) { attributes.put(UserModel.INCLUDE_SERVICE_ACCOUNT, includeServiceAccounts.toString()); - if (!auth.users().canView()) { - Set<String> groupModels = auth.groups().getGroupsWithViewPermission(); - - if (!groupModels.isEmpty()) { - session.setAttribute(UserModel.GROUPS, groupModels); - } + Set<String> groupIds = auth.groups().getGroupIdsWithViewPermission(); + if (!groupIds.isEmpty()) { + session.setAttribute(UserModel.GROUPS, groupIds); } - Stream<UserModel> userModels = session.users().searchForUserStream(realm, attributes, firstResult, maxResults).filter(usersEvaluator::canView); - return toRepresentation(realm, usersEvaluator, briefRepresentation, userModels); + return toRepresentation(realm, usersEvaluator, briefRepresentation, session.users().searchForUserStream(realm, attributes, firstResult, maxResults)); } private Stream<UserRepresentation> toRepresentation(RealmModel realm, UserPermissionEvaluator usersEvaluator, Boolean briefRepresentation, Stream<UserModel> userModels) { @@ -71,10 +71,10 @@ public static AdminPermissionManagement management(KeycloakSession session, Real } public static void registerListener(ProviderEventManager manager) { - manager.register(new ProviderEventListener() { - @Override - public void onEvent(ProviderEvent event) { - if (Profile.isFeatureEnabled(Profile.Feature.ADMIN_FINE_GRAINED_AUTHZ)) { + if (Profile.isFeatureEnabled(Profile.Feature.ADMIN_FINE_GRAINED_AUTHZ)) { + manager.register(new ProviderEventListener() { + @Override + public void onEvent(ProviderEvent event) { if (event instanceof RoleContainerModel.RoleRemovedEvent) { RoleContainerModel.RoleRemovedEvent cast = (RoleContainerModel.RoleRemovedEvent) event; RoleModel role = cast.getRole(); @@ -94,8 +94,8 @@ public void onEvent(ProviderEvent event) { management(cast.getKeycloakSession(), cast.getRealm()).groups().setPermissionsEnabled(cast.getGroup(), false); } } - } - }); + }); + } } @@ -16,6 +16,8 @@ */ package org.keycloak.services.resources.admin.permissions; +import org.keycloak.authorization.AdminPermissionsSchema; +import org.keycloak.models.AdminRoles; import org.keycloak.models.GroupModel; import java.util.Map; @@ -26,41 +28,121 @@ * @version $Revision: 1 $ */ public interface GroupPermissionEvaluator { + + /** + * Returns {@code true} if the caller has at least one of {@link AdminRoles#QUERY_GROUPS}, + * {@link AdminRoles#MANAGE_USERS} or {@link AdminRoles#VIEW_USERS} roles. + * <p/> + * For V2 only: Also if it has a permission to {@link AdminPermissionsSchema#VIEW} or + * {@link AdminPermissionsSchema#MANAGE} groups. + */ boolean canList(); + /** + * Throws ForbiddenException if {@link #canList()} returns {@code false}. + */ void requireList(); + /** + * Returns {@code true} if the caller has {@link AdminRoles#MANAGE_USERS} role. + * <p/> + * Or if it has a permission to {@link AdminPermissionsSchema#MANAGE} the group. + */ boolean canManage(GroupModel group); + /** + * Throws ForbiddenException if {@link #canManage(GroupModel)} returns {@code false}. + */ void requireManage(GroupModel group); + /** + * Returns {@code true} if the caller has one of {@link AdminRoles#MANAGE_USERS} or + * {@link AdminRoles#VIEW_USERS} roles. + * <p/> + * Or if it has a permission to {@link AdminPermissionsSchema#VIEW} or + * {@link AdminPermissionsSchema#MANAGE} the group. + */ boolean canView(GroupModel group); + /** + * Throws ForbiddenException if {@link #canView(GroupModel)} returns {@code false}. + */ void requireView(GroupModel group); + /** + * Returns {@code true} if the caller has {@link AdminRoles#MANAGE_USERS} role. + * <p/> + * For V2 only: Also if it has permission to {@link AdminPermissionsSchema#VIEW} or + * {@link AdminPermissionsSchema#MANAGE} groups. + */ boolean canManage(); + /** + * Throws ForbiddenException if {@link #canManage()} returns {@code false}. + */ void requireManage(); + /** + * Returns {@code true} if the caller has one of {@link AdminRoles#MANAGE_USERS} or + * {@link AdminRoles#VIEW_USERS} roles. + * <p/> + * Or if it has a permission to {@link AdminPermissionsSchema#VIEW} or + * {@link AdminPermissionsSchema#MANAGE} groups. + */ boolean canView(); + /** + * Throws ForbiddenException if {@link #canView()} returns {@code false}. + */ void requireView(); - boolean getGroupsWithViewPermission(GroupModel group); - + /** + * Throws ForbiddenException if {@link #canViewMembers(GroupModel)} returns {@code false}. + */ void requireViewMembers(GroupModel group); + /** + * Returns {@code true} if {@link UserPermissionEvaluator#canManage()} evaluates to {@code true}. + * <p/> + * Or if it has a permission to {@link AdminPermissionsSchema#MANAGE_MEMBERS} of the group. + */ boolean canManageMembers(GroupModel group); + /** + * Returns {@code true} if the caller has one of {@link AdminRoles#MANAGE_USERS} role. + * <p/> + * Or if it has a permission to {@link AdminPermissionsSchema#MANAGE} the group or + * {@link AdminPermissionsSchema#MANAGE_MEMBERSHIP} of the group. + */ boolean canManageMembership(GroupModel group); - + + /** + * Returns {@code true} if {@link UserPermissionEvaluator#canView()} evaluates to {@code true}. + * <p/> + * Or if it has a permission to {@link AdminPermissionsSchema#VIEW_MEMBERS} or + * {@link AdminPermissionsSchema#MANAGE_MEMBERS} of the group. + */ boolean canViewMembers(GroupModel group); - + + /** + * Throws ForbiddenException if {@link #canManageMembership(GroupModel)} returns {@code false}. + */ void requireManageMembership(GroupModel group); + /** + * Throws ForbiddenException if {@link #canManageMembership(GroupModel)} returns {@code false}. + */ void requireManageMembers(GroupModel group); + /** + * Returns Map with information what access the caller for the provided group has. + */ Map<String, Boolean> getAccess(GroupModel group); - Set<String> getGroupsWithViewPermission(); + /** + * If {@link UserPermissionEvaluator#canView()} evaluates to {@code true}, returns empty set. + * + * @return Stream of IDs of groups with view permission. + */ + Set<String> getGroupIdsWithViewPermission(); } @@ -53,9 +53,9 @@ class GroupPermissions implements GroupPermissionEvaluator, GroupPermissionManag private static final String RESOURCE_NAME_PREFIX = "group.resource."; private final AuthorizationProvider authz; - private final MgmtPermissions root; - private final ResourceStore resourceStore; - private final PolicyStore policyStore; + protected final MgmtPermissions root; + protected final ResourceStore resourceStore; + protected final PolicyStore policyStore; GroupPermissions(AuthorizationProvider authz, MgmtPermissions root) { this.authz = authz; @@ -73,7 +73,6 @@ private static String getGroupResourceName(GroupModel group) { return RESOURCE_NAME_PREFIX + group.getId(); } - private static String getManagePermissionGroup(GroupModel group) { return "manage.permission.group." + group.getId(); } @@ -147,7 +146,7 @@ private void initialize(GroupModel group) { @Override public boolean canList() { - return canView() || root.hasOneAdminRole(AdminRoles.VIEW_USERS, AdminRoles.MANAGE_USERS, AdminRoles.QUERY_GROUPS); + return root.hasOneAdminRole(AdminRoles.QUERY_GROUPS) || canView(); } @Override @@ -273,7 +272,7 @@ public void requireView(GroupModel group) { @Override public boolean canManage() { - return root.users().canManageDefault(); + return root.hasOneAdminRole(AdminRoles.MANAGE_USERS); } @Override @@ -282,9 +281,10 @@ public void requireManage() { throw new ForbiddenException(); } } + @Override public boolean canView() { - return root.users().canViewDefault(); + return root.hasOneAdminRole(AdminRoles.MANAGE_USERS, AdminRoles.VIEW_USERS); } @Override @@ -295,24 +295,8 @@ public void requireView() { } @Override - public boolean getGroupsWithViewPermission(GroupModel group) { - if (root.users().canView() || root.users().canManage()) { - return true; - } - - if (!root.isAdminSameRealm()) { - return false; - } - - ResourceServer server = root.realmResourceServer(); - if (server == null) return false; - - return hasPermission(group, VIEW_MEMBERS_SCOPE, MANAGE_MEMBERS_SCOPE); - } - - @Override - public Set<String> getGroupsWithViewPermission() { - if (root.users().canView() || root.users().canManage()) return Collections.emptySet(); + public Set<String> getGroupIdsWithViewPermission() { + if (root.users().canView()) return Collections.emptySet();
Leaderboard for this case
hard · 2 of 9 bots fully caught it (22% solve rate) · 74% avg coverage.
| # | Bot | Result | Caught | Coverage | Findings | False alarms |
|---|---|---|---|---|---|---|
| 1 | Claude Code (Opus 5.5) | solved | 3/3 | 100.0% | 3 | 0 |
| 2 | Drape (Review) | solved | 3/3 | 100.0% | 3 | 0 |
| 3 | cursor | partial | 2/3 | 80.0% | 2 | 0 |
| 4 | Drape (Deep Review) | partial | 2/3 | 80.0% | 3 | 0 |
| 5 | greptile | partial | 2/3 | 80.0% | 2 | 0 |
| 6 | Mjolnir (Opus 5.5) | partial | 2/3 | 80.0% | 4 | 0 |
| 7 | Mjolnir (Sonnet 5.5) | partial | 2/3 | 80.0% | 4 | 0 |
| 8 | qodo | partial | 2/3 | 80.0% | 6 | 0 |
| 9 | Cubic | partial | 2/3 | 80.0% | 6 | 1 |
Bot results
Claude Code (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | exact |
| d2 | high | ✓ | exact |
| d3 | medium | ✓ | off by one |
raw comments (3)
Privilege escalation: `canManage()` returns true when the caller has only the `VIEW` scope on all groups (`hasPermission(null, VIEW, MANAGE)`). An admin who was given read-only access to groups can then reach endpoints guarded by `groups().requireManage()`, such as creating top-level groups. Only `MANAGE` should be accepted here, the same way `canManage(GroupModel)` does it.
`getGroupIdsWithViewPermission()` uses `groupResource.getId()` (the authz resource's id) where it needs `groupResource.getName()`. In V2 the resource name is the group id (see `AdminPermissionsSchema.resolveGroup`). This breaks two things. (1) `hasPermission(groupResource.getId(), ...)` looks up the resource with `findByName` using the resource id, finds nothing, and falls back to the all-groups resource. As a result, per-group view-members/manage-members permissions are never applied, and every resource counts as granted whenever an all-groups permission exists. (2) The returned set holds resource ids, not group ids. It is put in `UserModel.GROUPS` to filter user search/count in the JPA provider, so it matches no groups. Admins who should see members of specific groups get empty or wrong user lists and counts. The loop also visits the 'Groups' type resource itself and can add its id to the set.
The cached `canViewGlobal` short-circuit was removed, so `auth.groups().canView(g)` now runs for every subgroup (and every group in `GroupsResource`). With V2 that means a full authz policy evaluation per group, even when the caller could already view all groups. This makes large group listings much slower.
Cubic · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | exact |
| d2 | high | ✓ | off by one |
| d3 | medium | ✗ | — |
In V2, canView(GroupModel) falls back to the all-groups resource when the group has no resource of its own, so an all-groups VIEW permission still grants access to each group. testViewGroups checks exactly this: it expects 2 groups after the all-groups VIEW permission is created. In V1, canView(group) checks canView() first. The empty list the finding predicts does not happen. [invalid: contradiction] [consensus 4/5: invalid=4, valid=1]
The change added the GROUPS resource type, and its group resources are named by group ID. getResourceName only resolves users, so for groups it falls back to getDisplayName(), which is never set for these resources. The added type is therefore only partly integrated. [grounded: tree server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java] [consensus 5/5: valid=5]
This is a Javadoc wording mismatch only. [grounded: diff] [consensus 5/5: minor=5]
The Javadoc link is wrong, but runtime behaviour is unaffected. [grounded: diff] [consensus 5/5: minor=5]
raw comments (7)
<!-- cubic:v=a865ad88-8122-4af7-9646-b46a0fc80c93 -->
<!-- cubic:review-run=d54fac63-bbc2-5149-856c-cc8d507a5795 -->
<!-- metadata:{"confidence":9} -->
P1: When an admin has only `VIEW` permission on all groups, this factory selects `GroupPermissionsV2`, whose global `canManage()` also accepts `VIEW`; `GroupsResource.addTopLevelGroup()` then allows group creation. Make the V2 management check require `MANAGE` instead of treating `VIEW` as sufficient.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At services/src/main/java/org/keycloak/services/resources/admin/permissions/MgmtPermissionsV2.java, line 60:
<comment>When an admin has only `VIEW` permission on all groups, this factory selects `GroupPermissionsV2`, whose global `canManage()` also accepts `VIEW`; `GroupsResource.addTopLevelGroup()` then allows group creation. Make the V2 management check require `MANAGE` instead of treating `VIEW` as sufficient.</comment>
<file context>
@@ -53,6 +54,13 @@ public ClientModel getRealmPermissionsClient() {
+ @Override
+ public GroupPermissions groups() {
+ if (groupPermissions != null) return groupPermissions;
+ groupPermissions = new GroupPermissionsV2(session, authz, this);
+ return groupPermissions;
+ }
</file context>
```
</details>
<!-- cubic:v=c59c5979-89da-41e0-9f44-da837c6506f9 -->
<!-- cubic:review-run=d54fac63-bbc2-5149-856c-cc8d507a5795 -->
<!-- metadata:{"confidence":10} -->
P1: When an admin has the V2 all-groups VIEW permission, this filter calls only `canView(GroupModel)` and can return an empty list despite `requireList()` succeeding. Preserve the global permission check before evaluating each group.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At services/src/main/java/org/keycloak/services/resources/admin/GroupsResource.java, line 113:
<comment>When an admin has the V2 all-groups VIEW permission, this filter calls only `canView(GroupModel)` and can return an empty list despite `requireList()` succeeding. Preserve the global permission check before evaluating each group.</comment>
<file context>
@@ -110,9 +109,8 @@ public Stream<GroupRepresentation> getGroups(@QueryParam("search") String search
- return stream
- .filter(g -> canViewGlobal || groupsEvaluator.canView(g))
+
+ return stream.filter(groupsEvaluator::canView)
.map(g -> GroupUtils.populateSubGroupCount(g, GroupUtils.toRepresentation(groupsEvaluator, g, !briefRepresentation)));
}
</file context>
```
</details>
```suggestion
return stream.filter(g -> groupsEvaluator.canView() || groupsEvaluator.canView(g))
```
<!-- cubic:v=525c44b1-36d6-40ef-8d3d-b3b67b388fc1 -->
<!-- cubic:review-run=d54fac63-bbc2-5149-856c-cc8d507a5795 -->
<!-- metadata:{"confidence":9} -->
P2: When a group-specific policy's resources are listed, the new group resource has no usable display name. Add a `GROUPS` branch in `getResourceName()` that resolves the group by `resource.getName()` and returns its name or path, like the existing user branch.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java, line 79:
<comment>When a group-specific policy's resources are listed, the new group resource has no usable display name. Add a `GROUPS` branch in `getResourceName()` that resolves the group by `resource.getName()` and returns its name or path, like the existing user branch.</comment>
<file context>
@@ -50,27 +51,42 @@
+ public static final String MANAGE_GROUP_MEMBERSHIP = "manage-group-membership";
+
public static final ResourceType CLIENTS = new ResourceType(CLIENTS_RESOURCE_TYPE, Set.of(CONFIGURE, MANAGE, MAP_ROLES, MAP_ROLES_CLIENT_SCOPE, MAP_ROLES_COMPOSITE, VIEW));
+ public static final ResourceType GROUPS = new ResourceType(GROUPS_RESOURCE_TYPE, Set.of(MANAGE, VIEW, MANAGE_MEMBERSHIP, MANAGE_MEMBERS, VIEW_MEMBERS));
+ public static final ResourceType USERS = new ResourceType(USERS_RESOURCE_TYPE, Set.of(MANAGE, VIEW, IMPERSONATE, MAP_ROLES, MANAGE_GROUP_MEMBERSHIP));
</file context>
```
</details>
<!-- cubic:v=aafd26ef-93ed-473e-a100-93e8eb200e87 -->
<!-- cubic:review-run=d54fac63-bbc2-5149-856c-cc8d507a5795 -->
<!-- metadata:{"confidence":10} -->
P2: Group-restricted user listings cannot resolve these values as group IDs. Pass the resource name to `hasPermission` and return that name instead of the authorization resource UUID.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java, line 123:
<comment>Group-restricted user listings cannot resolve these values as group IDs. Pass the resource name to `hasPermission` and return that name instead of the authorization resource UUID.</comment>
<file context>
@@ -0,0 +1,211 @@
+
+ resourceStore.findByType(server, AdminPermissionsSchema.GROUPS_RESOURCE_TYPE, groupResource -> {
+ if (hasPermission(groupResource.getId(), AdminPermissionsSchema.VIEW_MEMBERS, AdminPermissionsSchema.MANAGE_MEMBERS)) {
+ granted.add(groupResource.getId());
+ }
+ });
</file context>
```
</details>
```suggestion
if (hasPermission(groupResource.getName(), AdminPermissionsSchema.VIEW_MEMBERS, AdminPermissionsSchema.MANAGE_MEMBERS)) {
granted.add(groupResource.getName());
```
<!-- cubic:v=ba49e710-719f-4d55-9c78-a9eb3991c3a8 -->
<!-- cubic:review-run=d54fac63-bbc2-5149-856c-cc8d507a5795 -->
<!-- metadata:{"confidence":10} -->
P3: The new method returns a `Set<String>`, but its `@return` tag says `Stream`; update the tag to document the actual return type.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionEvaluator.java, line 145:
<comment>The new method returns a `Set<String>`, but its `@return` tag says `Stream`; update the tag to document the actual return type.</comment>
<file context>
@@ -26,41 +28,121 @@
+ /**
+ * If {@link UserPermissionEvaluator#canView()} evaluates to {@code true}, returns empty set.
+ *
+ * @return Stream of IDs of groups with view permission.
+ */
+ Set<String> getGroupIdsWithViewPermission();
</file context>
```
</details>
```suggestion
* @return Set of IDs of groups with view permission.
```
<!-- cubic:v=747a1365-e9d2-45f8-8780-3569c2be1408 -->
<!-- cubic:review-run=d54fac63-bbc2-5149-856c-cc8d507a5795 -->
<!-- metadata:{"confidence":10} -->
P3: `requireManageMembers` is documented as checking `canManageMembership`, but its implementations check `canManageMembers`; correct the link so the API docs describe the required authorization.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionEvaluator.java, line 128:
<comment>`requireManageMembers` is documented as checking `canManageMembership`, but its implementations check `canManageMembers`; correct the link so the API docs describe the required authorization.</comment>
<file context>
@@ -26,41 +28,121 @@
-
+
+ /**
+ * Throws ForbiddenException if {@link #canManageMembership(GroupModel)} returns {@code false}.
+ */
void requireManageMembership(GroupModel group);
</file context>
```
</details>
```suggestion
* Throws ForbiddenException if {@link #canManageMembers(GroupModel)} returns {@code false}.
```
<!-- cubic:review-summary:start -->
**6 issues found** across 19 files
<!-- cubic:review-summary:end -->
<details>
<summary>Prompt for AI agents (unresolved issues)</summary>
```text
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="services/src/main/java/org/keycloak/services/resources/admin/permissions/MgmtPermissionsV2.java">
<violation number="1" location="services/src/main/java/org/keycloak/services/resources/admin/permissions/MgmtPermissionsV2.java:60">
P1: When an admin has only `VIEW` permission on all groups, this factory selects `GroupPermissionsV2`, whose global `canManage()` also accepts `VIEW`; `GroupsResource.addTopLevelGroup()` then allows group creation. Make the V2 management check require `MANAGE` instead of treating `VIEW` as sufficient.</violation>
</file>
<file name="services/src/main/java/org/keycloak/services/resources/admin/GroupsResource.java">
<violation number="1" location="services/src/main/java/org/keycloak/services/resources/admin/GroupsResource.java:113">
P1: When an admin has the V2 all-groups VIEW permission, this filter calls only `canView(GroupModel)` and can return an empty list despite `requireList()` succeeding. Preserve the global permission check before evaluating each group.</violation>
</file>
<file name="server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java">
<violation number="1" location="server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java:79">
P2: When a group-specific policy's resources are listed, the new group resource has no usable display name. Add a `GROUPS` branch in `getResourceName()` that resolves the group by `resource.getName()` and returns its name or path, like the existing user branch.</violation>
</file>
<file name="services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java">
<violation number="1" location="services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:123">
P2: Group-restricted user listings cannot resolve these values as group IDs. Pass the resource name to `hasPermission` and return that name instead of the authorization resource UUID.</violation>
</file>
<file name="services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionEvaluator.java">
<violation number="1" location="services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionEvaluator.java:128">
P3: `requireManageMembers` is documented as checking `canManageMembership`, but its implementations check `canManageMembers`; correct the link so the API docs describe the required authorization.</violation>
<violation number="2" location="services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionEvaluator.java:145">
P3: The new method returns a `Set<String>`, but its `@return` tag says `Stream`; update the tag to document the actual return type.</violation>
</file>
```
</details>
<sub>Reply with feedback, questions, or to request a fix.<br /><br />[Re-trigger cubic](https://www.cubic.dev/action/re-review/pr/drape-io/crbench-cubic-2026-09/92/ai_pr_review_github_delivery_e49f89418df6d819f18c280b1329576f3ed42faa3754e0db79f089df0e496b07?returnTo=https%3A%2F%2Fgithub.com%2Fdrape-io%2Fcrbench-cubic-2026-09%2Fpull%2F92)</sub>
<!-- cubic:review-post:ai_pr_review_github_delivery_e49f89418df6d819f18c280b1329576f3ed42faa3754e0db79f089df0e496b07:4a46ee4f81563ab33eadacd8a3fb0daebf381f7b:d54fac63-bbc2-5149-856c-cc8d507a5795 -->
cursor · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | exact |
| d2 | high | ✓ | exact |
| d3 | medium | ✗ | — |
raw comments (3)
### VIEW grants global group manage
**High Severity**
<!-- DESCRIPTION START -->
`canManage()` treats all-groups `view` as sufficient to manage groups. Creating a top-level group goes through `requireManage()`, so an admin with only `view` on all groups can create and move groups. Per-group `canManage` correctly requires `manage` only, matching `ClientPermissionsV2`.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 4846599b-233c-4aad-80a5-bdac5563c2e4 -->
<!-- LOCATIONS START
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java#L64-L70
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmQ0NmIzNzE5LWYzMjctNDY4Ny05YzkwLWE5NmU4ZjkwMDJkMCIsImVuY3J5cHRpb25LZXkiOiJCYjRwWlBwaG1hUXpqc1p3Zzg1MTl6d2NRR0U0THpRdjhaMjJTQ01kSzNvIiwiYnJhbmNoIjoidDIta2V5Y2xvYWstMzcwMzgiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmQ0NmIzNzE5LWYzMjctNDY4Ny05YzkwLWE5NmU4ZjkwMDJkMCIsImVuY3J5cHRpb25LZXkiOiJCYjRwWlBwaG1hUXpqc1p3Zzg1MTl6d2NRR0U0THpRdjhaMjJTQ01kSzNvIiwiYnJhbmNoIjoidDIta2V5Y2xvYWstMzcwMzgiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByTnVtYmVyIjo1NSwiY29tbWl0U2hhIjoiM2QzYzk2ZDFiODA1MGJhZmU5YzcyY2MwODNkMDAwMzdkY2VlMTNjYyIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 3d3c96d1b8050bafe9c72cc083d00037dcee13cc. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### Wrong IDs for group view permission
**High Severity**
<!-- DESCRIPTION START -->
`getGroupIdsWithViewPermission` passes and collects `groupResource.getId()` (authorization resource primary key) instead of the realm group id stored as `resource.getName()`. `hasPermission` then looks up by name and misses the group, so user search counts and DB pre-filtering for `VIEW_MEMBERS` use empty or invalid group ids.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: bf497018-dabe-4a6b-a6c9-a0f5ff4a0f40 -->
<!-- LOCATIONS START
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java#L120-L124
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmZhMTg0YTBiLWVhOTAtNDUxNy1hZmQ1LTIxZjdlMDJmOGIwMCIsImVuY3J5cHRpb25LZXkiOiJWcUowM1pPV3RQVkxwa2FmOGZLQzktU3pYRjVLakNWTDRLVnFObHBoTFNRIiwiYnJhbmNoIjoidDIta2V5Y2xvYWstMzcwMzgiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmZhMTg0YTBiLWVhOTAtNDUxNy1hZmQ1LTIxZjdlMDJmOGIwMCIsImVuY3J5cHRpb25LZXkiOiJWcUowM1pPV3RQVkxwa2FmOGZLQzktU3pYRjVLakNWTDRLVnFObHBoTFNRIiwiYnJhbmNoIjoidDIta2V5Y2xvYWstMzcwMzgiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByTnVtYmVyIjo1NSwiY29tbWl0U2hhIjoiM2QzYzk2ZDFiODA1MGJhZmU5YzcyY2MwODNkMDAwMzdkY2VlMTNjYyIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 3d3c96d1b8050bafe9c72cc083d00037dcee13cc. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- BUGBOT_REVIEW -->
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
<!-- BUGBOT_FIX_ALL -->
<a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9BTExfSU5fQ1VSU09SIiwiZGF0YSI6eyJyZWRpc0tleSI6ImJ1Z2JvdC1tdWx0aTpiYzZjNDI1MC00MjZmLTQ5ZmEtYmU4Ni0wNGIxNzA5YzBhYWIiLCJlbmNyeXB0aW9uS2V5IjoidFNtaTAxemlja1Jpd25lak5XX0x0aDRxajZzT3ZSRVBaMEpsNmZUejZJQSIsImJyYW5jaCI6InQyLWtleWNsb2FrLTM3MDM4IiwicmVwb093bmVyIjoiZHJhcGUtaW8iLCJyZXBvTmFtZSI6ImNyYmVuY2gtY3Vyc29yLTIwMjYtMDkiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix All in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a>
<!-- /BUGBOT_FIX_ALL -->
<!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_BEGIN -->
<sup>❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_END -->
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 3d3c96d1b8050bafe9c72cc083d00037dcee13cc. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
Drape (Deep Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | exact |
| d2 | high | ✓ | exact |
| d3 | medium | ✗ | — |
`init` returns early when the admin-permissions client already exists, so realms set up before this change never get the new "Groups" type resource. In those realms `getResourceTypeResource` returns null (it is just `findByName`). The cached `findByResource` then calls `resource.getId()`, which throws an NPE. This path runs every time a group has no per-group resource, including user search through canViewByGroup → canViewMembers. The change added this code path, so it introduced the crash. [grounded: tree services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java] [consensus 3/3: valid=3]
raw comments (3)
**Group view-members lookup returns wrong IDs**
Per-group resources made by `getOrCreateResource` get no type, so `findByType("Groups")` only finds the all-groups resource. Its resource id, not a group id, goes into `granted`, and per-group VIEW_MEMBERS grants are never found. List the group resources (named by group id) and add `resource.getName()`. Skip the type resource itself.
```
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:105 @Override
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:106 public Set<String> getGroupIdsWithViewPermission() {
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:107 if (root.users().canView()) return Collections.emptySet();
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:109 if (!root.isAdminSameRealm()) {
server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java:118 resource = resourceStore.findByName(resourceServer, name);
server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java:120 if (resource == null) {
server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java:121 resource = resourceStore.create(resourceServer, name, resourceServer.getClientId());
server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java:122 ScopeStore scopeStore = storeFactory.getScopeStore();
server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java:123 resource.updateScopes(getResourceTypes().get(resourceType).getScopes().stream().map(scopeName -> {
server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java:124 Scope findByName = scopeStore.findByName(resourceServer, scopeName);
```
**Group checks crash in older realms**
`AdminPermissionsSchema.init` skips realms whose permissions client already exists, so they have no "Groups" resource. `getResourceTypeResource` then returns null, and `hasPermission` dereferences it. Return false on a null type resource, and add the Groups resource and scopes to existing realms.
```
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:143 if (resource == null) {
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:144 resource = AdminPermissionsSchema.SCHEMA.getResourceTypeResource(session, server, AdminPermissionsSchema.GROUPS_RESOURCE_TYPE);
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:146 // check if there is a permission for "all-groups". If so, proceed with the evaluation to check scopes
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:147 if (policyStore.findByResource(server, resource).isEmpty()) {
server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java:246 public void init(KeycloakSession session, RealmModel realm) {
server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java:247 ClientProvider clients = session.clients();
server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java:248 ClientModel client = realm.getAdminPermissionsClient();
server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java:250 if (client != null) {
server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java:251 return;
server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java:252 }
```
**View-only group permission grants group creation**
In V2, `canManage()` accepts the `view` scope as well as `manage`. So an admin who was only granted `view` on all groups passes `requireManage()` and can create top-level groups or move any group to the top level. Check only `AdminPermissionsSchema.MANAGE` in `canManage()`.
```
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:64 @Override
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:65 public boolean canManage() {
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:66 if (root.hasOneAdminRole(AdminRoles.MANAGE_USERS)) {
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:67 return true;
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:70 return hasPermission(null, AdminPermissionsSchema.VIEW, AdminPermissionsSchema.MANAGE);
services/src/main/java/org/keycloak/services/resources/admin/GroupsResource.java:192 if (rep.getId() != null) {
services/src/main/java/org/keycloak/services/resources/admin/GroupsResource.java:193 child = realm.getGroupById(rep.getId());
services/src/main/java/org/keycloak/services/resources/admin/GroupsResource.java:194 if (child == null) {
services/src/main/java/org/keycloak/services/resources/admin/GroupsResource.java:195 throw new NotFoundException("Could not find child by id");
services/src/main/java/org/keycloak/services/resources/admin/GroupsResource.java:196 }
```
Drape (Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | exact |
| d2 | high | ✓ | exact |
| d3 | medium | ✓ | off by one |
raw comments (3)
**View-only permission lets caller manage groups**
`canManage()` accepts the `view` scope as well as `manage`. An admin who was only granted view on all groups passes `requireManage()`, for example when creating a top-level group. Check only `AdminPermissionsSchema.MANAGE` in `canManage()`.
```
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:53 }
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:55 @Override
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:56 public boolean canView(GroupModel group) {
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:57 if (root.hasOneAdminRole(AdminRoles.MANAGE_USERS, AdminRoles.VIEW_USERS)) {
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:59 }
```
**Group-based user search returns resource IDs**
`getGroupIdsWithViewPermission` passes the resource's internal id to `hasPermission` and returns it. In V2 the group id is the resource name, and `hasPermission` looks up by name, so the lookup misses and the returned ids match no group. Use `groupResource.getName()` in both the `hasPermission` call and `granted.add`.
```
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:121 resourceStore.findByType(server, AdminPermissionsSchema.GROUPS_RESOURCE_TYPE, groupResource -> {
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:122 if (hasPermission(groupResource.getId(), AdminPermissionsSchema.VIEW_MEMBERS, AdminPermissionsSchema.MANAGE_MEMBERS)) {
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:123 granted.add(groupResource.getId());
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:124 }
```
**Group listing runs one permission evaluation per group**
The `canViewGlobal` short-circuit was removed from the group list and subgroup filters. In V2, an admin with view permission via an all-groups permission now gets a full evaluation per returned group instead of one. Evaluate the global `canView()` once and skip the per-group check when it is true.
```
services/src/main/java/org/keycloak/services/resources/admin/GroupsResource.java:113 return stream.filter(groupsEvaluator::canView)
services/src/main/java/org/keycloak/services/resources/admin/GroupsResource.java:114 .map(g -> GroupUtils.populateSubGroupCount(g, GroupUtils.toRepresentation(groupsEvaluator, g, !briefRepresentation)));
services/src/main/java/org/keycloak/services/resources/admin/GroupResource.java:176 this.auth.groups().requireView(group);
services/src/main/java/org/keycloak/services/resources/admin/GroupResource.java:177 return paginatedStream(
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:131 if (!root.isAdminSameRealm()) {
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:132 return false;
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:133 }
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:135 ResourceServer server = root.realmResourceServer();
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:137 if (server == null) {
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:138 return false;
```
greptile · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | exact |
| d2 | high | ✓ | exact |
| d3 | medium | ✗ | — |
raw comments (3)
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> <a href="#"><img alt="security" src="https://greptile-static-assets.s3.amazonaws.com/badges/Security.svg?v=2" align="top"></a> **View Permission Allows Mutations**
A caller granted only `view` on the all-groups resource passes `canManage()` because this check accepts either `VIEW` or `MANAGE`. Top-level group creation uses the no-argument `requireManage()`, so a view-only administrator can create groups or move an existing group to the top level without manage permission.
**How this was verified:** The collection mutation endpoint delegates to this check, whose granted-scope loop treats `view` as sufficient.
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> **Resource IDs Break Filtering**
`getGroupIdsWithViewPermission()` returns each authorization resource's generated ID instead of the Keycloak group ID stored in its name. These values are then compared with user-membership group IDs, so searches and counts omit users authorized through per-group `view-members` or `manage-members` permissions.
```suggestion
resourceStore.findByType(server, AdminPermissionsSchema.GROUPS_RESOURCE_TYPE, groupResource -> {
if (hasPermission(groupResource.getName(), AdminPermissionsSchema.VIEW_MEMBERS, AdminPermissionsSchema.MANAGE_MEMBERS)) {
granted.add(groupResource.getName());
}
});
```
<h3>Greptile Summary</h3>
This PR adds V2 fine-grained authorization for groups, integrates group permissions into user visibility and management checks, simplifies several authorization-filtering paths, and adds group resource-type tests.
- Defines the V2 Groups resource type and its view, manage, membership, and member scopes.
- Adds `GroupPermissionsV2` and connects it through `MgmtPermissionsV2`.
- Uses group-based permissions when listing, counting, viewing, and managing users.
- Adds integration coverage for global and per-group authorization behavior.
- Contains two authorization defects: global group view grants group creation, and per-group member visibility returns authorization-resource IDs instead of group IDs.
<h3>Confidence Score: 2/5</h3>
The PR is not safe to merge until collection-level group management requires manage permission and member visibility returns actual group IDs.
The current authorization path allows a view-only administrator to mutate the group collection, while the identifier mismatch causes legitimate per-group member permissions to produce empty or incorrect user searches and counts.
**Files Needing Attention:** services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java
<details open><summary><h3>Security Review</h3></summary>
A global `view` grant on the all-groups resource incorrectly satisfies the collection-level management check, allowing unauthorized top-level group creation or movement.
</details>
<details><summary><h3>Important Files Changed</h3></summary>
| Filename | Overview |
|----------|----------|
| services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java | Implements V2 group authorization but accepts view permission for collection management and returns authorization-resource IDs where group IDs are required. |
| services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java | Integrates group-based authorization into user searches and counts; its correctness is affected by invalid identifiers returned from `GroupPermissionsV2`. |
| server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java | Adds the Groups resource type and scopes and creates per-group resources named with the corresponding group ID. |
| tests/base/src/test/java/org/keycloak/tests/admin/authz/fgap/GroupResourceTypeEvaluationTest.java | Adds broad V2 group authorization coverage but does not exercise view-only group creation or user counts through per-group member permissions. |
| services/src/main/java/org/keycloak/services/resources/admin/permissions/UserPermissionsV2.java | Extends per-user authorization with inherited group member permissions for viewing, management, role mapping, and membership changes. |
</details>
<details open><summary><h3>Flowchart</h3></summary>
```mermaid
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Admin request] --> B{Operation}
B -->|Create top-level group| C[groups.requireManage]
C --> D[GroupPermissionsV2.canManage]
D --> E[Evaluate all-groups VIEW or MANAGE]
E -->|VIEW incorrectly accepted| F[Group mutation authorized]
B -->|Search or count users| G[getGroupIdsWithViewPermission]
G --> H[Enumerate group authorization resources]
H --> I[Return Resource IDs]
I --> J[User provider filters membership groupId]
J --> K[Authorized group members omitted]
```
</details>
<!-- greptile_other_comments_section -->
<sub>Reviews (1): Last reviewed commit: ["Update rest/admin-ui-ext/src/main/java/o..."](https://github.com/drape-io/crbench-greptile-2026-09/commit/2993aaf128d61c76fdf7a7226d335512230bcc95) | [Re-trigger Greptile](https://app.greptile.com/api/retrigger?id=64284610)</sub>
Mjolnir (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | exact |
| d2 | high | ✓ | exact |
| d3 | medium | ✗ | — |
The new V2 canManage() accepts the VIEW scope on the all-groups resource. addTopLevelGroup is guarded only by auth.groups().requireManage(), so an admin with a view-only all-groups grant can create groups. [grounded: tree services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java] [consensus 3/3: valid=3]
findByType only matches on the type field, and getOrCreateResource creates per-group resources without setting a type, so only the all-groups resource is enumerated. The method then passes the resource UUID to findByName and collects that UUID, which is not a group ID. As a result, user searches and counts are restricted to a group that does not exist. [grounded: tree services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java] [consensus 3/3: valid=3]
raw comments (4)
[P1] Group-wide `view` permission lets an admin create top-level groups
`canManage()` falls back to `hasPermission(null, AdminPermissionsSchema.VIEW, AdminPermissionsSchema.MANAGE)`, so `view` alone is enough. The other "manage" checks require `MANAGE`, for example `canManage(GroupModel)` uses `hasPermission(group.getId(), AdminPermissionsSchema.MANAGE)`. The only caller is `GroupsResource.addTopLevelGroup` (`auth.groups().requireManage()`), and that endpoint also moves existing groups to the top level. This happens when the V2 feature is enabled and an admin has an all-groups permission with only the `view` scope. That admin can then create top-level groups and re-parent existing groups, which is a privilege escalation.
[P1] `getGroupIdsWithViewPermission` never returns real group IDs
`resourceStore.findByType(server, GROUPS_RESOURCE_TYPE, ...)` only matches resources whose type is "Groups". Per-group resources created by `AdminPermissionsSchema.getOrCreateResource` get no type; their name is the group ID. So the only match is the "Groups" type resource itself. That resource's internal ID is then passed to `hasPermission`, where `findByName` finds nothing and the check falls back to the all-groups resource. On success, that same internal resource ID is added to `granted` instead of a group ID. This has two effects under V2. First, an admin who has `view-members` only on specific groups always gets an empty set, so `/users/count` returns 0 (`JpaUserProvider.getUsersCount(realm, Set)` returns 0 for an empty set). In that case search is not restricted by group: the visibility filter runs only after `first`/`max` are applied, so pages come back short or empty. Second, an admin with an all-groups `view-members` permission gets a set holding a non-existent group ID. `UserModel.GROUPS` is set to that ID, and the user search returns no users at all.
[P1] Global group `canManage()` also accepts the `view` scope
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:65-70 `GroupPermissionsV2.canManage()` returns `hasPermission(null, VIEW, MANAGE)`, which looks like it was copied from `canView()`. As a result, an admin who only has an all-groups permission with the `view` scope passes `auth.groups().requireManage()`. That check guards top-level group creation in `GroupsResource` (around line 181), so a view-only grant is enough to create groups in the realm. This contradicts the new test, which says "creating group requires manage scope". This only applies when FGAP V2 is enabled and an all-groups `view` permission exists. The check should accept only `MANAGE`.
[P2] `getGroupIdsWithViewPermission()` never finds per-group resources and returns the wrong IDs
services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java:121-124 This method has two problems. First, `resourceStore.findByType(server, "Groups", ...)` only matches resources whose `type` is `Groups`. In V2 that is only the all-groups resource created in `AdminPermissionsSchema` (`resource.setType(type)` around line 274). Per-group resources come from `getOrCreateResource` through `resourceStore.create(server, name, owner)`, which never sets a type, so they are never enumerated. Second, the method passes and collects `groupResource.getId()`, which is the authz resource UUID, but per-group resources are named by the group ID. `hasPermission` then calls `findByName` with that UUID and falls back to the all-groups resource. If an all-groups `view-members`/`manage-members` permission exists, the method returns the "Groups" resource UUID, a value that is not a group ID. `UsersResource.searchForUser`, `BruteForceUsersResource.searchForUser` and `getUsersCount` then restrict results to members of that nonexistent group. Those admins get an empty user list and a count of 0, even though they should see everyone. The loop should enumerate the actual group resources and use each resource's name (the group ID), not the resource ID.
Mjolnir (Sonnet 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | exact |
| d2 | high | ✓ | off by one |
| d3 | medium | ✗ | — |
V2 canManage() accepts the VIEW scope, so requireManage() (used to create top-level groups) passes for an admin who can only view; canManage(GroupModel) correctly requires MANAGE only. [grounded: tree services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java] [consensus 3/3: valid=3]
Group resources are named by group ID (resolveGroup returns group.getId()), and hasPermission looks them up by name. Passing the resource UUID makes that lookup miss, and the collected IDs are resource UUIDs, not group IDs. That breaks the GROUPS filtering and the user counts. [grounded: tree services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java] [consensus 3/3: valid=3]
raw comments (4)
[P1] Group `canManage()` grants access on the VIEW scope alone
In `GroupPermissionsV2.canManage()` the fallback checks `hasPermission(null, VIEW, MANAGE)`. That looks like it was copied from `canView()`. In V2, an admin who only has the "view" scope on the all-groups resource therefore passes `canManage()`. Callers such as `requireManage()` for creating top-level groups, and the "manage" flag in `getAccess`, then treat that admin as able to manage groups. This is a privilege escalation for any realm that uses admin permissions V2 and grants view-only access to groups. The check should require only `MANAGE`. The new javadoc says "VIEW or MANAGE" too, so the doc needs the same correction.
[P2] `getGroupIdsWithViewPermission` returns the resource UUID, not the group ID, and misses per-group resources
`findByType(server, "Groups", ...)` only matches the "all-groups" type resource. Per-group resources are created in `AdminPermissionsSchema.getOrCreateResource` without a type, and they are named by group ID. The callback then passes `groupResource.getId()` (the resource UUID) to `hasPermission`. There, `findByName` finds nothing and falls back to the all-groups resource. It then adds that UUID to the result set. If an admin has view-members or manage-members on all groups, the set contains one UUID that is not a group ID. `UsersResource.searchForUser` stores it in `UserModel.GROUPS`, and the user search and the count methods filter on it. Those calls return no users. Per-group view-members grants are never returned at all.
[P1] canManage() grants group management on VIEW scope
With the V2 schema, `canManage()` calls `hasPermission(null, VIEW, MANAGE)`, so an admin who only holds the `view` scope on the Groups resource type passes `canManage()`. `GroupsResource` uses `auth.groups().requireManage()` when creating a top-level group (GroupsResource.java:181), so a view-only admin can create groups. The `canManage()` Javadoc in the interface repeats the same wording ("VIEW or MANAGE"). Only `MANAGE` should be accepted, as `canManage(GroupModel)` does.
[P1] getGroupIdsWithViewPermission uses resource UUIDs where group IDs are expected
`resourceStore.findByType` yields `Resource` objects whose `getId()` is the authorization resource UUID. The group resource's name is the group ID (see `AdminPermissionsSchema.resolveGroup`). The code passes `groupResource.getId()` to `hasPermission`, which looks the resource up with `findByName(server, groupId)`. That lookup misses, so evaluation falls back to the type-level "Groups" resource instead of the specific group's permissions. It then adds the resource UUID to the returned set. `UsersResource` and `BruteForceUsersResource` put that set into `UserModel.GROUPS` to filter users and counts by group membership, so the filter never matches real group IDs. Admins with `view-members` or `manage-members` on specific groups get no users in user search and counts. It can also wrongly grant or deny access by evaluating the type resource. Use `groupResource.getName()` for both the check and the collected value.
qodo · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✓ | exact |
| d2 | high | ✓ | exact |
| d3 | medium | ✗ | — |
The all-groups resource is only used when no dedicated resource exists. DefaultPolicyEvaluator only pulls in type-level policies when resource.getType() != null, and getOrCreateResource never sets a type on concrete group resources. findByScopes(null) only matches policies that have no resource. So once a group has its own resource, an all-groups grant is not evaluated for it. [grounded: tree services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java] [consensus 3/3: valid=3]
init() returns early when the admin-permissions client already exists. The change adds the Groups type and its scopes to the schema but includes no migration, so realms initialized earlier lack the Groups resource and the new scopes. [grounded: tree server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java] [consensus 3/3: valid=3]
The only group-removal hook is registered for V1. Its V2 equivalent, setPermissionsEnabled, throws UnsupportedOperationException, and no other GroupRemovedEvent handler exists in services. So the V2 group resources created by this change stay behind after the group is deleted. [grounded: tree services/src/main/java/org/keycloak/services/resources/admin/permissions/AdminPermissions.java] [consensus 3/3: valid=3]
Concrete group resources are named by group ID and have no type, so findByType("Groups") returns only the all-groups resource. Its authz resource ID is then added to the group-ID set. With an all-groups view-members grant, UserModel.GROUPS is set to an ID that matches no group, and the user search returns nothing. [grounded: tree services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java] [consensus 3/3: valid=3]
raw comments (8)
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
1\. Group member grants hide all users <code>🐞 Bug</code> <code>≡ Correctness</code>
<pre>
<b><i>getGroupIdsWithViewPermission()</i></b> filters for resources of type <b><i>Groups</i></b>, performs a name-based
lookup using each generated authorization-resource ID, and returns that generated ID as though it
were the underlying group ID, while <b><i>getOrCreateResource()</i></b> creates per-group resources without
assigning the required type. When a principal has <b><i>view-members</i></b> or <b><i>manage-members</i></b> for a specific
group, the resource is omitted or misidentified, leaving user searches and counts with no usable
permitted-group IDs and unable to discover that group's members.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
Group member permissions cannot restrict user queries correctly because dynamically created per-group authorization resources are not assigned the `Groups` resource type, and `getGroupIdsWithViewPermission()` returns generated authorization-resource IDs instead of the group IDs stored in resource names. This prevents group-scoped `view-members` or `manage-members` permissions from producing a usable restriction for user searches and counts.
## Fix Focus Areas
- services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java[106-127]
- server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java[118-127]
- services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java[445-453]
## Recommended Fix
Assign `GROUPS_RESOURCE_TYPE` when `getOrCreateResource()` creates a concrete group resource so it matches the type used by V2 enumeration. Evaluate each discovered resource directly or by its name, and return `resource.getName()` as the actual group ID rather than returning the generated authorization-resource ID. Handle all-groups member scopes separately so they do not apply an invalid generated-ID restriction, and add tests covering both per-group and all-groups member access, including that a principal with `view-members` on one group can search for that group's members.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
2\. Global grants fail on some groups <code>🐞 Bug</code> <code>≡ Correctness</code>
<pre>
<b><i>GroupPermissionsV2.hasPermission()</i></b> falls back to the all-groups resource only when no dedicated
resource exists, rather than evaluating the global grant in addition to a dedicated resource. Once
any policy creates a resource for a group, other administrators holding an all-groups view or manage
grant can lose that group from listings and be denied its operations.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
All-groups permissions are ignored whenever a group has a dedicated authorization resource, making global grants depend on whether unrelated group-specific policies exist.
## Fix Focus Areas
- services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java[130-164]
- services/src/main/java/org/keycloak/services/resources/admin/GroupsResource.java[109-114]
- services/src/main/java/org/keycloak/services/resources/admin/GroupResource.java[176-180]
## Recommended Fix
Evaluate the requested scopes against both the dedicated group resource and the all-groups resource, with either applicable grant authorizing the operation. Add coverage where a group has a policy for one administrator while a different administrator relies exclusively on an all-groups grant.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
3\. Existing realms lack group permissions <code>🐞 Bug</code> <code>☼ Reliability</code>
<pre>
<b><i>AdminPermissionsSchema.init()</i></b> returns immediately whenever an admin-permissions client already
exists, so adding <b><i>Groups</i></b> to the static schema does not persist its resource or scopes into
previously initialized realms. After an upgrade, creating an all-groups permission cannot resolve
the missing resource and group-scope validation cannot find the newly declared scopes.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
Previously initialized admin-permission clients are not upgraded with the new Groups resource type and scopes, leaving group permissions unusable in existing realms.
## Fix Focus Areas
- server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java[78-89]
- server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java[246-278]
## Recommended Fix
Make schema initialization idempotently reconcile all required scopes and all-resource entries even when the admin-permissions client already exists, or add an explicit migration for existing resource servers. Add an upgrade test starting from a client initialized with only the prior Users and Clients schema.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended">
6\. Deleted groups leave policy records <code>🐞 Bug</code> <code>⚙ Maintainability</code>
<pre>
The new group resource path creates persistent authorization resources, but the version-two
implementation has no deletion hook for the corresponding resource and policies. Removing a group
therefore leaves stale policy data behind until individual policies happen to be removed, and later
attempts to remap the deleted group ID fail during model resolution.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
Deleting a group does not remove the version-two authorization resource and policies introduced for that group.
## Fix Focus Areas
- server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java[107-127]
- services/src/main/java/org/keycloak/services/resources/admin/permissions/AdminPermissions.java[73-98]
- services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java[167-175]
## Recommended Fix
Add version-two group-removal handling that deletes the dedicated authorization resource and its dependent policies without calling the unsupported legacy permission-management methods. Cover deletion of groups with one and multiple attached scope permissions.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
4\. All-group auditors cannot find users <code>🐞 Bug</code> <code>≡ Correctness</code>
<pre>
<b><i>getGroupIdsWithViewPermission()</i></b> adds <b><i>groupResource.getId()</i></b> even though concrete group resources
use the realm group ID as their name and authorization resource IDs are generated separately. When
an all-groups member permission is granted, the nonempty set contains the all-groups authorization
ID rather than a group ID, causing the user query to filter memberships against a value no realm
group has.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
The V2 group-permission enumeration returns authorization resource IDs where user queries require realm group IDs. It also treats the all-groups resource as if it were a concrete group, so an all-groups member-view grant installs an invalid restrictive group filter instead of allowing all groups.
## Fix Focus Areas
- services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java[106-127]
- services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java[130-152]
- server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java[105-127]
## Recommended Fix
Use each concrete resource's name, which is the realm group ID, when building the permitted group set. Detect a qualifying all-groups permission separately and return the unrestricted representation expected by the user-query callers; do not add its authorization resource ID to the group-ID set.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
5\. View-only group auditors can edit groups <code>🐞 Bug</code> <code>⛨ Security</code>
<pre>
<b><i>GroupPermissionsV2.canManage()</i></b> passes both <b><i>VIEW</i></b> and <b><i>MANAGE</i></b> to an evaluator that succeeds when
either scope is granted for the all-groups resource. A caller with only all-groups view permission
therefore passes <b><i>requireManage()</i></b> in <b><i>GroupsResource.addTopLevelGroup()</i></b> and reaches top-level
group creation, moves, and other globally guarded mutations.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
The global V2 group-management evaluator accepts `view` as well as `manage`. Endpoints that require global group management consequently authorize a view-only all-groups permission for top-level group creation, moves, and other mutations.
## Fix Focus Areas
- services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java[65-71]
- services/src/main/java/org/keycloak/services/resources/admin/GroupsResource.java[176-203]
## Recommended Fix
Change the non-role branch of `canManage()` to evaluate only `AdminPermissionsSchema.MANAGE`, consistent with `canManage(GroupModel)`. Add tests proving that an all-groups `view` permission still permits listing but receives forbidden when attempting top-level group creation or other group mutations.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<h3>PR Summary by Qodo</h3>
Add fine-grained group permissions to admin authorization v2
<code>✨ Enhancement</code> <code>🧪 Tests</code> <code>🕐 40+ Minutes</code>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<details>
<summary>AI Description</summary>
<dl>
<dd>
<br/>
><pre>
>• Adds fine-grained group resource scopes to admin authorization version two.
>• Applies group permissions to group listings and user visibility or management.
>• Adds integration coverage for group, membership, and member authorization flows.
></pre>
</dd>
</dl>
</details>
<details>
<summary>Diagram</summary>
<dl>
<dd>
<br/>
```mermaid
graph TD
REST["Admin REST"] --> EVAL["Permission Evaluators"] --> USER["User Permissions V2"] --> GROUP["Group Permissions V2"] --> SCHEMA["Group Resource Schema"] --> STORE["Authorization Stores"]
GROUP --> MODEL["User Group Queries"]
```
</dd>
</dl>
</details>
<details>
<summary>High-Level Assessment</summary>
<dl>
<dd>
<br/>
>The following are alternative approaches to this PR:
<details>
<summary><b>1. Split evaluation and management interfaces</b></summary>
<dl>
<dd>
- ➕ Avoids unsupported management operations in the V2 evaluator
- ➕ Separates runtime authorization checks from legacy permission configuration
- ➕ Reduces inheritance coupling between V1 and V2 behavior
- ➖ Requires broader API and implementation changes
- ➖ Increases migration scope and compatibility risk
- ➖ Duplicates or relocates shared hierarchy evaluation logic
</dd>
</dl>
</details>
>**Recommendation:** The incremental subclassing approach is appropriate for this PR because it reuses established group hierarchy logic and matches the existing UserPermissionsV2 design while limiting migration risk. A follow-up should consider separating evaluation from permission-management interfaces so V2 implementations do not need UnsupportedOperationException methods.
</dd>
</dl>
</details>
<details>
<summary> Files changed (19) <code> +831 / -126 </code> </summary>
<dl>
<dd>
<br/>
<details>
<summary>Enhancement (9) <code> +367 / -66 </code></summary>
<dl>
<dd>
<details>
<summary>BruteForceUsersResource.java<code>Filter brute-force user searches by authorized group IDs</code> <code>+4/-8</code></summary>
<br/>
>Filter brute-force user searches by authorized group IDs
>
><pre>
>• Retrieves group IDs visible to the caller and passes them through the session to user searches. It also streams search results directly into representation conversion.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/52/files#diff-3416f569b65a4124a461f7df906bbeea2ace5b424c9ec33cce1f7f635ab37a0c'>rest/admin-ui-ext/src/main/java/org/keycloak/admin/ui/rest/BruteForceUsersResource.java</a>
</details>
<details>
<summary>AdminPermissionsSchema.java<code>Define group resources and scopes in the authorization schema</code> <code>+37/-13</code></summary>
<br/>
>Define group resources and scopes in the authorization schema
>
><pre>
>• Adds the Groups resource type with view, manage, membership, and member scopes. Group resources can now be resolved and created alongside client and user resources.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/52/files#diff-cdea184f4d80846b982b9f6c0b523d021733f68015cd75d6a3e27700e3bf6c7c'>server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java</a>
</details>
<details>
<summary>GroupResource.java<code>Apply per-group visibility to subgroup listings</code> <code>+2/-3</code></summary>
<br/>
>Apply per-group visibility to subgroup listings
>
><pre>
>• Filters every subgroup through the group permission evaluator rather than bypassing checks under global access. It also tightens local variable initialization in child-group creation.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/52/files#diff-d233e82db465ac2b1ad22b124ab0bae3714f02d58c108c29afbbb935653d3cea'>services/src/main/java/org/keycloak/services/resources/admin/GroupResource.java</a>
</details>
<details>
<summary>GroupsResource.java<code>Use provider searches and per-group authorization</code> <code>+3/-5</code></summary>
<br/>
>Use provider searches and per-group authorization
>
><pre>
>• Calls the group provider directly for attribute searches and filters flat group results through the evaluator. This enables resource-specific group permissions to control listings.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/52/files#diff-cdba8763b4828809135e80a085d9b697f88fe999a9d76ad06988037a5403c84e'>services/src/main/java/org/keycloak/services/resources/admin/GroupsResource.java</a>
</details>
<details>
<summary>UsersResource.java<code>Constrain user searches and counts with authorized group IDs</code> <code>+7/-12</code></summary>
<br/>
>Constrain user searches and counts with authorized group IDs
>
><pre>
>• Uses authorized group IDs for restricted user counts and searches. Representation-level filtering is replaced by provider-level group constraints and evaluator-based conversion.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/52/files#diff-e76c3c2d761dc6fc4ea2331ff00dd0d662976facdc3d07b1d84ce980b6179f31'>services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java</a>
</details>
<details>
<summary>GroupPermissionEvaluator.java<code>Document and refine the group permission contract</code> <code>+87/-5</code></summary>
<br/>
>Document and refine the group permission contract
>
><pre>
>• Documents role and scope semantics for listing, viewing, managing, membership, and member operations. Replaces the old group access methods with an API returning authorized group IDs.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/52/files#diff-90d56e3afa1b3095938a328ec47174a020bb652e629bde041f7279f4944fb390'>services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionEvaluator.java</a>
</details>
<details>
<summary>GroupPermissionsV2.java<code>Implement V2 fine-grained group permission evaluation</code> <code>+211/-0</code></summary>
<br/>
>Implement V2 fine-grained group permission evaluation
>
><pre>
>• Adds V2 checks for global and resource-specific group scopes, including view, manage, membership, and member operations. It evaluates authorization resources and returns group IDs whose members the caller may view.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/52/files#diff-b6db47b37a6dcbb73e536a4ca56aaacd64d7d39c9ee9fcb7aa1a0004543875b4'>services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java</a>
</details>
<details>
<summary>MgmtPermissionsV2.java<code>Wire the V2 group permission evaluator</code> <code>+8/-0</code></summary>
<br/>
>Wire the V2 group permission evaluator
>
><pre>
>• Lazily creates and returns GroupPermissionsV2 for V2 admin permission management.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/52/files#diff-ddfc48829f1ed75f23401f0065e8abaf19809f5c1cb8f2397b4c5733eb4ef91c'>services/src/main/java/org/keycloak/services/resources/admin/permissions/MgmtPermissionsV2.java</a>
</details>
<details>
<summary>UserPermissionsV2.java<code>Expand V2 user permissions through group scopes</code> <code>+8/-20</code></summary>
<br/>
>Expand V2 user permissions through group scopes
>
><pre>
>• Allows user viewing, management, role mapping, and group-membership operations through applicable group member permissions. It also removes redundant ADMIN role checks and recognizes MANAGE as an operation-specific grant.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/52/files#diff-4e0df5b00ce216ae9f0c71cda4fd91416cb367d4c4803227bff03eda46cc8823'>services/src/main/java/org/keycloak/services/resources/admin/permissions/UserPermissionsV2.java</a>
</details>
</dd>
</dl>
</details>
<details>
<summary>Bug fix (3) <code> +22 / -38 </code></summary>
<dl>
<dd>
<details>
<summary>AdminPermissions.java<code>Register authorization listeners only when FGAP is enabled</code> <code>+6/-6</code></summary>
<br/>
>Register authorization listeners only when FGAP is enabled
>
><pre>
>• Moves the feature check outside the listener callback so the provider listener is registered only when fine-grained admin authorization is active.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/52/files#diff-a92b9f9a1a007b3924ac2756489c25f9ae8bb1cc92a367a0a839ee2e9b89c998'>services/src/main/java/org/keycloak/services/resources/admin/permissions/AdminPermissions.java</a>
</details>
<details>
<summary>GroupPermissions.java<code>Align legacy group checks with explicit roles and member scopes</code> <code>+11/-27</code></summary>
<br/>
>Align legacy group checks with explicit roles and member scopes
>
><pre>
>• Exposes shared stores to subclasses, uses explicit admin roles for global checks, and renames authorized-group retrieval. Managing members now also grants member visibility, and user visibility delegates to canViewMembers.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/52/files#diff-0fe14fe88c6e37aeb1650fe0d5e05a134da469e9506e70dda2d9a17f7a164816'>services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissions.java</a>
</details>
<details>
<summary>ApiUtil.java<code>Close created responses reliably in test utilities</code> <code>+5/-5</code></summary>
<br/>
>Close created responses reliably in test utilities
>
><pre>
>• Wraps created responses in try-with-resources while extracting the created resource identifier.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/52/files#diff-e304b69fc518093df280f3bd5d8b46d9f0da96459f2d7d8f033bcfeb47d1a38a'>test-framework/core/src/main/java/org/keycloak/testframework/util/ApiUtil.java</a>
</details>
</dd>
</dl>
</details>
<details>
<summary>Refactor (4) <code> +7 / -20 </code></summary>
<dl>
<dd>
<details>
<summary>ModelToRepresentation.java<code>Remove redundant group attribute search wrapper</code> <code>+0/-4</code></summary>
<br/>
>Remove redundant group attribute search wrapper
>
><pre>
>• Removes the utility method that only delegated group attribute searches to the group provider. Callers now use the provider directly.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/52/files#diff-b23cf775bd13ab46bd23cd6f65893b6908eaf261873127125da13a2959da8619'>server-spi-private/src/main/java/org/keycloak/models/utils/ModelToRepresentation.java</a>
</details>
<details>
<summary>RolePermissions.java<code>Use explicit manage-users role for default role mapping</code> <code>+1/-1</code></summary>
<br/>
>Use explicit manage-users role for default role mapping
>
><pre>
>• Replaces the removed user permission helper with a direct MANAGE_USERS role check before allowing role mappings.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/52/files#diff-5c0cd91cf189a9100c0b6b210222be1a17139a2497e967bd8d906a771743d47c'>services/src/main/java/org/keycloak/services/resources/admin/permissions/RolePermissions.java</a>
</details>
<details>
<summary>UserPermissions.java<code>Delegate group-derived user access to member permissions</code> <code>+6/-14</code></summary>
<br/>
>Delegate group-derived user access to member permissions
>
><pre>
>• Removes redundant default role helper methods and uses explicit role checks. User visibility and management inherited through group membership now delegate to group member permission methods.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/52/files#diff-6fd9d3e3aaac301c73847a660b0891a6787c41d3d907934a08c0fc9f8aac8612'>services/src/main/java/org/keycloak/services/resources/admin/permissions/UserPermissions.java</a>
</details>
<details>
<summary>UserResourceTypeEvaluationTest.java<code>Remove an unused test import</code> <code>+0/-1</code></summary>
<br/>
>Remove an unused test import
>
><pre>
>• Removes the unused Arrays import following authorization test cleanup.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/52/files#diff-fde5a7dfe09d86f0252e99baca6831778629e61ffe301e36259b40562000c3e3'>tests/base/src/test/java/org/keycloak/tests/admin/authz/fgap/UserResourceTypeEvaluationTest.java</a>
</details>
</dd>
</dl>
</details>
<details>
<summary>Tests (2) <code> +323 / -1 </code></summary>
<dl>
<dd>
<details>
<summary>GroupResourceTypeEvaluationTest.java<code>Test V2 group resource and member permissions</code> <code>+320/-0</code></summary>
<br/>
>Test V2 group resource and member permissions
>
><pre>
>• Adds integration tests for viewing and managing individual or all groups, group-derived user access, and membership management. The tests verify both denied and granted admin API behavior.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/52/files#diff-8f9305871c38e351f7db1c5f0f1a9621b6a79db44dbd8db8701cbe5fa9ff2d69'>tests/base/src/test/java/org/keycloak/tests/admin/authz/fgap/GroupResourceTypeEvaluationTest.java</a>
</details>
<details>
<summary>RealmAdminPermissionsConfig.java<code>Grant query-groups to the FGAP test administrator</code> <code>+3/-1</code></summary>
<br/>
>Grant query-groups to the FGAP test administrator
>
><pre>
>• Adds QUERY_GROUPS to the test administrator so group listings can proceed to fine-grained resource filtering.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/52/files#diff-639192b3ca89678fe98ba02be7e4496c77bbeb5d2b0037d8e1502f5b80ce6378'>tests/base/src/test/java/org/keycloak/tests/admin/authz/fgap/RealmAdminPermissionsConfig.java</a>
</details>
</dd>
</dl>
</details>
<details>
<summary>Documentation (1) <code> +112 / -1 </code></summary>
<dl>
<dd>
<details>
<summary>UserPermissionEvaluator.java<code>Document user authorization semantics and compatibility API</code> <code>+112/-1</code></summary>
<br/>
>Document user authorization semantics and compatibility API
>
><pre>
>• Adds detailed role, scope, and group-derived authorization contracts for user operations. Marks the legacy impersonation check as deprecated while retaining compatibility.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/52/files#diff-d2677d7be5a52edf93e51550455ed0d436835c973c415728c168707bbac868cf'>services/src/main/java/org/keycloak/services/resources/admin/permissions/UserPermissionEvaluator.java</a>
</details>
</dd>
</dl>
</details>
</dd>
</dl>
</details>
<h3>Code Review by Qodo</h3>
<code>🐞 Bugs (6)</code> <code>📘 Rule violations (0)</code> <code>📜 Skill insights (0)</code>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<br/>
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
<details>
<summary> 1. Group member grants hide all users <code>🐞 Bug</code> <code>≡ Correctness</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>getGroupIdsWithViewPermission()</i></b> filters for resources of type <b><i>Groups</i></b>, performs a name-based
>lookup using each generated authorization-resource ID, and returns that generated ID as though it
>were the underlying group ID, while <b><i>getOrCreateResource()</i></b> creates per-group resources without
>assigning the required type. When a principal has <b><i>view-members</i></b> or <b><i>manage-members</i></b> for a specific
>group, the resource is omitted or misidentified, leaving user searches and counts with no usable
>permitted-group IDs and unable to discover that group's members.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java[R121-123]](https://github.com/drape-io/crbench-qodo-2026-09/pull/52/files#diff-b6db47b37a6dcbb73e536a4ca56aaacd64d7d39c9ee9fcb7aa1a0004543875b4R121-R123)</code>
>
>```diff
>+ resourceStore.findByType(server, AdminPermissionsSchema.GROUPS_RESOURCE_TYPE, groupResource -> {
>+ if (hasPermission(groupResource.getId(), AdminPermissionsSchema.VIEW_MEMBERS, AdminPermissionsSchema.MANAGE_MEMBERS)) {
>+ granted.add(groupResource.getId());
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The schema stores the actual group ID in the resource name, generates a separate authorization
>resource ID, and creates dynamic per-group resources without setting their type. The discovery
>method filters resources by the <b><i>Groups</i></b> type, then uses the generated resource ID for a name-based
>lookup and returns generated IDs to user search and count APIs that expect real group IDs, proving
>both that per-group resources are missed by enumeration and that any discovered values are
>unsuitable for the downstream group restriction.
></pre>
>
> <code>[services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java[106-127]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java/#L106-L127)</code>
> <code>[services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java[130-145]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java/#L130-L145)</code>
> <code>[server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java[107-127]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java/#L107-L127)</code>
> <code>[server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java[181-186]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java/#L181-L186)</code>
> <code>[services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java[445-453]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java/#L445-L453)</code>
> <code>[server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java[105-127]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java/#L105-L127)</code>
> <code>[services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java[395-430]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java/#L395-L430)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>Group member permissions cannot restrict user queries correctly because dynamically created per-group authorization resources are not assigned the `Groups` resource type, and `getGroupIdsWithViewPermission()` returns generated authorization-resource IDs instead of the group IDs stored in resource names. This prevents group-scoped `view-members` or `manage-members` permissions from producing a usable restriction for user searches and counts.
>
>## Fix Focus Areas
>- services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java[106-127]
>- server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java[118-127]
>- services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java[445-453]
>
>## Recommended Fix
>Assign `GROUPS_RESOURCE_TYPE` when `getOrCreateResource()` creates a concrete group resource so it matches the type used by V2 enumeration. Evaluate each discovered resource directly or by its name, and return `resource.getName()` as the actual group ID rather than returning the generated authorization-resource ID. Handle all-groups member scopes separately so they do not apply an invalid generated-ID restriction, and add tests covering both per-group and all-groups member access, including that a principal with `view-members` on one group can search for that group's members.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<details>
<summary> 2. Global grants fail on some groups <code>🐞 Bug</code> <code>≡ Correctness</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>GroupPermissionsV2.hasPermission()</i></b> falls back to the all-groups resource only when no dedicated
>resource exists, rather than evaluating the global grant in addition to a dedicated resource. Once
>any policy creates a resource for a group, other administrators holding an all-groups view or manage
>grant can lose that group from listings and be denied its operations.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java[R141-144]](https://github.com/drape-io/crbench-qodo-2026-09/pull/52/files#diff-b6db47b37a6dcbb73e536a4ca56aaacd64d7d39c9ee9fcb7aa1a0004543875b4R141-R144)</code>
>
>```diff
>+ Resource resource = groupId == null ? null : resourceStore.findByName(server, groupId);
>+
>+ if (resource == null) {
>+ resource = AdminPermissionsSchema.SCHEMA.getResourceTypeResource(session, server, AdminPermissionsSchema.GROUPS_RESOURCE_TYPE);
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The implementation selects the dedicated resource when present and reaches the global resource only
>from its null branch. The changed listing filters invoke this group-specific path directly, and
>mutation checks use the same helper, so a dedicated policy can mask an otherwise valid global grant.
></pre>
>
> <code>[services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java[130-164]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java/#L130-L164)</code>
> <code>[services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java[55-80]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java/#L55-L80)</code>
> <code>[services/src/main/java/org/keycloak/services/resources/admin/GroupsResource.java[109-114]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/services/src/main/java/org/keycloak/services/resources/admin/GroupsResource.java/#L109-L114)</code>
> <code>[services/src/main/java/org/keycloak/services/resources/admin/GroupResource.java[170-180]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/services/src/main/java/org/keycloak/services/resources/admin/GroupResource.java/#L170-L180)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>All-groups permissions are ignored whenever a group has a dedicated authorization resource, making global grants depend on whether unrelated group-specific policies exist.
>
>## Fix Focus Areas
>- services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java[130-164]
>- services/src/main/java/org/keycloak/services/resources/admin/GroupsResource.java[109-114]
>- services/src/main/java/org/keycloak/services/resources/admin/GroupResource.java[176-180]
>
>## Recommended Fix
>Evaluate the requested scopes against both the dedicated group resource and the all-groups resource, with either applicable grant authorizing the operation. Add coverage where a group has a policy for one administrator while a different administrator relies exclusively on an all-groups grant.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<details>
<summary> 3. Existing realms lack group permissions <code>🐞 Bug</code> <code>☼ Reliability</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>AdminPermissionsSchema.init()</i></b> returns immediately whenever an admin-permissions client already
>exists, so adding <b><i>Groups</i></b> to the static schema does not persist its resource or scopes into
>previously initialized realms. After an upgrade, creating an all-groups permission cannot resolve
>the missing resource and group-scope validation cannot find the newly declared scopes.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java[R85-88]](https://github.com/drape-io/crbench-qodo-2026-09/pull/52/files#diff-cdea184f4d80846b982b9f6c0b523d021733f68015cd75d6a3e27700e3bf6c7cR85-R88)</code>
>
>```diff
>+ super(Map.of(
>+ CLIENTS_RESOURCE_TYPE, CLIENTS,
>+ GROUPS_RESOURCE_TYPE, GROUPS,
>+ USERS_RESOURCE_TYPE, USERS
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The newly declared group scopes and all-groups resource are persisted only after the existing-client
>early return. Permission creation depends on those persisted scopes and on locating the
>resource-type resource, so changing the static map alone cannot upgrade stored realm data.
></pre>
>
> <code>[server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java[78-89]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java/#L78-L89)</code>
> <code>[server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java[246-278]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java/#L246-L278)</code>
> <code>[server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java[133-150]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java/#L133-L150)</code>
> <code>[server-spi-private/src/main/java/org/keycloak/authorization/AuthorizationProvider.java[323-335]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/server-spi-private/src/main/java/org/keycloak/authorization/AuthorizationProvider.java/#L323-L335)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>Previously initialized admin-permission clients are not upgraded with the new Groups resource type and scopes, leaving group permissions unusable in existing realms.
>
>## Fix Focus Areas
>- server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java[78-89]
>- server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java[246-278]
>
>## Recommended Fix
>Make schema initialization idempotently reconcile all required scopes and all-resource entries even when the admin-permissions client already exists, or add an explicit migration for existing resource servers. Add an upgrade test starting from a client initialized with only the prior Users and Clients schema.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<details><summary><ins><strong>View high (2)</strong></ins></summary><br/>
<details>
<summary> 4. All-group auditors cannot find users <code>🐞 Bug</code> <code>≡ Correctness</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>getGroupIdsWithViewPermission()</i></b> adds <b><i>groupResource.getId()</i></b> even though concrete group resources
>use the realm group ID as their name and authorization resource IDs are generated separately. When
>an all-groups member permission is granted, the nonempty set contains the all-groups authorization
>ID rather than a group ID, causing the user query to filter memberships against a value no realm
>group has.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java[R121-124]](https://github.com/drape-io/crbench-qodo-2026-09/pull/52/files#diff-b6db47b37a6dcbb73e536a4ca56aaacd64d7d39c9ee9fcb7aa1a0004543875b4R121-R124)</code>
>
>```diff
>+ resourceStore.findByType(server, AdminPermissionsSchema.GROUPS_RESOURCE_TYPE, groupResource -> {
>+ if (hasPermission(groupResource.getId(), AdminPermissionsSchema.VIEW_MEMBERS, AdminPermissionsSchema.MANAGE_MEMBERS)) {
>+ granted.add(groupResource.getId());
>+ }
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The schema resolves a group to its group ID and stores that value as the resource name, whereas the
>resource-store overload generates an ID. The user provider consumes the session set as membership
>group IDs, so an authorization resource ID cannot match a membership.
></pre>
>
> <code>[services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java[119-124]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java/#L119-L124)</code>
> <code>[services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java[141-152]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java/#L141-L152)</code>
> <code>[server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java[105-127]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java/#L105-L127)</code>
> <code>[server-spi-private/src/main/java/org/keycloak/authorization/store/ResourceStore.java[45-58]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/server-spi-private/src/main/java/org/keycloak/authorization/store/ResourceStore.java/#L45-L58)</code>
> <code>[model/jpa/src/main/java/org/keycloak/models/jpa/JpaUserProvider.java[762-766]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/model/jpa/src/main/java/org/keycloak/models/jpa/JpaUserProvider.java/#L762-L766)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>The V2 group-permission enumeration returns authorization resource IDs where user queries require realm group IDs. It also treats the all-groups resource as if it were a concrete group, so an all-groups member-view grant installs an invalid restrictive group filter instead of allowing all groups.
>
>## Fix Focus Areas
>- services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java[106-127]
>- services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java[130-152]
>- server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java[105-127]
>
>## Recommended Fix
>Use each concrete resource's name, which is the realm group ID, when building the permitted group set. Detect a qualifying all-groups permission separately and return the unrestricted representation expected by the user-query callers; do not add its authorization resource ID to the group-ID set.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<details>
<summary> 5. View-only group auditors can edit groups <code>🐞 Bug</code> <code>⛨ Security</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>GroupPermissionsV2.canManage()</i></b> passes both <b><i>VIEW</i></b> and <b><i>MANAGE</i></b> to an evaluator that succeeds when
>either scope is granted for the all-groups resource. A caller with only all-groups view permission
>therefore passes <b><i>requireManage()</i></b> in <b><i>GroupsResource.addTopLevelGroup()</i></b> and reaches top-level
>group creation, moves, and other globally guarded mutations.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java[R65-71]](https://github.com/drape-io/crbench-qodo-2026-09/pull/52/files#diff-b6db47b37a6dcbb73e536a4ca56aaacd64d7d39c9ee9fcb7aa1a0004543875b4R65-R71)</code>
>
>```diff
>+ public boolean canManage() {
>+ if (root.hasOneAdminRole(AdminRoles.MANAGE_USERS)) {
>+ return true;
>+ }
>+
>+ return hasPermission(null, AdminPermissionsSchema.VIEW, AdminPermissionsSchema.MANAGE);
>+ }
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The global management check requests both <b><i>VIEW</i></b> and <b><i>MANAGE</i></b>, while <b><i>hasPermission</i></b> returns true
>when it finds any matching expected scope, even though the schema defines view and manage as
>distinct scopes. <b><i>GroupsResource.addTopLevelGroup()</i></b> gates its mutation on this check, and the
>per-group management implementation requires only <b><i>MANAGE</i></b>, confirming that the global check is
>over-broad.
></pre>
>
> <code>[services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java[65-80]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java/#L65-L80)</code>
> <code>[services/src/main/java/org/keycloak/services/resources/admin/GroupsResource.java[176-203]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/services/src/main/java/org/keycloak/services/resources/admin/GroupsResource.java/#L176-L203)</code>
> <code>[server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java[59-80]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java/#L59-L80)</code>
> <code>[services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java[65-70]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java/#L65-L70)</code>
> <code>[services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java[152-164]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java/#L152-L164)</code>
> <code>[services/src/main/java/org/keycloak/services/resources/admin/GroupsResource.java[171-182]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/services/src/main/java/org/keycloak/services/resources/admin/GroupsResource.java/#L171-L182)</code>
> <code>[server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java[59-61]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java/#L59-L61)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>The global V2 group-management evaluator accepts `view` as well as `manage`. Endpoints that require global group management consequently authorize a view-only all-groups permission for top-level group creation, moves, and other mutations.
>
>## Fix Focus Areas
>- services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java[65-71]
>- services/src/main/java/org/keycloak/services/resources/admin/GroupsResource.java[176-203]
>
>## Recommended Fix
>Change the non-role branch of `canManage()` to evaluate only `AdminPermissionsSchema.MANAGE`, consistent with `canManage(GroupModel)`. Add tests proving that an all-groups `view` permission still permits listing but receives forbidden when attempting top-level group creation or other group mutations.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
</details>
<br/>
<img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended">
<details>
<summary> 6. Deleted groups leave policy records <code>🐞 Bug</code> <code>⚙ Maintainability</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
>The new group resource path creates persistent authorization resources, but the version-two
>implementation has no deletion hook for the corresponding resource and policies. Removing a group
>therefore leaves stale policy data behind until individual policies happen to be removed, and later
>attempts to remap the deleted group ID fail during model resolution.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java[R108-110]](https://github.com/drape-io/crbench-qodo-2026-09/pull/52/files#diff-cdea184f4d80846b982b9f6c0b523d021733f68015cd75d6a3e27700e3bf6c7cR108-R110)</code>
>
>```diff
>+ case CLIENTS_RESOURCE_TYPE -> name = resolveClient(session, id);
>+ case GROUPS_RESOURCE_TYPE -> name = resolveGroup(session, id);
>+ case USERS_RESOURCE_TYPE -> name = resolveUser(session, id);
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>Individual group permissions now create schema resources keyed by group ID, while the removal
>listener is registered only for the legacy feature and the version-two cleanup method is
>unsupported. Schema orphan cleanup runs during policy removal rather than group removal, so deleting
>the underlying model does not remove these records.
></pre>
>
> <code>[server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java[107-127]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java/#L107-L127)</code>
> <code>[server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java[293-325]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java/#L293-L325)</code>
> <code>[services/src/main/java/org/keycloak/services/resources/admin/permissions/AdminPermissions.java[73-98]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/services/src/main/java/org/keycloak/services/resources/admin/permissions/AdminPermissions.java/#L73-L98)</code>
> <code>[services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java[167-175]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4322dd7b072fc8484d6a500bda9310bf439cd7c8/services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java/#L167-L175)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>Deleting a group does not remove the version-two authorization resource and policies introduced for that group.
>
>## Fix Focus Areas
>- server-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java[107-127]
>- services/src/main/java/org/keycloak/services/resources/admin/permissions/AdminPermissions.java[73-98]
>- services/src/main/java/org/keycloak/services/resources/admin/permissions/GroupPermissionsV2.java[167-175]
>
>## Recommended Fix
>Add version-two group-removal handling that deletes the dedicated authorization resource and its dependent policies without calling the unsupported legacy permission-management methods. Cover deletion of groups with one and multiple attached scope permissions.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-context:start -->
<details><summary><strong>Context sources</strong></summary>
<div>Review mode: <code>🧠 Deep</code>: This is a security-sensitive, cross-cutting authorization change with substantial new permission logic across multiple independent code paths and a high density of easy-to-miss access-control defects.</div>
<!-- qodo-context:end -->
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-daily-tip:start -->
<details>
<summary><strong>Tip of the day</strong></summary>
<br/>
<pre>💡 Did you know, you can reply 'qodo' on any finding to push back, ask questions, or dig deeper</pre>
<a href="https://docs.qodo.ai/tips-and-tricks">More tips ↗</a> | <a href="https://app.qodo.ai/configurations?tab=display-preferences">Customize Qodo ↗</a> | <a href="https://docs.qodo.ai">Qodo docs ↗</a>
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-daily-tip:end -->
<!-- https://github.com/drape-io/crbench-qodo-2026-09/commit/4322dd7b072fc8484d6a500bda9310bf439cd7c8 -->
<a href="https://www.qodo.ai"><img src="https://www.qodo.ai/wp-content/uploads/2025/03/qodo-logo.svg" width="80" alt="Qodo Logo"></a>