DeepSeek V4.1 Flash · Balanced

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

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

The normal review, with one generalist agent. Judge: Claude Haiku 5.5.

Gold bugs found
2 of 8
Comments published
4
Comments matching a bug
2
Comments not matching
2
Cost of this PR
$0.204

Published comments (4)

highbugservices/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:136-144

getClientsWithPermission returns bogus entry instead of client ids — The set ends up with the all-clients resource's literal name instead of client ids, so AvailableRoleMappingResource throws a NullPointerException on `realm.getClientById(cid)`. Iterate real clients and add `client.getId()` when `hasPermission` passes.

highbugserver-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java:73

Existing realms miss upgrade for new CLIENTS admin resource type — Realms with ADMIN_FINE_GRAINED_AUTHZ_V2 already enabled never get the new scopes or the CLIENTS resource type, and `getOrCreateResource` fails with ModelException("No scopes found."). Add reconciliation for existing admin-permissions resource servers when the schema grows.

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

ClientPermissionsV2 throws on live token-exchange and permission paths — Every token-exchange request in a V2 realm now throws a 500 through `canExchangeTo`, and the client `management/permissions` endpoints fail the same way. Return false for exchange checks and a no-op for `setPermissionsEnabled` instead of throwing on live paths. **Also found in:** - `services/src/main/java/org/keycloak/services/resources/admin/permissions/AdminPermissions.java:77-95`

mediumbugserver-spi-private/src/main/java/org/keycloak/authorization/AdminPermissionsSchema.java:93-95

Client permission listings return null display names — The CLIENTS type isn't handled in the name resolution, so `getDisplayName()` stays null and PolicyResourceService returns null displayNames for every client permission listing. Resolve the client UUID to a readable label for this type.

Gold bugs found (2)

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

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.
mediumClaims getResourceTypeResource can return null in ClientPermissionsV2.hasPermission, causing a NullPointerException in findByResource.
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.