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 e3e3557704..2fc5136414 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 @@ -1727,6 +1727,7 @@ public class RepresentationToModel { public static ComponentModel toModel(KeycloakSession session, ComponentRepresentation rep) { ComponentModel model = new ComponentModel(); + model.setId(rep.getId()); model.setParentId(rep.getParentId()); model.setProviderType(rep.getProviderType()); model.setProviderId(rep.getProviderId()); 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 6902dacce3..16a6ff3ae8 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 @@ -98,6 +98,26 @@ public class ComponentsTest extends AbstractAdminTest { assertTrue(returned.getConfig().containsKey("required")); } + @Test + public void testCreateWithoutGivenId() { + ComponentRepresentation rep = createComponentRepresentation("mycomponent"); + rep.getConfig().addFirst("required", "foo"); + rep.setId(null); + + String id = createComponent(rep); + assertNotNull(id); + } + + @Test + public void testCreateWithGivenId() { + ComponentRepresentation rep = createComponentRepresentation("mycomponent"); + rep.getConfig().addFirst("required", "foo"); + rep.setId("fixed-id"); + + String id = createComponent(rep); + assertEquals("fixed-id", id); + } + @Test public void testUpdate() { ComponentRepresentation rep = createComponentRepresentation("mycomponent");