Skip to content

🐞 Keycloak: unexpected locale field when adding languages to realm #2660

Open
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-unexpected-locale-field
Open

🐞 Keycloak: unexpected locale field when adding languages to realm #2660
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-unexpected-locale-field

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 11, 2026

Parent issue: https://github.com/sequentech/meta/issues/11716

Keycloak adds a built-in locale user-profile attribute when realm internationalization is enabled. In deferred registration, this surfaced as an unexpected required field.

  • Form rendering

    • Deferred registration now provides a Java-configured hiddenProfileAttributes list containing locale.
    • The Keycloak login theme applies that Java-provided list when rendering profile.attributes.
  • Deferred registration validation

    • Strip UserModel.LOCALE from normalized form data before creating the UserProfile.
    • Ignore Keycloak’s required-field validation error for locale.
  • Regression coverage

    • Added focused voter-enrollment tests for locale removal, hidden profile attribute configuration, and required-locale validation filtering.
public static final Set<String> HIDDEN_PROFILE_ATTRIBUTES = Set.of(UserModel.LOCALE);

form.setAttribute("hiddenProfileAttributes", HIDDEN_PROFILE_ATTRIBUTES);

Copilot AI changed the title [WIP] Fix unexpected locale field when adding languages to realm Hide Keycloak locale field in deferred registration May 11, 2026
Copilot AI requested a review from edulix May 11, 2026 20:55
Copilot finished work on behalf of edulix May 11, 2026 20:55
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 11, 2026

All contributors have signed the CLA. ✅
Posted by the CLA Assistant Lite bot.

Copy link
Copy Markdown
Contributor

@edulix edulix left a comment

Choose a reason for hiding this comment

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

apply required changes in this same branch

<#assign disabledElements = []>

<#list profile.attributes as attribute>
<#if attribute.name == "locale">
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.

I don't like this. Can't this be filtered in java properly instead?

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.

Addressed in 28d4b36: the locale field is now supplied from Java via HIDDEN_PROFILE_ATTRIBUTES, and the template only applies the generic Java-provided hidden attribute list instead of hardcoding locale.

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.11.4</version>
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.

please ensure this is the latest version

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.

Addressed in 28d4b36: updated JUnit Jupiter to 6.0.3, the latest stable release listed in Maven metadata; 6.1.0-RC1 is a release candidate.

@edulix edulix changed the title Hide Keycloak locale field in deferred registration 🐞 Keycloak: unexpected locale field when adding languages to realm May 11, 2026
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 11, 2026

apply required changes in this same branch

Applied the required changes in this same branch in 28d4b36.

Copilot AI changed the title 🐞 Keycloak: unexpected locale field when adding languages to realm Hide Keycloak locale field in deferred registration May 11, 2026
Copilot finished work on behalf of edulix May 11, 2026 21:09
Copilot AI requested a review from edulix May 11, 2026 21:09
@edulix edulix changed the title Hide Keycloak locale field in deferred registration 🐞 Keycloak: unexpected locale field when adding languages to realm May 11, 2026
@edulix edulix marked this pull request as ready for review May 11, 2026 21:34
Copilot AI review requested due to automatic review settings May 11, 2026 21:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes deferred-registration failures when Keycloak realm internationalization injects a built-in locale user-profile attribute by (a) hiding locale from the rendered profile attributes and (b) preventing locale from surfacing as a required-field validation blocker during deferred registration.

Changes:

  • Add locale to a Java-provided hiddenProfileAttributes set and pass it to the theme so locale isn’t rendered as a user-editable/required field.
  • Strip UserModel.LOCALE from normalized form data and filter out the specific “required locale” validation error.
  • Add focused JUnit tests covering locale removal, hidden attribute configuration, and locale-required error filtering.

Reviewed changes

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

File Description
packages/keycloak-extensions/voter-enrollment/src/main/java/sequent/keycloak/voter_enrollment/DeferredRegistrationUserCreation.java Removes locale from normalized form params, ignores required-locale validation error, and exposes hiddenProfileAttributes to the form/theme.
packages/keycloak-extensions/voter-enrollment/src/test/java/sequent/keycloak/voter_enrollment/DeferredRegistrationUserCreationTest.java Adds regression tests for locale stripping, hidden attribute configuration, and required-locale error matching.
packages/keycloak-extensions/voter-enrollment/pom.xml Adds a JUnit dependency for the new tests (currently with an invalid/nonexistent version).
packages/keycloak-extensions/sequent-theme/src/main/resources/theme/sequent.admin-portal/login/user-profile-commons.ftl Skips rendering profile attributes present in hiddenProfileAttributes (e.g., locale).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants