Repository navigation
Conversation
Closes keycloak#51755 Signed-off-by: Thibault Debatty <thibault.debatty@proton.me>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The test flattens all attribute values without asserting two single-valued attributes, so it can pass even if the mapper ignores single=false when parent groups are enabled.
1 open issue
What changed in this PR
Adds an opt-in setting to include ancestor groups in OIDC group claims and SAML group attributes, supporting authorization based on inherited group membership while preserving existing defaults.
Changes:
- Adds
include.parent.groups, defaulting tofalse, to both protocol mappers. - Introduces a shared hierarchy helper and de-duplicates expanded memberships by group ID.
- Adds unit and integration coverage for parent inclusion, full paths, and de-duplication.
| File | Description |
|---|---|
tests/base/src/test/java/org/keycloak/tests/admin/group/GroupMappersTest.java |
Adds an OIDC parent-group integration test. |
services/src/test/java/org/keycloak/protocol/saml/mappers/GroupMembershipMapperTest.java |
Tests parent inclusion and SAML attribute modes. |
services/src/test/java/org/keycloak/protocol/oidc/mappers/GroupMembershipMapperTest.java |
Tests defaults, ancestor expansion, paths, and distinct group IDs. |
services/src/main/java/org/keycloak/protocol/saml/mappers/GroupMembershipMapper.java |
Adds optional ancestor expansion for SAML attributes. |
services/src/main/java/org/keycloak/protocol/oidc/mappers/GroupMembershipMapper.java |
Adds optional ancestor expansion for OIDC claims. |
server-spi-private/src/main/java/org/keycloak/models/utils/KeycloakModelUtils.java |
Adds the shared group hierarchy helper. |
Review effort: Balanced
… attributes when parent groups are enabled' Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Thibault Debatty <thibault.debatty@proton.me>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

This adds a new "include.parent.groups" configuration option (default false) to the OIDC and SAML GroupMembershipMapper protocol mappers. When enabled, the group claim/attribute contains not only the groups the user is a direct member of, but also all parent groups, de-duplicated by group ID. This makes the claim more useful for downstream authorization decisions based on ancestor groups.
The hierarchy is computed by a new KeycloakModelUtils.getGroupHierarchy helper, which walks up the parent chain and returns the groups ordered from the top-level ancestor down to the given group. Organization groups are treated as top-level, so their hierarchy consists of the group itself. De-duplication is done by group ID rather than name, since names are not unique across the hierarchy.
Closes #51755