Skip to content

Add option to include empty organization claim - #50745

Closed
Develop-KIM wants to merge 2 commits into
keycloak:mainfrom
Develop-KIM:fix-empty-organization-claim
Closed

Add option to include empty organization claim#50745
Develop-KIM wants to merge 2 commits into
keycloak:mainfrom
Develop-KIM:fix-empty-organization-claim

Conversation

@Develop-KIM

@Develop-KIM Develop-KIM commented Jul 9, 2026

Copy link
Copy Markdown

Closes #50410

Summary

  • Add an opt-in includeEmptyClaim setting to the organization membership mapper.
  • Map an empty organization claim for users with no mapped organizations when the mapper is included through a default client scope.
  • Cover access token, ID token, userinfo, and JSON claim output.
  • Add the admin UI label/help text for the new mapper option.

Verification

  • ./mvnw -pl services -am -DskipTests compile
  • ./mvnw -pl testsuite/integration-arquillian/tests/base -am -DskipTests install
  • ./mvnw -pl testsuite/integration-arquillian/tests/base -Dtest=org.keycloak.testsuite.organization.mapper.OrganizationOIDCProtocolMapperTest#testEmptyOrganizationClaimMappedWhenConfigured test
  • ./mvnw -pl testsuite/integration-arquillian/tests/base -Dtest=org.keycloak.testsuite.organization.mapper.OrganizationOIDCProtocolMapperTest#testEmptyOrganizationClaimMappedAsJsonWhenConfigured clean test
  • ./mvnw -pl services,testsuite/integration-arquillian/tests/base spotless:check
  • git diff --check

Disclosure

This contribution was prepared with AI assistance and reviewed before submission.

@Develop-KIM
Develop-KIM requested a review from a team as a code owner July 9, 2026 18:36
Copilot AI review requested due to automatic review settings July 9, 2026 18:36
@Develop-KIM
Develop-KIM requested review from a team as code owners July 9, 2026 18:36
Closes #50410

Co-Authored-By: openai-codex <noreply@openai.com>
Signed-off-by: Develop-KIM <kimdonghwan913@gmail.com>

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.

Pull request overview

This PR resolves issue #50410 by adding an opt-in includeEmptyClaim setting to the Organization Membership OIDC protocol mapper. Previously, when a user belonged to zero organizations, the organization claim was entirely omitted from tokens, making an authoritative "member of nothing" indistinguishable from a missing/dropped claim. With the new flag (default false, preserving backward compatibility), the mapper can emit a deterministic empty value ([] for multivalued, {} for JSON) across access token, ID token, userinfo, and introspection output.

The implementation works around OIDCAttributeMapperHelper.mapClaim (which drops empty collections via mapAttributeValue) by detecting the empty claim in setClaim and writing it directly with JsonUtils.mapClaim. The default path (flag off) still returns null, so existing behavior is unchanged.

Changes:

  • Added INCLUDE_EMPTY_CLAIM config property and resolveEmptyValue/isEmptyClaim/mapEmptyClaim helpers to OrganizationMembershipMapper.
  • Added admin UI label/help text for the new option.
  • Added integration tests covering the empty-claim output for list and JSON claim types across access/ID/userinfo tokens.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
services/.../oidc/OrganizationMembershipMapper.java Adds the includeEmptyClaim option and logic to emit an empty claim for org-less users.
js/apps/admin-ui/maven-resources/theme/keycloak.v2/admin/messages/messages_en.properties Adds the admin UI label and help text for the new mapper option.
testsuite/.../organization/mapper/OrganizationOIDCProtocolMapperTest.java Adds tests verifying empty-claim output for list/JSON types and a helper to promote the org scope to a default scope.

Comment on lines +231 to +235
if (OIDCAttributeMapperHelper.isMultivalued(model)) {
return List.of();
}

return null;
Closes #50410

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Develop-KIM <kimdonghwan913@gmail.com>
Copilot AI review requested due to automatic review settings July 9, 2026 18:57

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

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.

Organization Membership mapper omits the claim for users with zero organizations instead of emitting an empty value

3 participants