From ce38c5b1356002abdd044e2e90bfe29199257df8 Mon Sep 17 00:00:00 2001 From: Steve Hawkins Date: Mon, 18 May 2026 09:54:10 -0400 Subject: [PATCH] fix: making the embedded resteasy server work again closes: #49058 Signed-off-by: Steve Hawkins --- .../org.keycloak.platform.PlatformProvider | 18 ------------- .../resteasy/ResteasyKeycloakApplication.java | 12 ++++----- testsuite/utils/pom.xml | 5 ---- .../keycloak/testsuite/KeycloakServer.java | 26 +++++++++++++++++-- 4 files changed, 30 insertions(+), 31 deletions(-) delete mode 100644 quarkus/runtime/src/main/resources/META-INF/services/org.keycloak.platform.PlatformProvider diff --git a/quarkus/runtime/src/main/resources/META-INF/services/org.keycloak.platform.PlatformProvider b/quarkus/runtime/src/main/resources/META-INF/services/org.keycloak.platform.PlatformProvider deleted file mode 100644 index ed631b757ee..00000000000 --- a/quarkus/runtime/src/main/resources/META-INF/services/org.keycloak.platform.PlatformProvider +++ /dev/null @@ -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 diff --git a/services/src/test/java/org/keycloak/services/resteasy/ResteasyKeycloakApplication.java b/services/src/test/java/org/keycloak/services/resteasy/ResteasyKeycloakApplication.java index 9c976673308..bd6d94af7b3 100644 --- a/services/src/test/java/org/keycloak/services/resteasy/ResteasyKeycloakApplication.java +++ b/services/src/test/java/org/keycloak/services/resteasy/ResteasyKeycloakApplication.java @@ -48,6 +48,12 @@ public class ResteasyKeycloakApplication extends KeycloakApplication { protected Set> 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(); } diff --git a/testsuite/utils/pom.xml b/testsuite/utils/pom.xml index 89ccd96a12a..d93f63ced82 100755 --- a/testsuite/utils/pom.xml +++ b/testsuite/utils/pom.xml @@ -268,11 +268,6 @@ ${mssql-jdbc.version} - - org.keycloak - keycloak-junit5 - - io.quarkus quarkus-micrometer diff --git a/testsuite/utils/src/main/java/org/keycloak/testsuite/KeycloakServer.java b/testsuite/utils/src/main/java/org/keycloak/testsuite/KeycloakServer.java index 32e9338bf45..95bc0e62a42 100755 --- a/testsuite/utils/src/main/java/org/keycloak/testsuite/KeycloakServer.java +++ b/testsuite/utils/src/main/java/org/keycloak/testsuite/KeycloakServer.java @@ -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;