DeepSeek V4.1 Flash · 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
4 of 8
Comments published
6
Comments matching a bug
4
Comments not matching
2
Cost of this PR
$0.323

Published comments (6)

highbugservices/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:214-221

All-clients grants ignored when per-client resource exists — Any client with its own resource loses the grants an admin holds on the "Clients" type resource, so all-clients `manage`, `configure` and `view` silently stop applying. Evaluate the type resource as well and fall back to it instead of consulting it only when `resourceStore.findByName` returns null.

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

getClientsWithPermission matches only type resource, not per-client grants — The per-client resources from `AdminPermissionsSchema.getOrCreateResource` carry no type, so `findByType` returns only the literal "Clients" resource and omits every real grant, leaving `getRoleIdsWithPermissions` with a null client id. Iterate the realm's clients and check `hasPermission` on each instead.

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

canExchangeTo throws UnsupportedOperationException on token exchange path — `AbstractTokenExchangeProvider` calls `canExchangeTo` on every cross-client exchange, so enabling V2 turns each one into an uncaught exception and HTTP 500 instead of a 403. Return `false` or delegate to the existing evaluation, including the inherited 2-arg overload.

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

Client removal fails when both fine-grained authz features are enabled — With V1 and V2 both enabled, the `ClientRemovedEvent` branch still reaches `ClientPermissionsV2.setPermissionsEnabled` and throws, so deleting a client returns 500. Skip that branch when `ADMIN_FINE_GRAINED_AUTHZ_V2` is on, since V2 needs no permission cleanup. **Also found in:** - `services/src/main/java/org/keycloak/services/resources/admin/permissions/MgmtPermissionsV2.java:63-68`

mediumperformanceservices/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:77-83

canView(ClientModel) issues redundant per-client permission checks — `ClientsResource.getClients` calls `canView` per client, so a realm listing runs up to four resource lookups and policy evaluations each, with the type-level result never cached. Check `hasPermission(scope)` once and evaluate the client scopes in a single pass.

mediumbugservices/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:224

Missing null check on fallback resource before evaluation — When the `getResourceTypeResource` fallback also returns null, `root.evaluatePermission` dereferences a null `resource` and throws. Return `false` before the evaluation when `resource` is null. **Also found in:** - `services/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:215-222` - `services/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:214-222`

Gold bugs found (4)

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.
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.
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 (4)

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.