#53335·keycloak

SCIM user PUT/PATCH bypass the user cache: active=false via SCIM does not disable the user for logins

Author: thomasdarimontCreated Sep 30, 2026Updated Sep 30, 2026
Labelskind/bugstatus/triageteam/core-iamarea/scim

Before reporting an issue

  • I have read and understood the above terms for submitting issues, and I understand that my issue may be closed without action if I do not follow them.

Area

scim

Describe the bug

UserResourceTypeProvider.getModel() (scim/model, line 179 on current main) loads the user via UserStoragePrivateUtil.userLocalStorage(session).getUserById(realm, id), i.e. the raw JPA user provider, instead of the cache-aware session.users().getUserById(realm, id) that 26.7.x uses. The change came with 801ef24464f (“Fix SCIM unfiltered search returning non-imported federated users”, closes #51343).

getModel() is the entry point for every write on an existing user: BaseResourceTypeProvider.update()/get()/delete(), AbstractScimResourceTypeProvider.patch(), and UserResourceTypeProvider.update()/patch().

As a result, SCIM PUT and PATCH modify the JPA entity directly, and the Infinispan user cache is never invalidated. DELETE is not affected because onDelete() goes through UserManager.removeUser(), which evicts the user.

Note that this is not reproducible on 26.7.4 so I marked it as a regression.

Version

nightly (sha256:ee4e87b69b95339287c3b25dd5ca06d5f47fd707f7f26d51b8414522983136f0)

Regression

  • The issue is a regression

Expected behavior

SCIM PUT/PATCH go through the cache-aware UserProvider (session.users()), or explicitly evict the user from the cache, so the change is immediately visible to logins and the Admin API. In particular, active=false via SCIM must block the next login.

Actual behavior

  • After a SCIM PATCH/PUT the database row is updated, but the cached UserModel keeps the previous values. Every cache-backed consumer (Admin REST GET /users/{id}, Admin Console, authentication flows, identity brokering, token issuance) continues to use the stale user until the entry is evicted (clear-user-cache, cache expiry, or a restart).
  • Deprovisioning via SCIM (active=false) therefore has no effect on logins: a disabled user can still authenticate, including through a brokered IdP login.
  • Attribute changes via SCIM (names, e-mail, custom attributes) are not visible in the Admin Console and not reflected in tokens of subsequent logins.
  • Direct JPA reads (SCIM filtered search, SCIM GET /Users/{id}, Admin API list with filters) already show the new values, so the two APIs report different states for the same user.
  • Creating (POST) and deleting (DELETE) users via SCIM behave correctly.

How to Reproduce?

  1. Realm with SCIM enabled, confidential client with manage-users and the SCIM audience mapper.
  2. POST /realms/{realm}/scim/v2/Users with "active": true -> user is created enabled.
  3. GET /admin/realms/{realm}/users/{id} once (or log in once) so the user is in the cache.
  4. PATCH /realms/{realm}/scim/v2/Users/{id} with {"schemas":["urn:ietf:params:scim:api:messages:2.0:PatchOp"],"Operations":[{"op":"replace","path":"active","value":false},{"op":"replace","path":"name.givenName","value":"Zed"}]} -> 200, response body has "active": false, "givenName": "Zed".
  5. GET /admin/realms/{realm}/users/{id} -> still "enabled": true, "firstName": "John".
  6. Log in as that user (direct login or via identity brokering) -> succeeds.
  7. POST /admin/realms/{realm}/clear-user-cache, then repeat 5 -> "enabled": false, "firstName": "Zed"; the login is now refused with “Account is disabled”.

Same with PUT /Users/{id}. Reads that hit the database directly show the new state immediately (GET /Users?filter=active eq false, GET /admin/realms/{realm}/users?enabled=false), which makes the inconsistency visible: SCIM GET /Users/{id} and filtered searches disagree with the Admin API and with authentication.

Anything else?

Found while building a SCIM-based provisioning PoC (Central Keycloak federates to a decoupled department Keycloak with identity brokering + auto-link). With this bug a SCIM active=false does not block the next brokered login.

Workaround in my PoC: POST /admin/realms/{realm}/clear-user-cache after SCIM writes, but this might have some performance implications.