Fix creation of domains when creating the organization

Closes #29005

Signed-off-by: vramik <vramik@redhat.com>
This commit is contained in:
vramik 2024-05-30 21:12:33 +02:00 committed by Alexander Schwartz
parent 6d6131cade
commit a8ceada973
3 changed files with 3 additions and 12 deletions

View file

@ -78,7 +78,7 @@ public class JpaOrganizationProvider implements OrganizationProvider {
}
@Override
public OrganizationModel create(String name, Set<String> 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());
}

View file

@ -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<String> domains);
OrganizationModel create(String name);
/**
* Returns a {@link OrganizationModel} by its {@code id};

View file

@ -93,13 +93,8 @@ public class OrganizationsResource {
throw ErrorResponse.error("Organization cannot be null.", Response.Status.BAD_REQUEST);
}
Set<String> 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);