From 27b291c3456c8afc8290aeb23769c635b3f85777 Mon Sep 17 00:00:00 2001 From: Marko Strukelj Date: Tue, 16 May 2017 18:52:58 +0200 Subject: [PATCH] RHSSO-978 Cannot migrate event types using export/import --- .../models/utils/RepresentationToModel.java | 2 ++ .../exportimport/ExportImportTest.java | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+) 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 1c90b0f00c..5d0ca57051 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 @@ -151,6 +151,8 @@ public class RepresentationToModel { if (rep.getMaxDeltaTimeSeconds() != null) newRealm.setMaxDeltaTimeSeconds(rep.getMaxDeltaTimeSeconds()); if (rep.getFailureFactor() != null) newRealm.setFailureFactor(rep.getFailureFactor()); if (rep.isEventsEnabled() != null) newRealm.setEventsEnabled(rep.isEventsEnabled()); + if (rep.getEnabledEventTypes() != null) + newRealm.setEnabledEventTypes(new HashSet<>(rep.getEnabledEventTypes())); if (rep.getEventsExpiration() != null) newRealm.setEventsExpiration(rep.getEventsExpiration()); if (rep.getEventsListeners() != null) newRealm.setEventsListeners(new HashSet<>(rep.getEventsListeners())); if (rep.isAdminEventsEnabled() != null) newRealm.setAdminEventsEnabled(rep.isAdminEventsEnabled()); diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/exportimport/ExportImportTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/exportimport/ExportImportTest.java index ae3a4a9f00..c130cfd037 100755 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/exportimport/ExportImportTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/exportimport/ExportImportTest.java @@ -27,6 +27,7 @@ import org.keycloak.exportimport.dir.DirExportProviderFactory; import org.keycloak.exportimport.singlefile.SingleFileExportProviderFactory; import org.keycloak.representations.idm.ComponentRepresentation; import org.keycloak.representations.idm.KeysMetadataRepresentation; +import org.keycloak.representations.idm.RealmEventsConfigRepresentation; import org.keycloak.representations.idm.RealmRepresentation; import org.keycloak.representations.idm.UserRepresentation; import org.keycloak.testsuite.AbstractKeycloakTest; @@ -35,6 +36,7 @@ import org.keycloak.testsuite.util.UserBuilder; import java.io.File; import java.net.URL; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -58,6 +60,8 @@ public class ExportImportTest extends AbstractKeycloakTest { testRealm1.getUsers().add(makeUser("user1")); testRealm1.getUsers().add(makeUser("user2")); testRealm1.getUsers().add(makeUser("user3")); + + setEventsConfig(testRealm1); testRealms.add(testRealm1); RealmRepresentation testRealm2 = loadJson(getClass().getResourceAsStream("/model/testrealm.json"), RealmRepresentation.class); @@ -65,6 +69,22 @@ public class ExportImportTest extends AbstractKeycloakTest { testRealms.add(testRealm2); } + private void setEventsConfig(RealmRepresentation realm) { + realm.setEventsEnabled(true); + realm.setAdminEventsEnabled(true); + realm.setAdminEventsDetailsEnabled(true); + realm.setEventsExpiration(600); + realm.setEnabledEventTypes(Arrays.asList("REGISTER", "REGISTER_ERROR", "LOGIN", "LOGIN_ERROR", "LOGOUT_ERROR")); + } + + private void checkEventsConfig(RealmEventsConfigRepresentation config) { + Assert.assertTrue(config.isEventsEnabled()); + Assert.assertTrue(config.isAdminEventsEnabled()); + Assert.assertTrue(config.isAdminEventsDetailsEnabled()); + Assert.assertEquals((Long) 600L, config.getEventsExpiration()); + Assert.assertNames(new HashSet(config.getEnabledEventTypes()),"REGISTER", "REGISTER_ERROR", "LOGIN", "LOGIN_ERROR", "LOGOUT_ERROR"); + } + private UserRepresentation makeUser(String userName) { return UserBuilder.create() .username(userName) @@ -222,6 +242,8 @@ public class ExportImportTest extends AbstractKeycloakTest { String importedSampleClientRoleId = adminClient.realm("test").clients().get(testAppId).roles().get("sample-client-role").toRepresentation().getId(); assertEquals(sampleClientRoleId, importedSampleClientRoleId); + + checkEventsConfig(adminClient.realm("test").getRealmEventsConfig()); } private void assertAuthenticated(String realmName, String username, String password) {