From 4d640921191ac1cd2c81de7d7a4ba02b09a1efcf Mon Sep 17 00:00:00 2001 From: StephanSchrader Date: Wed, 7 Aug 2024 14:40:30 +0200 Subject: [PATCH] Fix persist config values for custom components (#31862) Closes #31858 Signed-off-by: Stephan Schrader Signed-off-by: Stephan Schrader Co-authored-by: Stephan Schrader --- .../org/keycloak/models/utils/RepresentationToModel.java | 2 +- .../org/keycloak/testsuite/admin/ComponentsTest.java | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/server-spi-private/src/main/java/org/keycloak/models/utils/RepresentationToModel.java b/server-spi-private/src/main/java/org/keycloak/models/utils/RepresentationToModel.java index 154f8d73b8..f58cec0dcf 100755 --- a/server-spi-private/src/main/java/org/keycloak/models/utils/RepresentationToModel.java +++ b/server-spi-private/src/main/java/org/keycloak/models/utils/RepresentationToModel.java @@ -1058,7 +1058,7 @@ public class RepresentationToModel { Set keys = new HashSet<>(rep.getConfig().keySet()); for (String k : keys) { if (!internal && !providerConfiguration.containsKey(k)) { - break; + continue; } List values = rep.getConfig().get(k); diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/ComponentsTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/ComponentsTest.java index f8b140d71f..e9f86b69a7 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/ComponentsTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/ComponentsTest.java @@ -93,7 +93,7 @@ public class ComponentsTest extends AbstractAdminTest { public void testConcurrencyWithoutChildren() throws InterruptedException { testConcurrency((s, i) -> s.submit(new CreateAndDeleteComponent(s, i))); -// Data consistency is not guaranteed with concurrent access to entities in map store. +// Data consistency is not guaranteed with concurrent access to entities in map store. // For details see https://issues.redhat.com/browse/KEYCLOAK-17586 // The reason that this test remains here is to test whether it finishes in time (we need to test whether there is no slowness). // assertThat(realm.components().query(realm.toRepresentation().getId(), TestProvider.class.getName()), Matchers.hasSize(0)); @@ -103,7 +103,7 @@ public class ComponentsTest extends AbstractAdminTest { public void testConcurrencyWithChildren() throws InterruptedException { testConcurrency((s, i) -> s.submit(new CreateAndDeleteComponentWithFlatChildren(s, i))); -// Data consistency is not guaranteed with concurrent access to entities in map store. +// Data consistency is not guaranteed with concurrent access to entities in map store. // For details see https://issues.redhat.com/browse/KEYCLOAK-17586 // The reason that this test remains here is to test whether it finishes in time (we need to test whether there is no slowness). // assertThat(realm.components().query(realm.toRepresentation().getId(), TestProvider.class.getName()), Matchers.hasSize(0)); @@ -229,6 +229,9 @@ public class ComponentsTest extends AbstractAdminTest { // Check value updated returned.getConfig().putSingle("val1", "one-updated"); + // send a key / value which not contained in the original component config + returned.getConfig().putSingle("not-a-config-key", "ten"); + // Check null deletes property returned.getConfig().putSingle("val2", null); @@ -442,7 +445,7 @@ public class ComponentsTest extends AbstractAdminTest { ComponentRepresentation rep = createComponentRepresentation("test-" + i); rep.getConfig().putSingle("required", "required-value"); rep.setParentId(this.realm.toRepresentation().getId()); - + String id = createComponent(this.realm, rep); assertThat(id, Matchers.notNullValue());