From a4d9aaf9168189c852d99155b6becb9d0b046772 Mon Sep 17 00:00:00 2001 From: mposolda Date: Fri, 1 Apr 2016 15:49:22 +0200 Subject: [PATCH] KEYCLOAK-2613 Add version to RealmRepresentation in JSON exports --- .../representations/idm/RealmRepresentation.java | 10 ++++++++++ .../keycloak/exportimport/dir/DirExportProvider.java | 8 -------- .../org/keycloak/exportimport/util/ExportUtils.java | 4 ++++ .../exportimport/util/MultipleStepsExportProvider.java | 6 ------ .../testsuite/exportimport/ExportImportTest.java | 8 ++++---- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/org/keycloak/representations/idm/RealmRepresentation.java b/core/src/main/java/org/keycloak/representations/idm/RealmRepresentation.java index 54fa9beeb0..de4bf382e5 100755 --- a/core/src/main/java/org/keycloak/representations/idm/RealmRepresentation.java +++ b/core/src/main/java/org/keycloak/representations/idm/RealmRepresentation.java @@ -121,6 +121,8 @@ public class RealmRepresentation { protected String resetCredentialsFlow; protected String clientAuthenticationFlow; + protected String keycloakVersion; + @Deprecated protected Boolean social; @Deprecated @@ -814,6 +816,14 @@ public class RealmRepresentation { this.clientAuthenticationFlow = clientAuthenticationFlow; } + public String getKeycloakVersion() { + return keycloakVersion; + } + + public void setKeycloakVersion(String keycloakVersion) { + this.keycloakVersion = keycloakVersion; + } + public List getGroups() { return groups; } diff --git a/services/src/main/java/org/keycloak/exportimport/dir/DirExportProvider.java b/services/src/main/java/org/keycloak/exportimport/dir/DirExportProvider.java index dd1972d4d3..906d24628f 100755 --- a/services/src/main/java/org/keycloak/exportimport/dir/DirExportProvider.java +++ b/services/src/main/java/org/keycloak/exportimport/dir/DirExportProvider.java @@ -17,7 +17,6 @@ package org.keycloak.exportimport.dir; -import org.keycloak.representations.VersionRepresentation; import org.keycloak.exportimport.util.ExportUtils; import org.keycloak.exportimport.util.MultipleStepsExportProvider; import org.keycloak.models.KeycloakSession; @@ -86,13 +85,6 @@ public class DirExportProvider extends MultipleStepsExportProvider { ExportUtils.exportUsersToStream(session, realm, users, JsonSerialization.prettyMapper, os); } - @Override - protected void writeVersion(String fileName, VersionRepresentation version) throws IOException { - File file = new File(this.rootDirectory, fileName); - FileOutputStream stream = new FileOutputStream(file); - JsonSerialization.prettyMapper.writeValue(stream, version); - } - @Override public void close() { } diff --git a/services/src/main/java/org/keycloak/exportimport/util/ExportUtils.java b/services/src/main/java/org/keycloak/exportimport/util/ExportUtils.java index bdea6f6369..72cabb5259 100755 --- a/services/src/main/java/org/keycloak/exportimport/util/ExportUtils.java +++ b/services/src/main/java/org/keycloak/exportimport/util/ExportUtils.java @@ -22,6 +22,7 @@ import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; +import org.keycloak.common.Version; import org.keycloak.common.util.Base64; import org.keycloak.models.*; import org.keycloak.models.utils.ModelToRepresentation; @@ -39,6 +40,9 @@ public class ExportUtils { public static RealmRepresentation exportRealm(KeycloakSession session, RealmModel realm, boolean includeUsers) { RealmRepresentation rep = ModelToRepresentation.toRepresentation(realm, true); + // Project/product version + rep.setKeycloakVersion(Version.VERSION); + // Client Templates List templates = realm.getClientTemplates(); List templateReps = new ArrayList<>(); diff --git a/services/src/main/java/org/keycloak/exportimport/util/MultipleStepsExportProvider.java b/services/src/main/java/org/keycloak/exportimport/util/MultipleStepsExportProvider.java index 735659f018..453716986a 100755 --- a/services/src/main/java/org/keycloak/exportimport/util/MultipleStepsExportProvider.java +++ b/services/src/main/java/org/keycloak/exportimport/util/MultipleStepsExportProvider.java @@ -18,7 +18,6 @@ package org.keycloak.exportimport.util; import org.jboss.logging.Logger; -import org.keycloak.representations.VersionRepresentation; import org.keycloak.exportimport.ExportImportConfig; import org.keycloak.exportimport.ExportProvider; import org.keycloak.exportimport.UsersExportStrategy; @@ -57,14 +56,11 @@ public abstract class MultipleStepsExportProvider implements ExportProvider { for (RealmModel realm : holder.realms) { exportRealmImpl(factory, realm.getName()); } - - writeVersion("version.json", VersionRepresentation.SINGLETON); } @Override public void exportRealm(KeycloakSessionFactory factory, String realmName) throws IOException { exportRealmImpl(factory, realmName); - writeVersion("version.json", VersionRepresentation.SINGLETON); } protected void exportRealmImpl(KeycloakSessionFactory factory, final String realmName) throws IOException { @@ -127,8 +123,6 @@ public abstract class MultipleStepsExportProvider implements ExportProvider { protected abstract void writeUsers(String fileName, KeycloakSession session, RealmModel realm, List users) throws IOException; - protected abstract void writeVersion(String fileName, VersionRepresentation version) throws IOException; - public static class RealmsHolder { List realms; diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/exportimport/ExportImportTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/exportimport/ExportImportTest.java index f8f8e1407f..d3ada6e753 100755 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/exportimport/ExportImportTest.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/exportimport/ExportImportTest.java @@ -166,8 +166,8 @@ public class ExportImportTest { testFullExportImport(); - // There should be 6 files in target directory (3 realm, 3 user, 1 version) - Assert.assertEquals(7, new File(targetDirPath).listFiles().length); + // There should be 6 files in target directory (3 realm, 3 user) + Assert.assertEquals(6, new File(targetDirPath).listFiles().length); } @Test @@ -180,9 +180,9 @@ public class ExportImportTest { testRealmExportImport(); - // There should be 3 files in target directory (1 realm, 3 user, 1 version) + // There should be 3 files in target directory (1 realm, 3 user) File[] files = new File(targetDirPath).listFiles(); - Assert.assertEquals(5, files.length); + Assert.assertEquals(4, files.length); } @Test