8000 Ignore blank values when checking required user profile attributes by Vir-007 · Pull Request #53052 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Ignore blank values when checking required user profile attributes - #53052

Merged
pedroigor merged 2 commits into
keycloak:mainfrom
Vir-007:fix-required-multivalued-attribute-blank-values
Oct 6, 2026
Merged

pedroigor merged 2 commits into
keycloak:mainfrom
Vir-007:fix-required-multivalued-attribute-blank-values

Conversation

@Vir-007
@Vir-007 Vir-007 commented Sep 22, 2026
Copy link
Copy Markdown
Contributor

Closes #52776

In the keycloak.v2 login theme, a multiselect-checkboxes attribute also renders a hidden input (<input type="hidden" name="<attr>" value="">) so that clearing every checkbox still sends the attribute. That means the form always sends an extra empty string along with the selected options. AttributeRequiredByMetadataValidator failed as soon as any value was blank, so a required multiselect attribute could never pass validation during registration, whatever the user selected.

Blank values are already dropped when the attribute is stored (DefaultUserProfile removes the attribute if every value is blank and otherwise keeps only the non-blank values). This change makes the required check follow the same rule: it now fails only when there is no non-blank value. Single-valued attributes are not affected, because an empty or blank value still fails.

Tests:

  • New UserProfileTest#testRequiredMultivaluedAttributeWithBlankValue: [""] still fails the required check, and ["", "opt1", "opt2"] now passes validation and stores ["opt1", "opt2"]. The test fails without the fix (error-user-attribute-required).
  • UserProfileTest, admin.user.UserProfileTest and DeclarativeUserTest all pass (63 tests), and spotless:check passes on services and tests/base.

AI disclosure: the code, tests and this description were written with the help of an AI coding agent (Claude Code).

Copilot AI balanced review requested due to automatic review settings September 22, 2026 12:02
@Vir-007
Vir-007 requested a review from a team as a code owner September 22, 2026 12:02
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.

Copilot review overview

🟡 Changes recommended

The blank predicate still differs from persistence, allowing some whitespace-only required values to be discarded after validation.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Aligns required multivalued attribute validation with persisted values.

Changes:

  • Accepts mixed blank and non-blank values.
  • Adds registration coverage for checkbox multiselects.
File Description
AttributeRequiredByMetadataValidator.java Updates required-value validation.
UserProfileTest.java Tests validation and persistence behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI review requested due to automatic review settings September 22, 2026 12:13
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.

Copilot review overview

🟢 Approval recommended

The implementation matches persistence semantics and includes focused regression coverage.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@Vir-007
Vir-007 commented Sep 25, 2026
Copy link
Copy Markdown
Contributor Author

CONTRIBUTING.md asks new contributors to keep at most two pull requests open at a time, and I opened seven at once, so I'm closing this one for now. I'll reopen it once the others are done. Sorry for the noise.

@Vir-007 Vir-007 closed this Sep 25, 2026
@pedroigor pedroigor reopened this Oct 5, 2026
@pedroigor
pedroigor force-pushed the fix-required-multivalued-attribute-blank-values branch from b73a182 to 6c91c39 Compare October 5, 2026 19:34
A required multivalued attribute rendered as multiselect-checkboxes in the
keycloak.v2 login theme is always submitted with an extra empty value from
a hidden input, so the required validation failed even when options were
selected. Blank values are discarded when the attribute is stored, so only
fail the required check when no non-blank value is present.

Closes keycloak#52776

Signed-off-by: anarch <2vir.sharma@gmail.com>
DefaultUserProfile drops values that are blank according to
String.isBlank() (StringUtil), while the required check used
Validation.isBlank(), which only trims ASCII whitespace. A value such as
U+2003 passed the required check and was then discarded on save.

Relates to keycloak#52776

Signed-off-by: anarch <2vir.sharma@gmail.com>
@pedroigor
pedroigor force-pushed the fix-required-multivalued-attribute-blank-values branch from 6c91c39 to 37eade2 Compare October 6, 2026 11:16
Copilot AI balanced review requested due to automatic review settings October 6, 2026 11:16
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.

Copilot review overview

🟢 Approval recommended

The implementation matches persistence semantics and includes focused regression coverage.

Review effort: Balanced
Findings: None

@pedroigor
pedroigor merged commit 128db24 into keycloak:main Oct 6, 2026
97 checks passed
@pedroigor
Copy link
Copy Markdown
Contributor

Thanks, @Vir-007.

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.

Registration not possible when using multiselect-checkboxes as required user profile attribute

3 participants

0