MiniMax M3 · 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
2 of 8
Comments published
4
Comments matching a bug
2
Comments not matching
2
Cost of this PR
$0.464

Published comments (4)

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

getClientsWithPermission leaks the 'Clients' type-resource name into callers — Filter out entries where `resource.getName()` equals `AdminPermissionsSchema.CLIENTS_RESOURCE_TYPE`.

highbugservices/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:192-196

ClientPermissionsV2.setPermissionsEnabled throws on client removal under fine-grained authz — `ClientPermissionsV2.setPermissionsEnabled` throws `UnsupportedOperationException`, yet the `AdminPermissions` listener calls it on `ClientRemovedEvent` whenever `ADMIN_FINE_GRAINED_AUTHZ` is enabled, so client removal in V2 mode always fails. Implement V2 cleanup there, or gate the listener to fire only under V1 via an `instanceof ClientPermissions` check.

highbugservices/src/main/java/org/keycloak/services/resources/admin/permissions/AdminPermissions.java:74-98

ADMIN_FINE_GRAINED_AUTHZ listener triggers V2 setPermissionsEnabled UnsupportedOperationException — `AdminPermissions`'s `ProviderEventListener` calls `setPermissionsEnabled(false)` on `ClientRemovedEvent` under `ADMIN_FINE_GRAINED_AUTHZ`, but the V2 impl `ClientPermissionsV2.setPermissionsEnabled` throws `UnsupportedOperationException`. Restrict the branch to the legacy/V1 path with an extra V2 feature check so it skips V2.

mediumbugservices/src/main/java/org/keycloak/services/resources/admin/permissions/AdminPermissions.java:74-97

ADMIN_FINE_GRAINED_AUTHZ gate skipped V1 cleanup on role/client/group removal — Gating the three `AdminPermissions` cleanup listeners behind `ADMIN_FINE_GRAINED_AUTHZ` silently breaks the V1 cleanup contract, leaving orphan permissions whenever the feature is off (the default). Keep the V1 handlers registered unconditionally and gate only the V2-only additions.

Gold bugs found (2)

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.
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.

Gold bugs missed (6)

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.
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.