Uploaded image for project: 'Red Hat build of Keycloak'
  1. Red Hat build of Keycloak
  2. RHBK-2636

Profile attribute inputs incorrectly marked as required when minimum length is configured [GHI#36241]

XMLWordPrintable

    • False
    • Hide

      None

      Show
      None
    • False

      Before reporting an issue

      [X] I have read and understood the above terms for submitting issues, and I understand that my issue may be closed without action if I do not follow them.

      Area

      admin/ui

      Describe the bug

      The user attributes in /[realm]/users/[userId]/settings are incorrectly marked as required when a length validator with min is configured to a number. Unfortunately, the profile settings in the realm settings set the min to a string instead of a number, which makes this more difficult to reproduce.

      Adding validator through admin UI in realm settings:

      !image

      Adding validator through the API with a number instead:

      !image

      Note that even if a validator with length min: 10 is added to an attribute, it is still not a required attribute, and you can save the form without issues. This is the correct behavior, since fields can be optional but require a minimum length when set. For instance, if you have an optional phone number field and want to validate that the number has a specific length when it's set.

      Version

      26.0.7

      Regression

      [ ] The issue is a regression

      Expected behavior

      Validators with minimum length should not be considered as required. Only the required value should be considered.

      Actual behavior

      Using the minimum length as an "implicit" required state.

      How to Reproduce?

      1. Add a user attribute in the realm profile settings with a min length validator set to min: 1 using the Admin CLI API instead of the GUI.
      2. Open the edit form of a user.
      3. Observe that the field is marked as required, even though the field is not required.

      Anything else?

      The responsible section of code for this seems to be here:

      https://github.com/keycloak/keycloak/blob/0535c76e06cc78fd2e5107274369d0746548e5cf/js/libs/ui-shared/src/user-profile/utils.ts#L91-L121

              Unassigned Unassigned
              pvlha Pavel Vlha
              Keycloak Core IAM
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: