Skip to content

Remove the SCIM group members or user groups listed in a PATCH remove value - #55310

Open
Prasad484 wants to merge 1 commit into
keycloak:mainfrom
Prasad484:scim-entra-remove-by-value
Open

Prasad484 wants to merge 1 commit into
keycloak:mainfrom
Prasad484:scim-entra-remove-by-value

Conversation

@Prasad484

@Prasad484 Prasad484 commented Nov 18, 2026 •

Copy link
Copy Markdown

Closes #55307

Why honour value instead of rejecting it

RFC 7644 §3.5.2.2 defines no value for remove, and, read strictly, a remove on members without a filter removes every member. Microsoft Entra ID still sends exactly this request to remove one member (Microsoft's SCIM tutorial, "Update Group [Remove Members]"). Clearing the group would be destructive, and a 400 would leave Entra-managed groups unable to lose members at all, so the listed members are removed. That is what Entra expects, and it gives the same result as the filter form members[value eq "<id>"].

Decisions

  • The value is handled in AbstractModelSchema.remove, which users and groups share, so a user PATCH with "path": "groups" and a value now removes the user from the listed groups. Before this change it also answered 200 and left the user in every group. emails behaves as before, because its remover always clears the email. The admin-v2 client schema implements ModelSchema directly and keeps the default overload, which ignores the value.
  • An unknown id fails the whole operation with 400 and removes nothing, and a listed entry that is not present is skipped. For group members, both match the filter form today.
  • A remove with both a filter in the path and a value is rejected with 400 for any user or group attribute, because the RFC does not define that combination and neither choice of which one wins is obviously right. Before, the value was ignored.
  • An entry without a value is rejected with 400 instead of being looked up with a missing id: a member on a group add or remove, and a group on a user add, remove or PUT. The user PUT setter also compares the current groups against the request null-safely, so a missing id reaches the check instead of failing there first.
  • An entry that is not an object, such as [null] or ["<id>"], is rejected with 400 on add and remove of any multi-valued complex attribute. On main, add already fails with 500 for these entries, and remove would have inherited that once it reads the value. The check sits in AbstractModelSchema.setValue, which both operations pass through, so they reject the same input the same way. PUT and create are left alone, since their values come from the typed representation.
  • Attribute names are case insensitive (RFC 7643 §2.1). An add or remove that spells members or groups in another case, such as "path": "Members", with an object rather than an array in value failed with 500, because the alias branch of AbstractModelSchema.resolveAttributes unwrapped the object to a bare id. For a complex multi-valued attribute with an object value, that branch now resolves the value under the attribute's own name, as the lowercase spelling does. Other attributes keep the existing unwrapping, which simple attributes rely on.
  • An entry whose fields cannot be read into the entry type, such as {"value": {}} where the id must be a string, is rejected with 400 "Invalid value for members" (or groups) on add and remove. AttributeMapper used to wrap the Jackson failure in a RuntimeException, which answered 500. The message leaves out Jackson's text, which names internal Java types. A user PUT with the same entry already answered 400, because the request body fails to parse before this code runs.

Not changed

A remove on members with neither a filter nor a value still removes nobody. That case is discussed on #52752 and is left out of this change.

Review focus

AbstractModelSchema.remove, where the operation value is turned into the entries to remove, the entry check in AbstractModelSchema.setValue, the two member loops in GroupCoreModelSchema and the three group loops in UserCoreModelSchema, which now reject an entry without a value, the alias branch of AbstractModelSchema.resolveAttributes, and AttributeMapper.readComplexValue.

Local validation (main f2326fc)

  • Before the fix, with only the new tests applied: ./mvnw -pl scim/tests/base test -Dtest='GroupTest,AdminGroupProtectionTest' fails 4 of the 5 new group tests. testCannotRemoveServiceAccountByValue passes on main too, since main also refuses that request; it guards that service accounts stay protected when they are named in value. UserTest#testPatchRemoveGroupsByValue also fails on main: after a 200, the user is still in all three groups. On main, an add with [null] or ["<id>"] on members or groups answers 500. Before the path spelling fix, GroupTest#testPatchMembersWithPathInAnotherCase and UserTest#testPatchGroupsWithPathInAnotherCase fail with 500 (ClassCastException) on a remove with "Members" or "Groups" and an object value. Before the unreadable entry fix, GroupTest#testPatchMembersRejectsEntriesWithAnInvalidValue and UserTest#testGroupsRejectEntriesWithAnInvalidValue fail with 500 on both remove and add with {"value": {}}.
  • After the fix, with the distribution rebuilt from this branch (quarkus/dist, which the test server is unpacked from): ./mvnw -pl scim/core,scim/tests/base test passes, with 51 unit tests and 313 integration tests (2 skipped, both already @Disabled), including UserTest 111, GroupTest 44/44 and AdminGroupProtectionTest 25/25.
  • ./mvnw -Pspotless spotless:check -pl scim/core,scim/model,scim/tests/base passes.

Upgrade note

Added under Notable changes, because a client that received 200 for this request will now see members or groups removed, or a 400 for an unknown id, a filter with a value, or an entry that is not an object or cannot be read.

AI assistance: this change was prepared with Claude Code, an AI coding agent. I have reviewed it and will handle the review.

@Prasad484
Prasad484 force-pushed the scim-entra-remove-by-value branch from 452b68f to 20223cb Compare November 18, 2026 13:26
@Prasad484 Prasad484 changed the title Remove SCIM group members listed in a PATCH remove value Remove the SCIM group members or user groups listed in a PATCH remove value Nov 18, 2026
@Prasad484
Prasad484 marked this pull request as ready for review November 18, 2026 13:27
@Prasad484
Prasad484 requested a review from a team as a code owner November 18, 2026 13:27
Copilot AI balanced review requested due to automatic review settings November 18, 2026 13:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Malformed members or groups removal arrays containing null or string entries can trigger unhandled exceptions and HTTP 500 responses instead of validation errors returning 400.

1 open issue
What changed in this PR

This PR fixes SCIM PATCH removals that previously returned success without changing membership. It supports Microsoft Entra ID’s value-list format for group members and extends the same behavior to user groups, addressing #55307 while leaving unfiltered replacement behavior in #52752 unchanged.

Changes:

  • Pass PATCH removal values through the shared schema layer to select memberships to remove.
  • Reject conflicting filters and values, and group member entries with missing IDs.
  • Add membership and service-account regression tests, usage examples, and upgrade guidance.
File Description
scim/​tests/​base/​src/​test/​java/​org/​keycloak/​tests/​scim/​tck/​UserTest.java Tests user-group removal by value and invalid requests.
scim/​tests/​base/​src/​test/​java/​org/​keycloak/​tests/​scim/​tck/​GroupTest.java Tests member removal, events, and invalid targets.
scim/​tests/​base/​src/​test/​java/​org/​keycloak/​tests/​scim/​tck/​AdminGroupProtectionTest.java Tests service-account protection during value-based removal.
scim/​model/​src/​main/​java/​org/​keycloak/​scim/​model/​group/​GroupCoreModelSchema.java Rejects missing member IDs during add and remove.
scim/​core/​src/​main/​java/​org/​keycloak/​scim/​resource/​spi/​AbstractScimResourceTypeProvider.java Forwards operation values to schema removal.
scim/​core/​src/​main/​java/​org/​keycloak/​scim/​resource/​schema/​path/​Path.java Exposes whether a path contains a filter.
scim/​core/​src/​main/​java/​org/​keycloak/​scim/​resource/​schema/​ModelSchema.java Adds a value-aware removal overload.
scim/​core/​src/​main/​java/​org/​keycloak/​scim/​resource/​schema/​AbstractModelSchema.java Resolves removal targets and rejects filter/value conflicts.
scim/​core/​src/​main/​java/​org/​keycloak/​scim/​protocol/​request/​PatchRequest.java Adds a builder overload for removal values.
docs/​documentation/​upgrading/​topics/​changes/​changes-27_0_0.adoc Explains changed behavior and membership reconciliation guidance.
docs/​documentation/​server_admin/​topics/​scim/​managing-users.adoc Documents removing user groups by value.
docs/​documentation/​server_admin/​topics/​scim/​managing-groups.adoc Documents member removal by value and error behavior.

Review effort: Balanced

@Prasad484
Prasad484 force-pushed the scim-entra-remove-by-value branch from 20223cb to d3fc17e Compare November 19, 2026 01:44
Copilot AI balanced review requested due to automatic review settings November 19, 2026 01:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

User group PATCH requests with missing or null group IDs can return 500 instead of 400, requiring validation in the group remover and regression coverage.

1 open issue
1 resolved since last review

Review effort: Balanced

@Prasad484
Prasad484 force-pushed the scim-entra-remove-by-value branch from d3fc17e to 98d7999 Compare November 19, 2026 02:24
Copilot AI balanced review requested due to automatic review settings November 19, 2026 02:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Case-insensitive SCIM paths such as Members and Groups can trigger HTTP 500 errors because alias resolution unwraps complex objects into strings that the remover casts to member objects.

1 open issue
1 resolved since last review

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Malformed member or group removal requests can trigger HTTP 500 because complex-value deserialization failures are not translated into validation errors that return 400.

1 open issue
1 resolved since last review

Review effort: Balanced

… value

A PATCH remove with a list in the operation's value and no filter in the path now removes the listed entries, instead of answering 200 and changing nothing. On a group, path members removes those members; on a user, path groups removes the user from those groups. The value is passed to the model schema; a remove with both a filter and a value is rejected with 400. An entry without a value (a group member, or a user's group in an add, remove or PUT), and an add or remove entry that is not an object, such as null or a bare id, or whose fields cannot be read, such as {"value": {}}, are rejected with 400 instead of failing with 500. An add or remove that spells members or groups in another case, such as Members, with a single object in value now works as the lowercase spelling does, instead of failing with 500.

Closes keycloak#55307

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Prasad Rahatekar <83812676+Prasad484@users.noreply.github.com>
@Prasad484
Prasad484 force-pushed the scim-entra-remove-by-value branch from 197c931 to e62baab Compare November 19, 2026 03:45
Copilot AI balanced review requested due to automatic review settings November 19, 2026 03:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The SCIM PATCH membership-removal change has no active review issues.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SCIM PATCH remove on members with a value list answers 200 and removes nobody

2 participants