Kimi K3.1 Pro · 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
- 6 of 8
- Comments published
- 11
- Comments matching a bug
- 6
- Comments not matching
- 5
- Cost of this PR
- $3.364
Published comments (11)
Missing Clients resource breaks permissions for existing admin-permissions clients — An existing admin-permissions client created before this PR has no `Clients` resource because `AdminPermissionsSchema.init` returns when that client already exists, so `getResourceTypeResource` returns null and `findByResource` dereferences `resource.getId()`. Backfill the new resource and scopes for existing realms and handle a missing aggregate resource before querying policies.
V2 canExchangeTo throws on every cross-client token exchange — `AdminPermissions.management(...).clients()` resolves to this V2 implementation whenever V2 is enabled, and `AbstractTokenExchangeProvider` calls `canExchangeTo` for every exchange to a different target client. The unconditional exception turns such token-exchange attempts into server errors; implement V2 evaluation or deny/delegate without throwing.
When V2 is enabled without V1, this guard skips `ClientRemovedEvent` cleanup, leaving the new… — Add V2 resource and policy cleanup independently of the V1-only listener.
Per-client resources created by `AdminPermissionsSchema.getOrCreateResource` never have `type`… — Store `Clients` as their type, including for existing resources, or query using the actual resource storage scheme.
All-clients grants add "Clients" as a client ID and trigger an NPE — The built-in all-clients resource also has type `Clients`, so a matching all-clients permission adds the literal name `Clients` as a client ID; `AvailableRoleMappingResource` then dereferences `realm.getClientById("Clients")` and throws a null-pointer exception. Exclude the aggregate resource and expand an all-clients grant to actual client IDs.
canView() ignores the all-clients manage permission — An administrator granted only the all-clients `manage` scope still gets `canView() == false`, so `ClientsResource.getClients` rejects the request at `requireList()` unless the administrator also has an unrelated query role. Include `hasPermission(AdminPermissionsSchema.MANAGE)` in this check, matching the manage-implies-view behavior of `canView(ClientModel)` and `canView(ClientScopeModel)`.
All-clients grants are skipped when a client-specific resource exists — The all-clients permission is considered only when the client has no resource of its own. If a client has any client-specific permission (for example CONFIGURE), resource is non-null and an all-clients MANAGE or VIEW grant is never evaluated, so valid global grants stop applying to that client.
CONFIGURE test does not check permissions on a different client — This test grants CONFIGURE only on `myclient`, but every post-grant operation still targets `myclient`; the later denied operations only distinguish CONFIGURE from MANAGE. If `canConfigure` ignored the supplied client and applied that permission to every client, the entire test would still pass.
OnlyOneClient test does not check that other clients stay forbidden — The “OnlyOneClient” role-mapping test never verifies that another client remains inaccessible after these grants. An implementation that ignores the client argument when evaluating MAP_ROLES/MAP_ROLES_COMPOSITE would still fail the pre-grant checks and pass both post-grant calls.
View-all-clients test accepts an incomplete client list — `not(empty())` does not verify the claimed ability to list and view all clients: the test would still pass if the all-clients VIEW permission exposed only `myclient`, since the subsequent protocol-mapper check also uses only that client. Compare the returned client IDs with the complete set obtained through the privileged realm admin (or at least assert access to multiple otherwise-unpermissioned clients).
V2 setPermissionsEnabled breaks client removal cleanup — This override conflicts with the changed `AdminPermissions` client-removal listener. That listener calls `management(...).clients().setPermissionsEnabled(client, false)` on every `ClientRemovedEvent`; with V2 enabled, `clients()` returns this class, so the call always throws `UnsupportedOperationException` and can cause client deletion to fail. **Also found in:** - `services/src/main/java/org/keycloak/services/resources/admin/permissions/AdminPermissions.java:89-92` - `services/src/main/java/org/keycloak/services/resources/admin/permissions/AdminPermissions.java:89-91`