mirror of
https://github.com/keycloak/keycloak.git
synced 2026-05-26 13:50:48 +00:00
fix: merging the platform concept into the application
closes: #46377 Signed-off-by: Steve Hawkins <shawkins@redhat.com>
This commit is contained in:
committed by
Pedro Igor
parent
ccb76d5c21
commit
56c2721186
+2
-2
@@ -28,8 +28,8 @@ import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.KeycloakSessionFactory;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.UserModel;
|
||||
import org.keycloak.platform.Platform;
|
||||
import org.keycloak.representations.idm.RealmRepresentation;
|
||||
import org.keycloak.services.resources.KeycloakApplication;
|
||||
import org.keycloak.util.JsonSerialization;
|
||||
|
||||
/**
|
||||
@@ -49,7 +49,7 @@ public class DirExportProvider extends MultipleStepsExportProvider<DirExportProv
|
||||
private File getRootDirectory() {
|
||||
if (rootDirectory == null) {
|
||||
if (dir == null) {
|
||||
rootDirectory = new File(Platform.getPlatform().getTmpDirectory(), "keycloak-export");
|
||||
rootDirectory = new File(KeycloakApplication.getTmpDirectory(), "keycloak-export");
|
||||
} else {
|
||||
rootDirectory = new File(dir);
|
||||
}
|
||||
|
||||
+2
-2
@@ -34,9 +34,9 @@ import org.keycloak.exportimport.util.ExportImportSessionTask.Mode;
|
||||
import org.keycloak.exportimport.util.ImportUtils;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.KeycloakSessionFactory;
|
||||
import org.keycloak.platform.Platform;
|
||||
import org.keycloak.representations.idm.RealmRepresentation;
|
||||
import org.keycloak.services.ServicesLogger;
|
||||
import org.keycloak.services.resources.KeycloakApplication;
|
||||
import org.keycloak.storage.datastore.DefaultExportImportManager;
|
||||
import org.keycloak.util.JsonSerialization;
|
||||
import org.keycloak.utils.KeycloakSessionUtil;
|
||||
@@ -80,7 +80,7 @@ public class DirImportProvider extends AbstractFileBasedImportProvider {
|
||||
|
||||
private File getRootDirectory() {
|
||||
if (rootDirectory == null) {
|
||||
this.rootDirectory = new File(Platform.getPlatform().getTmpDirectory(), "keycloak-export");
|
||||
this.rootDirectory = new File(KeycloakApplication.getTmpDirectory(), "keycloak-export");
|
||||
if (!this.rootDirectory.exists()) {
|
||||
throw new IllegalStateException("Directory " + this.rootDirectory + " doesn't exist");
|
||||
}
|
||||
|
||||
+2
-4
@@ -24,11 +24,10 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.keycloak.platform.Platform;
|
||||
import org.keycloak.quarkus.runtime.Environment;
|
||||
import org.keycloak.quarkus.runtime.Messages;
|
||||
import org.keycloak.quarkus.runtime.integration.QuarkusPlatform;
|
||||
|
||||
import io.quarkus.runtime.Application;
|
||||
import io.smallrye.config.ConfigValue;
|
||||
import org.jboss.logging.Logger;
|
||||
import picocli.CommandLine;
|
||||
@@ -110,8 +109,7 @@ public final class ExecutionExceptionHandler implements CommandLine.IExecutionEx
|
||||
|
||||
// The "cause" can be null
|
||||
private void logError(PrintWriter errorWriter, String errorMessage, Throwable cause) {
|
||||
QuarkusPlatform platform = (QuarkusPlatform) Platform.getPlatform();
|
||||
if (platform.isStarted()) {
|
||||
if (Application.currentApplication() != null) {
|
||||
// Can delegate to proper logger once the platform is started
|
||||
if (cause == null) {
|
||||
getLogger().error(errorMessage);
|
||||
|
||||
+3
-9
@@ -25,8 +25,8 @@ import java.util.ServiceLoader;
|
||||
|
||||
import org.keycloak.Config;
|
||||
import org.keycloak.compatibility.CompatibilityMetadataProvider;
|
||||
import org.keycloak.config.ConfigProviderFactory;
|
||||
import org.keycloak.quarkus.runtime.cli.PropertyException;
|
||||
import org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProviderFactory;
|
||||
|
||||
import picocli.CommandLine;
|
||||
|
||||
@@ -75,14 +75,8 @@ public abstract class AbstractUpdatesCommand extends AbstractAutoBuildCommand {
|
||||
|
||||
private static void loadConfiguration() {
|
||||
// Initialize config without directly referencing MicroProfileConfigProvider
|
||||
// as that currently causing classloading issue during command creation
|
||||
var configProvider = ServiceLoader.load(ConfigProviderFactory.class)
|
||||
.stream()
|
||||
.findFirst()
|
||||
.map(ServiceLoader.Provider::get)
|
||||
.flatMap(ConfigProviderFactory::create)
|
||||
.orElseThrow(() -> new RuntimeException("Failed to load Keycloak Configuration"));
|
||||
Config.init(configProvider);
|
||||
// as that currently causing classloading issue during command creation - when a provider jar is deleted
|
||||
Config.init(new MicroProfileConfigProviderFactory().create());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-7
@@ -17,16 +17,12 @@
|
||||
|
||||
package org.keycloak.quarkus.runtime.configuration;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.keycloak.Config;
|
||||
import org.keycloak.config.ConfigProviderFactory;
|
||||
|
||||
public class MicroProfileConfigProviderFactory implements ConfigProviderFactory {
|
||||
public class MicroProfileConfigProviderFactory {
|
||||
|
||||
@Override
|
||||
public Optional<Config.ConfigProvider> create() {
|
||||
return Optional.of(new MicroProfileConfigProvider());
|
||||
public Config.ConfigProvider create() {
|
||||
return new MicroProfileConfigProvider();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-93
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* Copyright 2021 Red Hat, Inc. and/or its affiliates
|
||||
* and other contributors as indicated by the @author tags.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.keycloak.quarkus.runtime.integration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.keycloak.platform.PlatformProvider;
|
||||
import org.keycloak.quarkus.runtime.Environment;
|
||||
|
||||
import io.quarkus.runtime.Quarkus;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
public class QuarkusPlatform implements PlatformProvider {
|
||||
|
||||
private static final Logger log = Logger.getLogger(QuarkusPlatform.class);
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "Quarkus";
|
||||
}
|
||||
|
||||
private AtomicBoolean started = new AtomicBoolean(false);
|
||||
private File tmpDir;
|
||||
|
||||
@Override
|
||||
public void exit(Throwable cause) {
|
||||
Quarkus.asyncExit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when Quarkus platform is started
|
||||
*/
|
||||
public void started() {
|
||||
this.started.set(true);
|
||||
}
|
||||
|
||||
public boolean isStarted() {
|
||||
return started.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getTmpDirectory() {
|
||||
if (tmpDir == null) {
|
||||
String dataDir = Environment.getDataDir().orElse(null);
|
||||
|
||||
File tmpDir;
|
||||
if (dataDir == null) {
|
||||
// Should happen just in non-script launch scenarios
|
||||
try {
|
||||
tmpDir = Path.of(System.getProperty("java.io.tmpdir"), "keycloak-quarkus-tmp").toFile();
|
||||
if (tmpDir.exists()) {
|
||||
org.apache.commons.io.FileUtils.deleteDirectory(tmpDir);
|
||||
}
|
||||
if (tmpDir.mkdirs()) {
|
||||
tmpDir.deleteOnExit();
|
||||
}
|
||||
} catch (IOException ioex) {
|
||||
throw new RuntimeException("It was not possible to create temporary directory keycloak-quarkus-tmp", ioex);
|
||||
}
|
||||
} else {
|
||||
tmpDir = new File(dataDir, "tmp");
|
||||
tmpDir.mkdirs();
|
||||
}
|
||||
|
||||
if (tmpDir.isDirectory()) {
|
||||
this.tmpDir = tmpDir;
|
||||
log.debugf("Using server tmp directory: %s", tmpDir.getAbsolutePath());
|
||||
} else {
|
||||
throw new RuntimeException("Temporary directory " + tmpDir.getAbsolutePath() + " does not exist and it was not possible to create it.");
|
||||
}
|
||||
}
|
||||
return tmpDir;
|
||||
}
|
||||
|
||||
}
|
||||
+12
-4
@@ -23,17 +23,17 @@ import jakarta.ws.rs.ApplicationPath;
|
||||
import org.keycloak.config.BootstrapAdminOptions;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.KeycloakSessionFactory;
|
||||
import org.keycloak.platform.Platform;
|
||||
import org.keycloak.quarkus.runtime.Environment;
|
||||
import org.keycloak.quarkus.runtime.configuration.Configuration;
|
||||
import org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProvider;
|
||||
import org.keycloak.quarkus.runtime.configuration.PropertyMappingInterceptor;
|
||||
import org.keycloak.quarkus.runtime.integration.QuarkusKeycloakSessionFactory;
|
||||
import org.keycloak.quarkus.runtime.integration.QuarkusPlatform;
|
||||
import org.keycloak.services.ServicesLogger;
|
||||
import org.keycloak.services.managers.ApplianceBootstrap;
|
||||
import org.keycloak.services.resources.KeycloakApplication;
|
||||
import org.keycloak.utils.StringUtil;
|
||||
|
||||
import io.quarkus.runtime.Quarkus;
|
||||
import io.quarkus.runtime.ShutdownEvent;
|
||||
import io.quarkus.runtime.StartupEvent;
|
||||
import io.smallrye.common.annotation.Blocking;
|
||||
@@ -45,9 +45,17 @@ public class QuarkusKeycloakApplication extends KeycloakApplication {
|
||||
private static final String KEYCLOAK_ADMIN_ENV_VAR = "KEYCLOAK_ADMIN";
|
||||
private static final String KEYCLOAK_ADMIN_PASSWORD_ENV_VAR = "KEYCLOAK_ADMIN_PASSWORD";
|
||||
|
||||
@Override
|
||||
protected String getDataDir() {
|
||||
return Environment.getDataDir().orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void exit(Throwable cause) {
|
||||
Quarkus.asyncExit(1);
|
||||
}
|
||||
|
||||
void onStartupEvent(@Observes StartupEvent event) {
|
||||
QuarkusPlatform platform = (QuarkusPlatform) Platform.getPlatform();
|
||||
platform.started();
|
||||
startup();
|
||||
}
|
||||
|
||||
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
#
|
||||
# Copyright 2019 Red Hat, Inc. and/or its affiliates
|
||||
# and other contributors as indicated by the @author tags.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProviderFactory
|
||||
@@ -32,13 +32,13 @@ import org.keycloak.config.HttpOptions;
|
||||
import org.keycloak.config.LoggingOptions;
|
||||
import org.keycloak.config.Option;
|
||||
import org.keycloak.config.SecurityOptions;
|
||||
import org.keycloak.platform.Platform;
|
||||
import org.keycloak.quarkus.runtime.Environment;
|
||||
import org.keycloak.quarkus.runtime.KeycloakMain;
|
||||
import org.keycloak.quarkus.runtime.cli.Picocli;
|
||||
import org.keycloak.quarkus.runtime.cli.command.AbstractAutoBuildCommand;
|
||||
import org.keycloak.quarkus.runtime.configuration.Configuration;
|
||||
import org.keycloak.quarkus.runtime.configuration.IgnoredArtifacts;
|
||||
import org.keycloak.services.resources.KeycloakApplication;
|
||||
|
||||
import io.quarkus.bootstrap.app.AugmentAction;
|
||||
import io.quarkus.bootstrap.app.CuratedApplication;
|
||||
@@ -114,7 +114,7 @@ public class Keycloak {
|
||||
|
||||
public Keycloak start(List<String> rawArgs) {
|
||||
if (homeDir == null) {
|
||||
homeDir = Platform.getPlatform().getTmpDirectory().toPath();
|
||||
homeDir = KeycloakApplication.createTmpDirectory().toPath();
|
||||
}
|
||||
|
||||
List<String> args = new ArrayList<>(rawArgs);
|
||||
|
||||
+2
-2
@@ -35,7 +35,7 @@ import org.keycloak.quarkus.runtime.cli.command.DryRunMixin;
|
||||
import org.keycloak.quarkus.runtime.cli.command.Start;
|
||||
import org.keycloak.quarkus.runtime.cli.command.StartDev;
|
||||
import org.keycloak.quarkus.runtime.configuration.Configuration;
|
||||
import org.keycloak.quarkus.runtime.integration.QuarkusPlatform;
|
||||
import org.keycloak.services.resources.KeycloakApplication;
|
||||
|
||||
import io.quarkus.deployment.util.FileUtil;
|
||||
import io.quarkus.runtime.configuration.QuarkusConfigFactory;
|
||||
@@ -335,7 +335,7 @@ public class CLITestExtension extends QuarkusMainTestExtension {
|
||||
}
|
||||
} else {
|
||||
// This is for re-creating the H2 database instead of using the default in home
|
||||
setProperty("kc.db-url-path", new QuarkusPlatform().getTmpDirectory().getAbsolutePath());
|
||||
setProperty("kc.db-url-path", KeycloakApplication.createTmpDirectory().getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019 Red Hat, Inc. and/or its affiliates
|
||||
* and other contributors as indicated by the @author tags.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.keycloak.config;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.keycloak.Config;
|
||||
|
||||
public interface ConfigProviderFactory {
|
||||
|
||||
Optional<Config.ConfigProvider> create();
|
||||
|
||||
}
|
||||
+2
-2
@@ -10,9 +10,9 @@ import java.util.Set;
|
||||
import org.keycloak.Config;
|
||||
import org.keycloak.common.Version;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.platform.Platform;
|
||||
import org.keycloak.provider.ProviderConfigProperty;
|
||||
import org.keycloak.provider.ProviderConfigurationBuilder;
|
||||
import org.keycloak.services.resources.KeycloakApplication;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.jboss.logging.Logger;
|
||||
@@ -67,7 +67,7 @@ public class GzipResourceEncodingProviderFactory implements ResourceEncodingProv
|
||||
return cacheDir;
|
||||
}
|
||||
|
||||
File cacheRoot = new File(Platform.getPlatform().getTmpDirectory(), "kc-gzip-cache");
|
||||
File cacheRoot = new File(KeycloakApplication.getTmpDirectory(), "kc-gzip-cache");
|
||||
File cacheDir = new File(cacheRoot, Version.RESOURCES_VERSION);
|
||||
|
||||
if (cacheRoot.isDirectory()) {
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019 Red Hat, Inc. and/or its affiliates
|
||||
* and other contributors as indicated by the @author tags.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.keycloak.platform;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
public class Platform {
|
||||
|
||||
private static PlatformProvider INSTANCE;
|
||||
|
||||
public static PlatformProvider getPlatform() {
|
||||
|
||||
if (INSTANCE == null) {
|
||||
ServiceLoader<PlatformProvider> loader = ServiceLoader.load(PlatformProvider.class, Platform.class.getClassLoader());
|
||||
try {
|
||||
INSTANCE = loader.iterator().next();
|
||||
} catch (NoSuchElementException e) {
|
||||
throw new RuntimeException("No PlatformProvider found");
|
||||
}
|
||||
}
|
||||
|
||||
return INSTANCE;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019 Red Hat, Inc. and/or its affiliates
|
||||
* and other contributors as indicated by the @author tags.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.keycloak.platform;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
||||
public interface PlatformProvider {
|
||||
|
||||
String name();
|
||||
|
||||
default void onStartup(Runnable runnable) {
|
||||
|
||||
}
|
||||
|
||||
default void onShutdown(Runnable runnable) {
|
||||
|
||||
}
|
||||
|
||||
void exit(Throwable cause);
|
||||
|
||||
/**
|
||||
* @return tmp directory specific to target platform. Implementation can make sure to create "tmp" directory in case it does not exists.
|
||||
* The directory should be usually inside the corresponding server directory. In production, it should not be system directory like "/tmp" .
|
||||
*/
|
||||
File getTmpDirectory();
|
||||
|
||||
}
|
||||
@@ -16,17 +16,16 @@
|
||||
*/
|
||||
package org.keycloak.services.resources;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.ServiceLoader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import jakarta.transaction.SystemException;
|
||||
import jakarta.transaction.Transaction;
|
||||
import jakarta.ws.rs.core.Application;
|
||||
|
||||
import org.keycloak.Config;
|
||||
import org.keycloak.common.Profile;
|
||||
import org.keycloak.common.crypto.CryptoIntegration;
|
||||
import org.keycloak.config.ConfigProviderFactory;
|
||||
import org.keycloak.exportimport.ExportImportConfig;
|
||||
import org.keycloak.exportimport.ExportImportManager;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
@@ -36,8 +35,6 @@ import org.keycloak.models.dblock.DBLockManager;
|
||||
import org.keycloak.models.dblock.DBLockProvider;
|
||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||
import org.keycloak.models.utils.PostMigrationEvent;
|
||||
import org.keycloak.platform.Platform;
|
||||
import org.keycloak.platform.PlatformProvider;
|
||||
import org.keycloak.services.managers.ApplianceBootstrap;
|
||||
import org.keycloak.transaction.JtaTransactionManagerLookup;
|
||||
|
||||
@@ -50,26 +47,65 @@ import org.jboss.logging.Logger;
|
||||
*/
|
||||
public abstract class KeycloakApplication extends Application {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(KeycloakApplication.class);
|
||||
private static final String KC_TMPDIR = "kc.io.tmpdir";
|
||||
|
||||
protected final PlatformProvider platform = Platform.getPlatform();
|
||||
private static final Logger logger = Logger.getLogger(KeycloakApplication.class);
|
||||
|
||||
private static KeycloakSessionFactory sessionFactory;
|
||||
|
||||
public KeycloakApplication() {
|
||||
try {
|
||||
|
||||
logger.debugv("PlatformProvider: {0}", platform.getClass().getName());
|
||||
File tmpDir = initTmpDirectory();
|
||||
if (tmpDir.isDirectory()) {
|
||||
logger.debugf("Using server tmp directory: %s", tmpDir.getAbsolutePath());
|
||||
} else {
|
||||
logger.warnf("Temporary directory %s does not exist and it was not possible to create it.", tmpDir.getAbsolutePath());
|
||||
}
|
||||
System.setProperty(KC_TMPDIR, tmpDir.getAbsolutePath());
|
||||
logger.debugv("Application: {0}", this.getClass().getName());
|
||||
loadConfig();
|
||||
|
||||
platform.onStartup(this::startup);
|
||||
platform.onShutdown(this::shutdown);
|
||||
|
||||
} catch (Throwable t) {
|
||||
platform.exit(t);
|
||||
exit(t);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getTmpDirectory() {
|
||||
return System.getProperty(KC_TMPDIR, System.getProperty("java.io.tmpdir"));
|
||||
}
|
||||
|
||||
protected File initTmpDirectory() {
|
||||
String dataDir = getDataDir();
|
||||
|
||||
File tmpDir;
|
||||
if (dataDir == null) {
|
||||
// Should happen just in non-script launch scenarios
|
||||
tmpDir = createTmpDirectory();
|
||||
} else {
|
||||
tmpDir = new File(dataDir, "tmp");
|
||||
tmpDir.mkdirs();
|
||||
}
|
||||
return tmpDir;
|
||||
}
|
||||
|
||||
public static File createTmpDirectory() {
|
||||
try {
|
||||
File tmpDir = Path.of(System.getProperty("java.io.tmpdir"), "server-tmp").toFile();
|
||||
if (tmpDir.exists()) {
|
||||
org.apache.commons.io.FileUtils.deleteDirectory(tmpDir);
|
||||
}
|
||||
if (tmpDir.mkdirs()) {
|
||||
tmpDir.deleteOnExit();
|
||||
}
|
||||
return tmpDir;
|
||||
} catch (IOException ioex) {
|
||||
throw new RuntimeException("It was not possible to create temporary directory keycloak-quarkus-tmp", ioex);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void exit(Throwable t);
|
||||
|
||||
protected abstract String getDataDir();
|
||||
|
||||
protected void startup() {
|
||||
Profile.getInstance().logUnsupportedFeatures();
|
||||
CryptoIntegration.init(KeycloakApplication.class.getClassLoader());
|
||||
@@ -164,19 +200,7 @@ public abstract class KeycloakApplication extends Application {
|
||||
|
||||
protected abstract void createTemporaryAdmin(KeycloakSession session);
|
||||
|
||||
protected void loadConfig() {
|
||||
|
||||
ServiceLoader<ConfigProviderFactory> loader = ServiceLoader.load(ConfigProviderFactory.class, KeycloakApplication.class.getClassLoader());
|
||||
|
||||
try {
|
||||
ConfigProviderFactory factory = loader.iterator().next();
|
||||
logger.debugv("ConfigProvider: {0}", factory.getClass().getName());
|
||||
Config.init(factory.create().orElseThrow(() -> new RuntimeException("Failed to load Keycloak configuration")));
|
||||
} catch (NoSuchElementException e) {
|
||||
throw new RuntimeException("No valid ConfigProvider found");
|
||||
}
|
||||
|
||||
}
|
||||
protected abstract void loadConfig();
|
||||
|
||||
protected abstract KeycloakSessionFactory createSessionFactory();
|
||||
|
||||
|
||||
+2
-4
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.keycloak.testsuite;
|
||||
package org.keycloak.services.resteasy;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -23,7 +23,6 @@ import java.net.URL;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.keycloak.Config;
|
||||
import org.keycloak.config.ConfigProviderFactory;
|
||||
import org.keycloak.services.ServicesLogger;
|
||||
import org.keycloak.util.JsonSerialization;
|
||||
import org.keycloak.utils.JsonConfigProvider;
|
||||
@@ -31,11 +30,10 @@ import org.keycloak.utils.JsonConfigProvider;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
public class JsonConfigProviderFactory implements ConfigProviderFactory {
|
||||
public class JsonConfigProviderFactory {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(JsonConfigProviderFactory.class);
|
||||
|
||||
@Override
|
||||
public Optional<Config.ConfigProvider> create() {
|
||||
|
||||
JsonNode node = null;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.keycloak.testsuite;
|
||||
package org.keycloak.services.resteasy;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
+23
@@ -20,7 +20,9 @@ package org.keycloak.services.resteasy;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.keycloak.Config;
|
||||
import org.keycloak.common.Profile;
|
||||
import org.keycloak.common.profile.PropertiesProfileConfigResolver;
|
||||
import org.keycloak.common.util.MultiSiteUtils;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.KeycloakSessionFactory;
|
||||
@@ -44,6 +46,10 @@ public class ResteasyKeycloakApplication extends KeycloakApplication {
|
||||
protected Set<Class<?>> classes = new HashSet<>();
|
||||
|
||||
public ResteasyKeycloakApplication() {
|
||||
Profile.configure(
|
||||
new PropertiesProfileConfigResolver(System.getProperties()),
|
||||
new PropertiesFileProfileConfigResolver()
|
||||
);
|
||||
classes.add(RealmsResource.class);
|
||||
if (Profile.isFeatureEnabled(Profile.Feature.ADMIN_API)) {
|
||||
classes.add(AdminRoot.class);
|
||||
@@ -66,6 +72,16 @@ public class ResteasyKeycloakApplication extends KeycloakApplication {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDataDir() {
|
||||
return System.getProperty("project.build.directory");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void exit(Throwable cause) {
|
||||
throw new RuntimeException(cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Class<?>> getClasses() {
|
||||
return classes;
|
||||
@@ -88,4 +104,11 @@ public class ResteasyKeycloakApplication extends KeycloakApplication {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadConfig() {
|
||||
Config.init(new JsonConfigProviderFactory().create()
|
||||
.orElseThrow(() -> new RuntimeException("Failed to load Keycloak configuration")));
|
||||
startup();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-2
@@ -1,10 +1,11 @@
|
||||
package org.keycloak.testsuite.theme;
|
||||
|
||||
import org.keycloak.Config;
|
||||
import org.keycloak.platform.Platform;
|
||||
import org.keycloak.provider.EnvironmentDependentProviderFactory;
|
||||
import org.keycloak.theme.ClasspathThemeResourceProviderFactory;
|
||||
|
||||
import io.quarkus.runtime.Application;
|
||||
|
||||
public class TestThemeResourceProvider extends ClasspathThemeResourceProviderFactory implements EnvironmentDependentProviderFactory {
|
||||
|
||||
public TestThemeResourceProvider() {
|
||||
@@ -18,6 +19,6 @@ public class TestThemeResourceProvider extends ClasspathThemeResourceProviderFac
|
||||
*/
|
||||
@Override
|
||||
public boolean isSupported(Config.Scope config) {
|
||||
return Platform.getPlatform().name().equals("Undertow");
|
||||
return Application.currentApplication() == null;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -11,8 +11,8 @@ import java.util.regex.Pattern;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import org.keycloak.common.Version;
|
||||
import org.keycloak.platform.Platform;
|
||||
import org.keycloak.representations.idm.RealmRepresentation;
|
||||
import org.keycloak.services.resources.KeycloakApplication;
|
||||
import org.keycloak.testsuite.AbstractTestRealmKeycloakTest;
|
||||
import org.keycloak.theme.Theme;
|
||||
|
||||
@@ -129,7 +129,7 @@ public class ThemeResourceProviderTest extends AbstractTestRealmKeycloakTest {
|
||||
}
|
||||
|
||||
testingClient.server().run(session -> {
|
||||
String serverTmpDir = Platform.getPlatform().getTmpDirectory().toString();
|
||||
String serverTmpDir = KeycloakApplication.getTmpDirectory().toString();
|
||||
assertTrue(Paths.get(serverTmpDir, "kc-gzip-cache", resourcesVersion, "welcome", "keycloak", "css", "welcome.css.gz").toFile().isFile());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -53,7 +53,6 @@ import org.keycloak.connections.infinispan.InfinispanConnectionProvider;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.KeycloakSessionFactory;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.platform.Platform;
|
||||
import org.keycloak.protocol.ProtocolMapperSpi;
|
||||
import org.keycloak.protocol.oidc.mappers.DeployedScriptOIDCProtocolMapper;
|
||||
import org.keycloak.protocol.saml.mappers.DeployedScriptSAMLProtocolMapper;
|
||||
@@ -323,7 +322,7 @@ public class KeycloakServer {
|
||||
|
||||
// we generate a dynamic jboss.server.data.dir and remove it at the end.
|
||||
try {
|
||||
File tempKeycloakFolder = Platform.getPlatform().getTmpDirectory();
|
||||
String tempKeycloakFolder = KeycloakApplication.getTmpDirectory();
|
||||
File tmpDataDir = new File(tempKeycloakFolder, "/data");
|
||||
|
||||
if (tmpDataDir.mkdirs()) {
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019 Red Hat, Inc. and/or its affiliates
|
||||
* and other contributors as indicated by the @author tags.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.keycloak.testsuite;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
||||
import org.keycloak.common.Profile;
|
||||
import org.keycloak.common.profile.PropertiesProfileConfigResolver;
|
||||
import org.keycloak.platform.PlatformProvider;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
public class TestPlatform implements PlatformProvider {
|
||||
|
||||
private static final Logger log = Logger.getLogger(TestPlatform.class);
|
||||
|
||||
private File tmpDir;
|
||||
|
||||
public TestPlatform() {
|
||||
Profile.configure(
|
||||
new PropertiesProfileConfigResolver(System.getProperties()),
|
||||
new PropertiesFileProfileConfigResolver()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "Undertow";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartup(Runnable startupHook) {
|
||||
startupHook.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShutdown(Runnable shutdownHook) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exit(Throwable cause) {
|
||||
throw new RuntimeException(cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getTmpDirectory() {
|
||||
if (tmpDir == null) {
|
||||
String projectBuildDir = System.getProperty("project.build.directory");
|
||||
File tmpDir;
|
||||
if (projectBuildDir != null) {
|
||||
tmpDir = new File(projectBuildDir, "server-tmp");
|
||||
tmpDir.mkdir();
|
||||
} else {
|
||||
try {
|
||||
tmpDir = Files.createTempDirectory("keycloak-server-").toFile();
|
||||
tmpDir.deleteOnExit();
|
||||
} catch (IOException ioe) {
|
||||
throw new RuntimeException("Could not create temporary directory", ioe);
|
||||
}
|
||||
}
|
||||
|
||||
if (tmpDir.isDirectory()) {
|
||||
this.tmpDir = tmpDir;
|
||||
log.infof("Using server tmp directory: %s", tmpDir.getAbsolutePath());
|
||||
} else {
|
||||
throw new RuntimeException("Directory " + tmpDir + " was not created and does not exists");
|
||||
}
|
||||
}
|
||||
return tmpDir;
|
||||
}
|
||||
|
||||
}
|
||||
-1
@@ -1 +0,0 @@
|
||||
org.keycloak.testsuite.JsonConfigProviderFactory
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
#
|
||||
# Copyright 2019 Red Hat, Inc. and/or its affiliates
|
||||
# and other contributors as indicated by the @author tags.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
org.keycloak.testsuite.TestPlatform
|
||||
Reference in New Issue
Block a user