Skip to content

SCIM : Support type "Group" in "members" field for child groups - #51478

Open
cgeorgilakis wants to merge 1 commit into
keycloak:mainfrom
eosc-kc:51078_scim_members
Open

SCIM : Support type "Group" in "members" field for child groups#51478
cgeorgilakis wants to merge 1 commit into
keycloak:mainfrom
eosc-kc:51078_scim_members

Conversation

@cgeorgilakis

Copy link
Copy Markdown
Contributor

Closes #51078

@cgeorgilakis
cgeorgilakis requested a review from a team as a code owner August 6, 2026 08:04
Copilot AI balanced review requested due to automatic review settings August 6, 2026 08:04

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

Authorization leaks, hierarchy cycles, unsafe detachments, and incorrect move semantics must be addressed.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

Adds SCIM nested-group membership support.

Changes:

  • Returns child groups as Group members.
  • Supports adding/removing subgroup members through PATCH.
  • Adds request-builder support and integration tests.
File summaries
File Description
GroupCoreModelSchema.java Maps and manages subgroup members.
PatchRequest.java Adds structured member PATCH values.
GroupTest.java Tests mixed user/group membership.
Review details

Suppressed comments (1)

scim/model/src/main/java/org/keycloak/scim/model/group/GroupCoreModelSchema.java:185

  • The untyped removal path can likewise detach any visible group named by the filter, even when that group is not a member of model. Guard the parent relationship and perform the change through the realm move API.
                                model.removeChild(subGroup);
  • Files reviewed: 3/3 changed files
  • Comments generated: 6
  • Review effort level: Balanced

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Comment on lines 72 to +76
if (permissions.hasPermission(model, AdminPermissionsSchema.GROUPS_RESOURCE_TYPE, AdminPermissionsSchema.VIEW_MEMBERS)) {
members = session.users().getGroupMembersStream(realm, model)
.filter(this::canViewUser);
members.addAll(session.users().getGroupMembersStream(realm, model)
.filter(this::canViewUser).toList());
}
members.addAll(model.getSubGroupsStream().toList());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is it possible in Keycloak model, a user to have access to a parent group and not to its subgroup?

throw new ModelValidationException("Group with id " + member.getValue() + " not found");
}
checkGroupMembershipPermission(session.getContext().getPermissions(), subGroup);
model.removeChild(subGroup);
}
if (!model.getId().equals(subGroup.getParentId())) {
checkGroupMembershipPermission(session.getContext().getPermissions(), subGroup);
model.addChild(subGroup);
} else {
GroupModel subGroup = session.groups().getGroupById(realm, member.getValue());
if (subGroup == null || !canViewGroup(subGroup)) {
throw new ModelValidationException("User or Group ` with id " + member.getValue() + " not found");
Comment on lines +197 to +199
if (model.getId().equals(member.getValue())) {
throw new ModelValidationException("A group cannot be a member of itself");
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is correct. However, I don't see any such check in Admin REST API.
Do we need it? Generally, I believe that we should have the same check as Admin REST API.

Comment on lines +132 to +140
public Builder add(String path, Object objectValue) {
try {
String json = JsonSerialization.writeValueAsString(objectValue);
operation("add", path, json);
} catch (IOException e) {
throw new RuntimeException(e);
}
return this;
}
Copilot AI review requested due to automatic review settings August 6, 2026 14:21
Closes keycloak#51078

Signed-off-by: cgeorgilakis-grnet <cgeorgilakis@admin.grnet.gr>
@cgeorgilakis

Copy link
Copy Markdown
Contributor Author

I have made changes based on Copilot comments except my comments in some of its proposals.

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

Subgroup membership is not included in existing members.value filtering.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details

Suppressed comments (1)

scim/model/src/main/java/org/keycloak/scim/model/group/GroupCoreModelSchema.java:76

  • members.value now returns subgroup IDs, but filtering that same attribute still joins only UserGroupMembershipEntity (GroupResourceTypeProvider.java:205-210). As a result, GET /Groups?filter=members.value eq "<child-group-id>" omits the parent even though its returned members contains that child; extend the filter predicate to include groups whose child has that ID.
                members.addAll(model.getSubGroupsStream().toList());
  • Files reviewed: 3/3 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Copilot AI review requested due to automatic review settings August 6, 2026 14: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

Group-member filtering remains user-only, and prior authorization and hierarchy-cycle concerns remain unresolved.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details

Suppressed comments (1)

scim/model/src/main/java/org/keycloak/scim/model/group/GroupCoreModelSchema.java:76

  • Adding subgroups to members makes members.value cover both users and groups, but GroupResourceTypeProvider.getAttributeExpression still joins only UserGroupMembershipEntity; consequently, filtering Groups by a child-group ID omits the parent even though GET returns that child in members. Extend the query mapping to match child groups via their parentId and cover this alongside the existing user-member filter test.
                members.addAll(model.getSubGroupsStream().toList());
  • Files reviewed: 3/3 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

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 : Support type "Group" in "members" field for child groups

3 participants