Repository navigation
Conversation
452b68f to
20223cb
Compare
There was a problem hiding this comment.
🟡 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
20223cb to
d3fc17e
Compare
d3fc17e to
98d7999
Compare
There was a problem hiding this comment.
🟡 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
98d7999 to
197c931
Compare
There was a problem hiding this comment.
🟡 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>
197c931 to
e62baab
Compare
Closes #55307
Why honour
valueinstead of rejecting itRFC 7644 §3.5.2.2 defines no
valueforremove, and, read strictly, aremoveonmemberswithout 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 formmembers[value eq "<id>"].Decisions
AbstractModelSchema.remove, which users and groups share, so a userPATCHwith"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.emailsbehaves as before, because its remover always clears the email. The admin-v2 client schema implementsModelSchemadirectly and keeps the default overload, which ignores the value.removewith both a filter in the path and avalueis 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.valueis rejected with 400 instead of being looked up with a missing id: a member on a groupaddorremove, and a group on a useradd,removeorPUT. The userPUTsetter also compares the current groups against the request null-safely, so a missing id reaches the check instead of failing there first.[null]or["<id>"], is rejected with 400 onaddandremoveof any multi-valued complex attribute. On main,addalready fails with 500 for these entries, andremovewould have inherited that once it reads the value. The check sits inAbstractModelSchema.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.addorremovethat spellsmembersorgroupsin another case, such as"path": "Members", with an object rather than an array invaluefailed with 500, because the alias branch ofAbstractModelSchema.resolveAttributesunwrapped 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.{"value": {}}where the id must be a string, is rejected with 400 "Invalid value for members" (orgroups) onaddandremove.AttributeMapperused to wrap the Jackson failure in aRuntimeException, which answered 500. The message leaves out Jackson's text, which names internal Java types. A userPUTwith the same entry already answered 400, because the request body fails to parse before this code runs.Not changed
A
removeonmemberswith neither a filter nor avaluestill 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 inAbstractModelSchema.setValue, the two member loops inGroupCoreModelSchemaand the three group loops inUserCoreModelSchema, which now reject an entry without avalue, the alias branch ofAbstractModelSchema.resolveAttributes, andAttributeMapper.readComplexValue.Local validation (main f2326fc)
./mvnw -pl scim/tests/base test -Dtest='GroupTest,AdminGroupProtectionTest'fails 4 of the 5 new group tests.testCannotRemoveServiceAccountByValuepasses on main too, since main also refuses that request; it guards that service accounts stay protected when they are named invalue.UserTest#testPatchRemoveGroupsByValuealso fails on main: after a 200, the user is still in all three groups. On main, anaddwith[null]or["<id>"]onmembersorgroupsanswers 500. Before the path spelling fix,GroupTest#testPatchMembersWithPathInAnotherCaseandUserTest#testPatchGroupsWithPathInAnotherCasefail with 500 (ClassCastException) on aremovewith"Members"or"Groups"and an object value. Before the unreadable entry fix,GroupTest#testPatchMembersRejectsEntriesWithAnInvalidValueandUserTest#testGroupsRejectEntriesWithAnInvalidValuefail with 500 on bothremoveandaddwith{"value": {}}.quarkus/dist, which the test server is unpacked from):./mvnw -pl scim/core,scim/tests/base testpasses, with 51 unit tests and 313 integration tests (2 skipped, both already@Disabled), includingUserTest111,GroupTest44/44 andAdminGroupProtectionTest25/25../mvnw -Pspotless spotless:check -pl scim/core,scim/model,scim/tests/basepasses.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.