fix: providing a separate session for each file (#34210)
closes: #34095 Signed-off-by: Steve Hawkins <shawkins@redhat.com>
This commit is contained in:
parent
cef0231bf0
commit
bd499755a2
2 changed files with 32 additions and 3 deletions
|
@ -17,7 +17,9 @@
|
||||||
|
|
||||||
package org.keycloak.it.cli.dist;
|
package org.keycloak.it.cli.dist;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -30,6 +32,9 @@ import org.keycloak.it.junit5.extension.RawDistOnly;
|
||||||
import org.keycloak.it.utils.KeycloakDistribution;
|
import org.keycloak.it.utils.KeycloakDistribution;
|
||||||
import org.keycloak.it.utils.RawKeycloakDistribution;
|
import org.keycloak.it.utils.RawKeycloakDistribution;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
|
||||||
import io.quarkus.deployment.util.FileUtil;
|
import io.quarkus.deployment.util.FileUtil;
|
||||||
import io.quarkus.test.junit.main.Launch;
|
import io.quarkus.test.junit.main.Launch;
|
||||||
import io.quarkus.test.junit.main.LaunchResult;
|
import io.quarkus.test.junit.main.LaunchResult;
|
||||||
|
@ -45,6 +50,21 @@ public class ImportAtStartupDistTest {
|
||||||
CLIResult cliResult = (CLIResult) result;
|
CLIResult cliResult = (CLIResult) result;
|
||||||
cliResult.assertMessage("Realm 'quickstart-realm' imported");
|
cliResult.assertMessage("Realm 'quickstart-realm' imported");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@BeforeStartDistribution(CreateRealmConfigurationFile.class)
|
||||||
|
void testMultipleImport(KeycloakDistribution dist) throws IOException {
|
||||||
|
RawKeycloakDistribution rawDist = dist.unwrap(RawKeycloakDistribution.class);
|
||||||
|
Path dir = rawDist.getDistPath().resolve("data").resolve("import");
|
||||||
|
|
||||||
|
// add another realm
|
||||||
|
Files.write(dir.resolve("realm2.json"), Files.readAllLines(dir.resolve("realm.json")).stream()
|
||||||
|
.map(s -> s.replace("quickstart-realm", "other-realm")).toList());
|
||||||
|
|
||||||
|
CLIResult cliResult = dist.run("start-dev", "--import-realm");
|
||||||
|
cliResult.assertMessage("Realm 'quickstart-realm' imported");
|
||||||
|
cliResult.assertMessage("Realm 'other-realm' imported");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@BeforeStartDistribution(CreateRealmConfigurationFileAndDir.class)
|
@BeforeStartDistribution(CreateRealmConfigurationFileAndDir.class)
|
||||||
|
@ -115,7 +135,7 @@ public class ImportAtStartupDistTest {
|
||||||
result.assertMessage("Realm 'quickstart-realm' imported");
|
result.assertMessage("Realm 'quickstart-realm' imported");
|
||||||
result.assertNoMessage("Not importing realm master from file");
|
result.assertNoMessage("Not importing realm master from file");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CreateRealmConfigurationFile implements Consumer<KeycloakDistribution> {
|
public static class CreateRealmConfigurationFile implements Consumer<KeycloakDistribution> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -170,8 +170,17 @@ public class ExportImportManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
return filesToImport.stream().map(file -> () -> {
|
return filesToImport.stream().map(file -> () -> {
|
||||||
ExportImportConfig.setFile(file);
|
// we need a new session to pickup the static system property
|
||||||
return session.getProvider(ImportProvider.class, providerId);
|
// file setting - it is picked up by the provider only at create time
|
||||||
|
// this will eventually need to be consolidated with the master existance check
|
||||||
|
// to prevent double parsing
|
||||||
|
KeycloakSession newSession = session.getKeycloakSessionFactory().create();
|
||||||
|
try {
|
||||||
|
ExportImportConfig.setFile(file);
|
||||||
|
return newSession.getProvider(ImportProvider.class, providerId);
|
||||||
|
} finally {
|
||||||
|
newSession.close();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return Stream.empty();
|
return Stream.empty();
|
||||||
|
|
Loading…
Reference in a new issue