From a8ceada9738bc106e4ca6913ad571e30bd641848 Mon Sep 17 00:00:00 2001 From: vramik Date: Thu, 30 May 2024 21:12:33 +0200 Subject: [PATCH] Fix creation of domains when creating the organization Closes #29005 Signed-off-by: vramik --- .../keycloak/organization/jpa/JpaOrganizationProvider.java | 4 +--- .../org/keycloak/organization/OrganizationProvider.java | 4 +--- .../organization/admin/resource/OrganizationsResource.java | 7 +------ 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/model/jpa/src/main/java/org/keycloak/organization/jpa/JpaOrganizationProvider.java b/model/jpa/src/main/java/org/keycloak/organization/jpa/JpaOrganizationProvider.java index e8a0b39be5..070ba2c1db 100644 --- a/model/jpa/src/main/java/org/keycloak/organization/jpa/JpaOrganizationProvider.java +++ b/model/jpa/src/main/java/org/keycloak/organization/jpa/JpaOrganizationProvider.java @@ -78,7 +78,7 @@ public class JpaOrganizationProvider implements OrganizationProvider { } @Override - public OrganizationModel create(String name, Set domains) { + public OrganizationModel create(String name) { if (StringUtil.isBlank(name)) { throw new ModelValidationException("Name can not be null"); } @@ -98,8 +98,6 @@ public class JpaOrganizationProvider implements OrganizationProvider { adapter.setEnabled(true); em.persist(adapter.getEntity()); - - adapter.setDomains(domains.stream().map(OrganizationDomainModel::new).collect(Collectors.toSet())); } finally { session.removeAttribute(OrganizationModel.class.getName()); } diff --git a/server-spi-private/src/main/java/org/keycloak/organization/OrganizationProvider.java b/server-spi-private/src/main/java/org/keycloak/organization/OrganizationProvider.java index 758b7f4d2f..94e27025b5 100644 --- a/server-spi-private/src/main/java/org/keycloak/organization/OrganizationProvider.java +++ b/server-spi-private/src/main/java/org/keycloak/organization/OrganizationProvider.java @@ -17,7 +17,6 @@ package org.keycloak.organization; import java.util.Map; -import java.util.Set; import java.util.stream.Stream; import org.keycloak.models.IdentityProviderModel; import org.keycloak.models.ModelDuplicateException; @@ -35,11 +34,10 @@ public interface OrganizationProvider extends Provider { * Creates a new organization with given {@code name} to the realm. * The internal ID of the organization will be created automatically. * @param name String name of the organization. - * @param domains the domains * @throws ModelDuplicateException If there is already an organization with the given name * @return Model of the created organization. */ - OrganizationModel create(String name, Set domains); + OrganizationModel create(String name); /** * Returns a {@link OrganizationModel} by its {@code id}; diff --git a/services/src/main/java/org/keycloak/organization/admin/resource/OrganizationsResource.java b/services/src/main/java/org/keycloak/organization/admin/resource/OrganizationsResource.java index 449b3066a1..a7b03e00bd 100644 --- a/services/src/main/java/org/keycloak/organization/admin/resource/OrganizationsResource.java +++ b/services/src/main/java/org/keycloak/organization/admin/resource/OrganizationsResource.java @@ -93,13 +93,8 @@ public class OrganizationsResource { throw ErrorResponse.error("Organization cannot be null.", Response.Status.BAD_REQUEST); } - Set domains = ofNullable(organization.getDomains()).orElse(Set.of()).stream() - .map(OrganizationDomainRepresentation::getName) - .filter(StringUtil::isNotBlank) - .collect(Collectors.toSet()); - try { - OrganizationModel model = provider.create(organization.getName(), domains); + OrganizationModel model = provider.create(organization.getName()); Organizations.toModel(organization, model);