diff --git a/model/jpa/src/main/java/org/keycloak/organization/jpa/OrganizationAdapter.java b/model/jpa/src/main/java/org/keycloak/organization/jpa/OrganizationAdapter.java index 31deb133b7..cb8b674068 100644 --- a/model/jpa/src/main/java/org/keycloak/organization/jpa/OrganizationAdapter.java +++ b/model/jpa/src/main/java/org/keycloak/organization/jpa/OrganizationAdapter.java @@ -20,6 +20,7 @@ package org.keycloak.organization.jpa; import org.keycloak.models.GroupModel; import java.util.Collection; import java.util.Map; +import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -68,28 +69,14 @@ public final class OrganizationAdapter implements OrganizationModel, JpaModel values) { - getGroup().setAttribute(name, values); - } - - @Override - public void removeAttribute(String name) { - getGroup().removeAttribute(name); - } - - @Override - public String getFirstAttribute(String name) { - return getGroup().getFirstAttribute(name); - } - - @Override - public Stream getAttributeStream(String name) { - return getGroup().getAttributeStream(name); + public void setAttributes(Map> attributes) { + if (attributes == null) { + return; + } + Set attrsToRemove = getAttributes().keySet(); + attrsToRemove.removeAll(attributes.keySet()); + attrsToRemove.forEach(group::removeAttribute); + attributes.forEach(group::setAttribute); } @Override diff --git a/server-spi/src/main/java/org/keycloak/models/OrganizationModel.java b/server-spi/src/main/java/org/keycloak/models/OrganizationModel.java index ff7bf63dd6..18b00f07d3 100644 --- a/server-spi/src/main/java/org/keycloak/models/OrganizationModel.java +++ b/server-spi/src/main/java/org/keycloak/models/OrganizationModel.java @@ -32,18 +32,10 @@ public interface OrganizationModel { String getName(); - void setSingleAttribute(String name, String value); - - void setAttribute(String name, List values); - - void removeAttribute(String name); - - String getFirstAttribute(String name); - - Stream getAttributeStream(String name); - Map> getAttributes(); + void setAttributes(Map> attributes); + Stream getDomains(); void setDomains(Collection domains); diff --git a/services/src/main/java/org/keycloak/organization/admin/resource/OrganizationResource.java b/services/src/main/java/org/keycloak/organization/admin/resource/OrganizationResource.java index 654b094254..a9c0de0e5f 100644 --- a/services/src/main/java/org/keycloak/organization/admin/resource/OrganizationResource.java +++ b/services/src/main/java/org/keycloak/organization/admin/resource/OrganizationResource.java @@ -17,6 +17,8 @@ package org.keycloak.organization.admin.resource; +import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.Objects; import java.util.stream.Collectors; @@ -182,26 +184,18 @@ public class OrganizationResource { } model.setName(rep.getName()); + model.setAttributes(rep.getAttributes()); + model.setDomains(Optional.ofNullable(rep.getDomains()).orElse(Set.of()).stream() + .filter(this::validateDomainRepresentation) + .peek(domainRep -> { + OrganizationModel orgModel = provider.getByDomainName(domainRep.getName()); + if (orgModel != null && !Objects.equals(model.getId(), orgModel.getId())) { + throw ErrorResponse.error("Domain " + domainRep.getName() + " is already linked to another organization", Response.Status.BAD_REQUEST); + } + }) + .map(this::toModel) + .collect(Collectors.toSet())); - if (rep.getAttributes() != null) { - Set attrsToRemove = model.getAttributes().keySet(); - attrsToRemove.removeAll(rep.getAttributes().keySet()); - attrsToRemove.forEach(model::removeAttribute); - - rep.getAttributes().entrySet().forEach(entry -> model.setAttribute(entry.getKey(), entry.getValue())); - } - - if (rep.getDomains() != null) { - model.setDomains(rep.getDomains().stream().filter(this::validateDomainRepresentation) - .peek(domainRep -> { - OrganizationModel orgModel = provider.getByDomainName(domainRep.getName()); - if (orgModel != null && !Objects.equals(model.getId(), orgModel.getId())) { - throw ErrorResponse.error("Domain " + domainRep.getName() + " is already linked to another organization", Response.Status.BAD_REQUEST); - } - }) - .map(this::toModel) - .collect(Collectors.toSet())); - } return model; }