Claude Sonnet 5.5 · Heavy

add-client-resource-type-and-scopes-to-authorization-schema-keycloak

Keycloak · Java · L · 300–799 lines · 5 files

The generalist plus 9 specialist lens agents in parallel, then the same verify and dedup steps. Judge: Claude Haiku 5.5.

Gold bugs found
3 of 8
Comments published
4
Comments matching a bug
3
Comments not matching
1
Cost of this PR
$3.295

Published comments (4)

highbugservices/src/main/java/org/keycloak/services/resources/admin/permissions/AdminPermissions.java:89-91

Client removal handler throws when V2 fine-grained authz is enabled — With both feature flags on, `management()` returns `MgmtPermissionsV2`, and `ClientPermissionsV2.setPermissionsEnabled` always throws `UnsupportedOperationException`, so client deletion fails. Skip this V1 cleanup in the `ClientRemovedEvent` handler when V2 is enabled, or make `setPermissionsEnabled` a no-op.

mediumbugservices/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:214-222

NPE when Clients type resource is missing in hasPermission — `getResourceTypeResource` can return null, and passing it to `findByResource` causes an NPE and a 500 instead of a denial. Return false when the resource is null before calling `findByResource`.

mediumbugservices/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:138-142

getClientsWithPermission matches no per-client resources — Per-client resources from `AdminPermissionsSchema.getOrCreateResource` have no type, so `findByType` misses them and only finds the type-level "Clients" resource, which is not a client id. Callers like `AvailableRoleMappingResource` get wrong results; iterate clients and look up each resource by owner and name.

mediumbugservices/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:147-150

canExchangeTo throws UnsupportedOperationException in V2 instead of denying — `AbstractTokenExchangeProvider` still calls `canExchangeTo`, so under V2 token exchange fails with `UnsupportedOperationException` instead of a permission denial. Return false in `canExchangeTo`, or guard the caller.

Gold bugs found (3)

highgetClientsWithPermission in ClientPermissionsV2 only finds the type-level 'Clients' resource and returns its name, never actual client ids, so callers that resolve the returned values as client ids get wrong results or null clients.
mediumClaims getResourceTypeResource can return null in ClientPermissionsV2.hasPermission, causing a NullPointerException in findByResource.
highClientPermissionsV2.canExchangeTo throws UnsupportedOperationException, but AbstractTokenExchangeProvider still calls clients().canExchangeTo for client-to-client exchange, so with token exchange and FGAP V2 enabled the request fails with a server error instead of a permission decision.

Gold bugs missed (5)

mediumClaims the removal-cleanup listener is guarded by the V1 fine-grained flag, so client/role/group permissions are orphaned when V1 is disabled or only V2 is enabled.
mediumClientPermissionsV2.canView() ignores a global MANAGE permission, so admins with only global manage take the unpaginated, per-client evaluated listing path.
highcanView(client) short-circuits on the global all-clients VIEW permission, so a client-specific permission denying an admin is never evaluated and the client is still viewable.
mediumThe negative check for removing a default client scope expects ForbiddenException, but it can come from the preceding getDefaultClientScopes() call, so the test passes even without a permission check on removal.
highIn ClientPermissionsV2.hasPermission, an admin granted a permission on all clients is denied on any client that also has its own per-client permission resource, because only the per-client resource is evaluated.