Skip to content

Fix organization creation when domain is empty - #50857

Closed
ayushmanayush wants to merge 4 commits into
keycloak:mainfrom
ayushmanayush:fix-50825
Closed

Fix organization creation when domain is empty#50857
ayushmanayush wants to merge 4 commits into
keycloak:mainfrom
ayushmanayush:fix-50825

Conversation

@ayushmanayush

Copy link
Copy Markdown

Description

Fixes the regression introduced in 26.7.0 where creating an organization
without specifying a domain results in an "Invalid domain format" error.

Root cause

The frontend converted empty domain values into domain objects, causing
validation to fail even though the domain field is optional.

Solution

Filter out empty domain values before creating the domain objects so that
validation is only applied to non-empty domains.
Fixes #50825

Copilot AI review requested due to automatic review settings July 14, 2026 08:59
@ayushmanayush
ayushmanayush requested review from a team as code owners July 14, 2026 08:59
Signed-off-by: ayush <ishusingh1404@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

Fixes organization creation when the optional domain field is empty.

Changes:

  • Filters blank domains before API conversion.
  • Allows blank input in shared domain validation.

Reviewed changes

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

File Description
Organizations.java Treats blank domains as absent.
OrganizationForm.tsx Excludes blank domains from requests.


public static void validateDomain(String rawDomain) {
if (rawDomain == null) {
if (rawDomain == null || isBlank(rawDomain)) {
Copilot AI review requested due to automatic review settings July 14, 2026 09:10

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 2 out of 2 changed files in this pull request and generated 2 comments.

Comment on lines +24 to +26
domains: org.domains
?.filter((d) => d.trim() !== "")
.map((d) => ({ name: d, verified: false })),

public static void validateDomain(String rawDomain) {
if (rawDomain == null) {
if (rawDomain == null || isBlank(rawDomain)) {
Copilot AI review requested due to automatic review settings July 15, 2026 10:15

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 2 out of 2 changed files in this pull request and generated 2 comments.


public static void validateDomain(String rawDomain) {
if (rawDomain == null) {
if (rawDomain == null || isBlank(rawDomain)) {
Comment on lines +24 to +26
domains: org.domains
?.filter((d) => d.trim() !== "")
.map((d) => ({ name: d, verified: false })),
@sguilhen
sguilhen requested review from edewit and ssilvert July 17, 2026 02:48
@sguilhen

Copy link
Copy Markdown
Contributor

@ssilvert @edewit could you please review this one? It is a fix for a regression in 26.7

@ssilvert

Copy link
Copy Markdown
Contributor

@ayushmanayush All the suggestions from Copilot appear to be valid. Please fix them before we proceed with further review.

@ayushmanayush

ayushmanayush commented Jul 17, 2026

Copy link
Copy Markdown
Author

Ok I'll further look into it and update asap

Copilot AI review requested due to automatic review settings July 17, 2026 18:41

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 2 out of 2 changed files in this pull request and generated 1 comment.

Comment on lines +24 to +26
domains: org.domains
?.filter((d) => d.trim() !== "")
.map((d) => ({ name: d, verified: false })),
Copilot AI review requested due to automatic review settings July 17, 2026 18:54

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 1 comment.


public static void validateDomain(String rawDomain) {
if (rawDomain == null) {
if (isBlank(rawDomain)) {
@ssilvert

Copy link
Copy Markdown
Contributor

@ayushmanayush We need you to sign your commits so that DCO will pass.

Signed-off-by: ayush <ishusingh1404@gmail.com>
@sguilhen

Copy link
Copy Markdown
Contributor

I think all commits need to be signed-off for the DCO check to pass. So either add the sign-off or, better yet, squash them into one

@keycloak-github-bot keycloak-github-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@keycloak-github-bot

Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.oauth.ClientAuthPostMethodTest#testPostAuthenticationNotAllowedWhenBasicRequested

Keycloak CI - Base IT (6)

java.lang.NullPointerException: Cannot read field "features" because the return value of "org.keycloak.common.Profile.getInstance()" is null
	at org.keycloak.common.Profile.isFeatureEnabled(Profile.java:534)
	at org.keycloak.protocol.oidc.OIDCClientSecretConfigWrapper.<init>(OIDCClientSecretConfigWrapper.java:41)
	at org.keycloak.protocol.oidc.OIDCClientSecretConfigWrapper.fromClientRepresentation(OIDCClientSecretConfigWrapper.java:49)
	at org.keycloak.testsuite.oauth.ClientAuthPostMethodTest.testPostAuthenticationNotAllowedWhenBasicRequested(ClientAuthPostMethodTest.java:141)
...

Report flaky test

org.keycloak.testsuite.oauth.ClientAuthPostMethodTest#testBasicAuthenticationNotAllowedWhenPostRequested

Keycloak CI - Base IT (6)

java.lang.NullPointerException: Cannot read field "features" because the return value of "org.keycloak.common.Profile.getInstance()" is null
	at org.keycloak.common.Profile.isFeatureEnabled(Profile.java:534)
	at org.keycloak.protocol.oidc.OIDCClientSecretConfigWrapper.<init>(OIDCClientSecretConfigWrapper.java:41)
	at org.keycloak.protocol.oidc.OIDCClientSecretConfigWrapper.fromClientRepresentation(OIDCClientSecretConfigWrapper.java:49)
	at org.keycloak.testsuite.oauth.ClientAuthPostMethodTest.testBasicAuthenticationNotAllowedWhenPostRequested(ClientAuthPostMethodTest.java:112)
...

Report flaky test

org.keycloak.testsuite.forms.MultipleTabsLoginTest#multipleTabsParallelLoginTestWithAuthSessionExpiredAndRequiredAction

Keycloak CI - Forms IT (chrome)

org.opentest4j.AssertionFailedError: expected: <true> but was: <false>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertTrue.failNotTrue(AssertTrue.java:63)
	at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:36)
...

Report flaky test

org.keycloak.testsuite.forms.MultipleTabsLoginTest#multipleTabsParallelLoginTestWithAuthSessionExpiredAndRefreshInTab1

Keycloak CI - Forms IT (chrome)

org.opentest4j.AssertionFailedError: expected: <true> but was: <false>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertTrue.failNotTrue(AssertTrue.java:63)
	at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:36)
...

Report flaky test

@ahus1

ahus1 commented Aug 2, 2026

Copy link
Copy Markdown
Member

I think all commits need to be signed-off for the DCO check to pass. So either add the sign-off or, better yet, squash them into one

@sguilhen - ideally yes. Still, the last commit is signed off, and we might proceed with that if no-one objects. I approved the build, the frontend has some problems.

@ayushmanayush - can you please review those?

@edewit

edewit commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

there is also a prettier problem in
js/apps/admin-ui/src/organizations/OrganizationForm.test.tsx

@sguilhen

sguilhen commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Thanks for the contribution @ayushmanayush! Since this has been idle for a while and it is a fix for a regression, I went ahead and opened a new PR with the necessary adjustments so we can get it merged.

The main changes from the original PR:

  • added trim() in the .map() call - the original code filtered on d.trim() but mapped the untrimmed value, so inputs like " example.com " would pass the filter but still hit server-side validation with leading/trailing whitespace.
  • added a test for the trimming behavior and fixed prettier formatting in the test file.
  • dropped the unrelated removal of stripOrganizationId() and its import, which were accidentally included (likely from a merge).

Closing in favor of #51542.

@sguilhen sguilhen closed this Aug 7, 2026
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.

Creating an organization without a domain leads to an error

6 participants