From aa945d563613434e10b87aa2fc51665664b7ea1f Mon Sep 17 00:00:00 2001 From: Stefan Guilhen Date: Tue, 7 May 2024 09:25:50 -0300 Subject: [PATCH] Add description field to OrganizationEntity Closes #29356 Signed-off-by: Stefan Guilhen --- .../idm/OrganizationRepresentation.java | 9 +++++++++ .../models/jpa/entities/OrganizationEntity.java | 11 +++++++++++ .../organization/jpa/OrganizationAdapter.java | 10 ++++++++++ .../main/resources/META-INF/jpa-changelog-25.0.0.xml | 1 + .../java/org/keycloak/models/OrganizationModel.java | 4 ++++ .../admin/resource/OrganizationResource.java | 2 ++ .../organization/admin/OrganizationTest.java | 4 ++++ 7 files changed, 41 insertions(+) diff --git a/core/src/main/java/org/keycloak/representations/idm/OrganizationRepresentation.java b/core/src/main/java/org/keycloak/representations/idm/OrganizationRepresentation.java index f5c5497559..0980f1058f 100644 --- a/core/src/main/java/org/keycloak/representations/idm/OrganizationRepresentation.java +++ b/core/src/main/java/org/keycloak/representations/idm/OrganizationRepresentation.java @@ -29,6 +29,7 @@ public class OrganizationRepresentation { private String id; private String name; private boolean enabled = true; + private String description; private Map> attributes; private Set domains; @@ -56,6 +57,14 @@ public class OrganizationRepresentation { this.enabled = enabled; } + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + } + public Map> getAttributes() { return attributes; } diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/OrganizationEntity.java b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/OrganizationEntity.java index b912a2b835..ec3b11df23 100644 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/entities/OrganizationEntity.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/entities/OrganizationEntity.java @@ -54,6 +54,9 @@ public class OrganizationEntity { @Column(name = "ENABLED") private boolean enabled; + @Column(name = "DESCRIPTION") + private String description; + @Column(name = "REALM_ID") private String realmId; @@ -83,6 +86,14 @@ public class OrganizationEntity { this.enabled = enabled; } + public String getDescription() { + return this.description; + } + + public void setDescription(String description) { + this.description = description; + } + public String getRealmId() { return realmId; } 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 d3698dc8c8..c9a020d61f 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 @@ -86,6 +86,16 @@ public final class OrganizationAdapter implements OrganizationModel, JpaModel> attributes) { if (attributes == null) { diff --git a/model/jpa/src/main/resources/META-INF/jpa-changelog-25.0.0.xml b/model/jpa/src/main/resources/META-INF/jpa-changelog-25.0.0.xml index 2502b16674..59b8160117 100644 --- a/model/jpa/src/main/resources/META-INF/jpa-changelog-25.0.0.xml +++ b/model/jpa/src/main/resources/META-INF/jpa-changelog-25.0.0.xml @@ -95,6 +95,7 @@ + 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 923be2d036..e9c1882cb3 100644 --- a/server-spi/src/main/java/org/keycloak/models/OrganizationModel.java +++ b/server-spi/src/main/java/org/keycloak/models/OrganizationModel.java @@ -38,6 +38,10 @@ public interface OrganizationModel { void setEnabled(boolean enabled); + String getDescription(); + + void setDescription(String description); + Map> getAttributes(); void setAttributes(Map> attributes); 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 bfe80349e2..6bddaa105c 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 @@ -174,6 +174,7 @@ public class OrganizationResource { rep.setId(model.getId()); rep.setName(model.getName()); rep.setEnabled(model.isEnabled()); + rep.setDescription(model.getDescription()); rep.setAttributes(model.getAttributes()); model.getDomains().filter(Objects::nonNull).map(this::toRepresentation) .forEach(rep::addDomain); @@ -195,6 +196,7 @@ public class OrganizationResource { model.setName(rep.getName()); model.setEnabled(rep.isEnabled()); + model.setDescription(rep.getDescription()); model.setAttributes(rep.getAttributes()); model.setDomains(Optional.ofNullable(rep.getDomains()).orElse(Set.of()).stream() .filter(Objects::nonNull) diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/organization/admin/OrganizationTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/organization/admin/OrganizationTest.java index a105e92267..979ad8e196 100755 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/organization/admin/OrganizationTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/organization/admin/OrganizationTest.java @@ -24,6 +24,7 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -56,6 +57,7 @@ public class OrganizationTest extends AbstractOrganizationTest { assertEquals(organizationName, expected.getName()); expected.setName("acme"); expected.setEnabled(false); + expected.setDescription("ACME Corporation Organization"); OrganizationResource organization = testRealm().organizations().get(expected.getId()); @@ -68,6 +70,8 @@ public class OrganizationTest extends AbstractOrganizationTest { assertEquals(expected.getName(), existing.getName()); assertEquals(1, existing.getDomains().size()); assertThat(existing.isEnabled(), is(false)); + assertThat(existing.getDescription(), notNullValue()); + assertThat(expected.getDescription(), is(equalTo(existing.getDescription()))); } @Test