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.
  • A member entry without a value is rejected with 400 on a group add as well as remove, instead of looking up a user with a missing id.
  • 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.

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, and the two member loops in GroupCoreModelSchema, which now reject an entry without a value.

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.
  • 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 308 integration tests (2 skipped, both already @Disabled), including UserTest 108, GroupTest 42/42 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.

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

… 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, and a group member entry without a value, are rejected with 400. An add or remove entry that is not an object, such as null or a bare id, is rejected with 400 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 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

Comment on lines +125 to +127
if (hasValue && attribute.isMultivalued() && attribute.getComplexType() != null) {
// the value lists the values to remove, e.g. "members" with [{"value": "<user id>"}], normalized as for add
values = ofNullable(resolveAttributes(path.getPath(), value).get(attribute)).orElse(NullNode.getInstance());
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