parent
3b65f1163d
commit
3161c4424c
4 changed files with 37 additions and 19 deletions
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
package org.keycloak.exportimport;
|
package org.keycloak.exportimport;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||||
*/
|
*/
|
||||||
|
@ -58,8 +60,9 @@ public class ExportImportConfig {
|
||||||
return System.getProperty(ACTION);
|
return System.getProperty(ACTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setAction(String exportImportAction) {
|
public static Closeable setAction(String exportImportAction) {
|
||||||
System.setProperty(ACTION, exportImportAction);
|
System.setProperty(ACTION, exportImportAction);
|
||||||
|
return () -> System.getProperties().remove(ACTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setProvider(String exportImportProvider) {
|
public static void setProvider(String exportImportProvider) {
|
||||||
|
|
|
@ -19,6 +19,7 @@ import org.keycloak.testsuite.client.KeycloakTestingClient;
|
||||||
import org.keycloak.testsuite.federation.UserMapStorageFactory;
|
import org.keycloak.testsuite.federation.UserMapStorageFactory;
|
||||||
import org.keycloak.testsuite.util.RealmBuilder;
|
import org.keycloak.testsuite.util.RealmBuilder;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
import javax.ws.rs.NotFoundException;
|
import javax.ws.rs.NotFoundException;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -123,8 +124,9 @@ public class ComponentExportImportTest extends AbstractAuthTest {
|
||||||
ExportImportConfig.setProvider(SingleFileExportProviderFactory.PROVIDER_ID);
|
ExportImportConfig.setProvider(SingleFileExportProviderFactory.PROVIDER_ID);
|
||||||
ExportImportConfig.setFile(exportFilePath);
|
ExportImportConfig.setFile(exportFilePath);
|
||||||
ExportImportConfig.setRealmName(REALM_NAME);
|
ExportImportConfig.setRealmName(REALM_NAME);
|
||||||
ExportImportConfig.setAction(ExportImportConfig.ACTION_EXPORT);
|
try (Closeable c = ExportImportConfig.setAction(ExportImportConfig.ACTION_EXPORT)) {
|
||||||
new ExportImportManager(session).runExport();
|
new ExportImportManager(session).runExport();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
testRealmResource().remove();
|
testRealmResource().remove();
|
||||||
|
@ -139,8 +141,9 @@ public class ComponentExportImportTest extends AbstractAuthTest {
|
||||||
// import
|
// import
|
||||||
testingClient.server().run(session -> {
|
testingClient.server().run(session -> {
|
||||||
Assert.assertNull(session.realms().getRealmByName(REALM_NAME));
|
Assert.assertNull(session.realms().getRealmByName(REALM_NAME));
|
||||||
ExportImportConfig.setAction(ExportImportConfig.ACTION_IMPORT);
|
try (Closeable c = ExportImportConfig.setAction(ExportImportConfig.ACTION_IMPORT)) {
|
||||||
new ExportImportManager(session).runImport();
|
new ExportImportManager(session).runImport();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Assert realm was imported
|
// Assert realm was imported
|
||||||
|
|
|
@ -39,6 +39,7 @@ import org.keycloak.services.managers.RealmManager;
|
||||||
import org.keycloak.storage.UserStorageUtil;
|
import org.keycloak.storage.UserStorageUtil;
|
||||||
import org.keycloak.testsuite.AbstractAuthTest;
|
import org.keycloak.testsuite.AbstractAuthTest;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
import javax.ws.rs.NotFoundException;
|
import javax.ws.rs.NotFoundException;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
@ -125,15 +126,17 @@ public class FederatedStorageExportImportTest extends AbstractAuthTest {
|
||||||
ExportImportConfig.setProvider(SingleFileExportProviderFactory.PROVIDER_ID);
|
ExportImportConfig.setProvider(SingleFileExportProviderFactory.PROVIDER_ID);
|
||||||
ExportImportConfig.setFile(exportFileAbsolutePath);
|
ExportImportConfig.setFile(exportFileAbsolutePath);
|
||||||
ExportImportConfig.setRealmName(REALM_NAME);
|
ExportImportConfig.setRealmName(REALM_NAME);
|
||||||
ExportImportConfig.setAction(ExportImportConfig.ACTION_EXPORT);
|
try (Closeable c = ExportImportConfig.setAction(ExportImportConfig.ACTION_EXPORT)) {
|
||||||
new ExportImportManager(session).runExport();
|
new ExportImportManager(session).runExport();
|
||||||
|
}
|
||||||
session.realms().removeRealm(realmId);
|
session.realms().removeRealm(realmId);
|
||||||
});
|
});
|
||||||
|
|
||||||
testingClient.server().run(session -> {
|
testingClient.server().run(session -> {
|
||||||
Assert.assertNull(session.realms().getRealmByName(REALM_NAME));
|
Assert.assertNull(session.realms().getRealmByName(REALM_NAME));
|
||||||
ExportImportConfig.setAction(ExportImportConfig.ACTION_IMPORT);
|
try (Closeable c = ExportImportConfig.setAction(ExportImportConfig.ACTION_IMPORT)) {
|
||||||
new ExportImportManager(session).runImport();
|
new ExportImportManager(session).runImport();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
testingClient.server().run(session -> {
|
testingClient.server().run(session -> {
|
||||||
|
@ -193,16 +196,18 @@ public class FederatedStorageExportImportTest extends AbstractAuthTest {
|
||||||
ExportImportConfig.setProvider(DirExportProviderFactory.PROVIDER_ID);
|
ExportImportConfig.setProvider(DirExportProviderFactory.PROVIDER_ID);
|
||||||
ExportImportConfig.setDir(exportDirAbsolutePath);
|
ExportImportConfig.setDir(exportDirAbsolutePath);
|
||||||
ExportImportConfig.setRealmName(REALM_NAME);
|
ExportImportConfig.setRealmName(REALM_NAME);
|
||||||
ExportImportConfig.setAction(ExportImportConfig.ACTION_EXPORT);
|
try (Closeable c = ExportImportConfig.setAction(ExportImportConfig.ACTION_EXPORT)) {
|
||||||
new ExportImportManager(session).runExport();
|
new ExportImportManager(session).runExport();
|
||||||
|
}
|
||||||
session.realms().removeRealm(realmId);
|
session.realms().removeRealm(realmId);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
testingClient.server().run(session -> {
|
testingClient.server().run(session -> {
|
||||||
Assert.assertNull(session.realms().getRealmByName(REALM_NAME));
|
Assert.assertNull(session.realms().getRealmByName(REALM_NAME));
|
||||||
ExportImportConfig.setAction(ExportImportConfig.ACTION_IMPORT);
|
try (Closeable c = ExportImportConfig.setAction(ExportImportConfig.ACTION_IMPORT)) {
|
||||||
new ExportImportManager(session).runImport();
|
new ExportImportManager(session).runImport();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
testingClient.server().run(session -> {
|
testingClient.server().run(session -> {
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.keycloak.models.RoleModel;
|
||||||
import org.keycloak.testsuite.model.KeycloakModelTest;
|
import org.keycloak.testsuite.model.KeycloakModelTest;
|
||||||
import org.keycloak.testsuite.model.RequireProvider;
|
import org.keycloak.testsuite.model.RequireProvider;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
@ -77,9 +78,12 @@ public class ExportModelTest extends KeycloakModelTest {
|
||||||
.config(SingleFileExportProviderFactory.REALM_NAME, REALM_NAME);
|
.config(SingleFileExportProviderFactory.REALM_NAME, REALM_NAME);
|
||||||
|
|
||||||
inComittedTransaction(session -> {
|
inComittedTransaction(session -> {
|
||||||
ExportImportConfig.setAction(ExportImportConfig.ACTION_EXPORT);
|
try (Closeable c = ExportImportConfig.setAction(ExportImportConfig.ACTION_EXPORT)) {
|
||||||
ExportImportManager exportImportManager = new ExportImportManager(session);
|
ExportImportManager exportImportManager = new ExportImportManager(session);
|
||||||
exportImportManager.runExport();
|
exportImportManager.runExport();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
log.error(ex.getMessage(), ex);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// file will exist if export was successful
|
// file will exist if export was successful
|
||||||
|
@ -112,9 +116,12 @@ public class ExportModelTest extends KeycloakModelTest {
|
||||||
.config(DirExportProviderFactory.REALM_NAME, REALM_NAME);
|
.config(DirExportProviderFactory.REALM_NAME, REALM_NAME);
|
||||||
|
|
||||||
inComittedTransaction(session -> {
|
inComittedTransaction(session -> {
|
||||||
ExportImportConfig.setAction(ExportImportConfig.ACTION_EXPORT);
|
try (Closeable c = ExportImportConfig.setAction(ExportImportConfig.ACTION_EXPORT)) {
|
||||||
ExportImportManager exportImportManager = new ExportImportManager(session);
|
ExportImportManager exportImportManager = new ExportImportManager(session);
|
||||||
exportImportManager.runExport();
|
exportImportManager.runExport();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
log.error(ex.getMessage(), ex);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// file will exist if export was successful
|
// file will exist if export was successful
|
||||||
|
|
Loading…
Reference in a new issue