fix: making the embedded resteasy server work again

closes: #49058

Signed-off-by: Steve Hawkins <shawkins@redhat.com>
This commit is contained in:
Steve Hawkins
2026-05-18 09:54:10 -04:00
committed by Marek Posolda
parent f9e275318c
commit ce38c5b135
4 changed files with 30 additions and 31 deletions
@@ -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.integration.QuarkusPlatform
@@ -48,6 +48,12 @@ public class ResteasyKeycloakApplication extends KeycloakApplication {
protected Set<Class<?>> classes = new HashSet<>();
public ResteasyKeycloakApplication() {
Config.init(new JsonConfigProviderFactory().create()
.orElseThrow(() -> new RuntimeException("Failed to load Keycloak configuration")));
Profile.configure(
new PropertiesProfileConfigResolver(System.getProperties()),
new PropertiesFileProfileConfigResolver()
);
classes.add(RealmsResource.class);
if (Profile.isFeatureEnabled(Profile.Feature.ADMIN_API)) {
classes.add(AdminRoot.class);
@@ -68,12 +74,6 @@ public class ResteasyKeycloakApplication extends KeycloakApplication {
// an endpoint for the load balancer to gather information whether this site should receive requests or not.
classes.add(LoadBalancerResource.class);
}
Config.init(new JsonConfigProviderFactory().create()
.orElseThrow(() -> new RuntimeException("Failed to load Keycloak configuration")));
Profile.configure(
new PropertiesProfileConfigResolver(System.getProperties()),
new PropertiesFileProfileConfigResolver()
);
startup();
}
-5
View File
@@ -268,11 +268,6 @@
<version>${mssql-jdbc.version}</version>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-junit5</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-micrometer</artifactId>
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.KeyStore;
import java.text.SimpleDateFormat;
@@ -41,7 +42,6 @@ import javax.net.ssl.TrustManagerFactory;
import jakarta.servlet.DispatcherType;
import jakarta.servlet.Filter;
import org.keycloak.Keycloak;
import org.keycloak.authentication.AuthenticatorSpi;
import org.keycloak.authentication.authenticators.browser.DeployedScriptAuthenticatorFactory;
import org.keycloak.authorization.policy.provider.PolicySpi;
@@ -77,6 +77,7 @@ import io.undertow.servlet.api.DefaultServletConfig;
import io.undertow.servlet.api.DeploymentInfo;
import io.undertow.servlet.api.FilterInfo;
import io.undertow.servlet.api.InstanceHandle;
import org.apache.commons.io.FileUtils;
import org.jboss.logging.Logger;
import org.jboss.resteasy.core.ResteasyDeploymentImpl;
import org.jboss.resteasy.plugins.server.servlet.ResteasyContextParameters;
@@ -320,7 +321,28 @@ public class KeycloakServer {
}
// we generate a dynamic jboss.server.data.dir and remove it at the end.
return Keycloak.initTempDirectory("keycloak-data").toFile().getAbsolutePath();
return initTempDirectory("keycloak-data").toFile().getAbsolutePath();
}
public static Path initTempDirectory(String name) {
String buildDir = System.getProperty("project.build.directory");
if (buildDir == null) {
try {
Path tempDirectory = Files.createTempDirectory(name);
tempDirectory.toFile().deleteOnExit();
return tempDirectory.toAbsolutePath();
} catch (IOException e) {
throw new RuntimeException("Could not create temporary directory", e);
}
} else {
Path tempDirectory = Path.of(buildDir, name);
try {
FileUtils.deleteDirectory(tempDirectory.toFile());
} catch (IOException e) {
e.printStackTrace();
}
return tempDirectory;
}
}
private KeycloakServerConfig config;