GLM-5.3 · 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
- 8
- Comments matching a bug
- 4
- Comments not matching
- 4
- Cost of this PR
- $4.083
Published comments (8)
Existing admin-permissions servers never get the `Clients` type or new scopes — Creating any client permission fails — `getScope` throws, `getOrCreateResource` throws `ModelException` — and every client permission evaluation NPEs via the null type resource. Because `init()` returns early when `getAdminPermissionsClient()` exists, add a migration creating the missing type resource and scopes.
getClientsWithPermission adds type-level 'Clients' name, not per-client IDs — Per-client resources from `getOrCreateResource` carry no type, so `findByType` matches only the type-level resource and `granted` collects the literal `Clients` — `AvailableRoleMappingResource.getRoleIdsWithPermissions` then NPEs calling `realm.getClientById`. Set the resource type at creation, as V1's `ClientPermissions` does, or resolve per-client resources by name.
NPE when Clients type resource is missing in hasPermission(ClientModel, String) — When the type resource is absent, `getResourceTypeResource` returns null and `policyStore.findByResource` throws, turning every `canManage`/`canView`/`canConfigure`/`canMapRoles` client check into a 500 instead of a denial. Add a null check returning false, as the `hasPermission(String)` overload does.
Client removal listener calls setPermissionsEnabled that throws under AUTHZ_V2 — With `ADMIN_FINE_GRAINED_AUTHZ_V2` enabled, the `ClientRemovedEvent` handler reaches `ClientPermissionsV2.setPermissionsEnabled`, which throws `UnsupportedOperationException` — every client deletion fails. Make the listener V2-aware: skip the call or perform V2-appropriate cleanup when that flag is on. **Also found in:** - `services/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:192-195` - `services/src/main/java/org/keycloak/services/resources/admin/permissions/ClientPermissionsV2.java:193-195`
V2 canExchangeTo throws UnsupportedOperationException, crashing token exchange — `AbstractTokenExchangeProvider` calls `canExchangeTo` for every non-self audience client, so with V2 enabled cross-client token exchange returns a 500 rather than evaluating or denying. Implement the evaluation — the now-dead `getEvaluationContext` shows the intent — or return false.
Type-level all-clients fallback re-evaluated for every client and scope check — In the `ClientsResource.getClients` listing, each `canView` repeats the identical type-level fallback up to three times — thousands of full policy evaluations per request in large realms. Compute the fallback once per request or collapse scopes into a single `hasPermission` call.
All-clients permission fallback skipped once a per-client resource exists — Granting `view` on one client then `manage` for all clients leaves `canManage` returning false and a 403 despite the realm-wide grant, contradicting the `ClientPermissionEvaluator` javadoc. In `hasPermission(ClientModel, String)`, evaluate the all-clients resource whenever the per-client evaluation fails to grant the requested scope.
testMapRolesAndCompositesOnlyOneClient doesn't verify per-client scoping — Every operation in `testMapRolesAndCompositesOnlyOneClient` targets `myclient`, so a regression where one client's permission authorizes all clients would still pass. Add a negative check against a second client, as `testManageOnlyOneClient` does, and grant scopes separately. **Also found in:** - `tests/base/src/test/java/org/keycloak/tests/admin/authz/fgap/PermissionClientTest.java:191-247`