Read cache-ispn.xml from conf/ by default

Fixed #31492

Signed-off-by: Pedro Ruivo <pruivo@redhat.com>
Signed-off-by: Alexander Schwartz <aschwart@redhat.com>
Co-authored-by: Alexander Schwartz <aschwart@redhat.com>
This commit is contained in:
Pedro Ruivo 2024-10-09 17:40:17 +01:00 committed by GitHub
parent ff44d8dd98
commit 0e3554934e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 40 additions and 36 deletions

View file

@ -0,0 +1,5 @@
= Infinispan default XML configuration location
Previous releases ignored any change to `conf/cache-ispn.xml` if the `--cache-config-file` option was not provided.
Starting from this release, when `--cache-config-file` is not set, the default Infinispan XML configuration file is `conf/cache-ispn.xml` as this is both the expected behavior and the implied behavior given the docs of the current and previous releases.

View file

@ -1,6 +1,10 @@
[[migration-changes]]
== Migration Changes
=== Migrating to 26.1.0
include::changes-26_1_0.adoc[leveloffset=3]
=== Migrating to 26.0.0
include::changes-26_0_0.adoc[leveloffset=3]

View file

@ -31,6 +31,7 @@ import liquibase.Scope;
import liquibase.servicelocator.ServiceLocator;
import org.hibernate.cfg.AvailableSettings;
import org.infinispan.commons.util.FileLookupFactory;
import org.jboss.logging.Logger;
import org.keycloak.Config;
import org.keycloak.common.Profile;
import org.keycloak.common.crypto.CryptoIntegration;
@ -72,6 +73,8 @@ public class KeycloakRecorder {
public static final String DEFAULT_HEALTH_ENDPOINT = "/health";
public static final String DEFAULT_METRICS_ENDPOINT = "/metrics";
private static final Logger logger = Logger.getLogger(KeycloakRecorder.class);
public void initConfig() {
Config.init(new MicroProfileConfigProvider());
}
@ -135,30 +138,32 @@ public class KeycloakRecorder {
private String getInfinispanConfigFile() {
String configFile = getKcConfigValue("spi-connections-infinispan-quarkus-config-file").getValue();
if (configFile != null) {
Path configPath = Paths.get(configFile);
String path;
if (configPath.toFile().exists()) {
path = configPath.toFile().getAbsolutePath();
} else {
path = configPath.getFileName().toString();
}
InputStream url = FileLookupFactory.newInstance().lookupFile(path, KeycloakRecorder.class.getClassLoader());
if (url == null) {
throw new IllegalArgumentException("Could not load cluster configuration file at [" + configPath + "]");
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url))) {
return reader.lines().collect(Collectors.joining("\n"));
} catch (Exception cause) {
throw new RuntimeException("Failed to read clustering configuration from [" + url + "]", cause);
}
} else {
if (configFile == null) {
throw new IllegalArgumentException("Option 'configFile' needs to be specified");
}
Path configPath = Paths.get(configFile);
String path;
if (configPath.toFile().exists()) {
path = configPath.toFile().getAbsolutePath();
} else {
path = configPath.getFileName().toString();
}
logger.debugf("Infinispan configuration file: %s", path);
InputStream url = FileLookupFactory.newInstance().lookupFile(path, KeycloakRecorder.class.getClassLoader());
if (url == null) {
throw new IllegalArgumentException("Could not load cluster configuration file at [" + configPath + "]");
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url))) {
return reader.lines().collect(Collectors.joining("\n"));
} catch (Exception cause) {
throw new RuntimeException("Failed to read clustering configuration from [" + url + "]", cause);
}
}
public void setDefaultUserProfileConfiguration(UPConfig configuration) {

View file

@ -6,15 +6,10 @@ import static org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper.
import java.io.File;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.function.BooleanSupplier;
import java.util.stream.Stream;
import org.keycloak.config.CachingOptions;
import org.keycloak.config.OptionBuilder;
import org.keycloak.config.OptionCategory;
import org.keycloak.infinispan.util.InfinispanUtils;
import org.keycloak.quarkus.runtime.Environment;
@ -41,7 +36,7 @@ final class CachingPropertyMappers {
if (CachingOptions.Mechanism.local.name().equals(value)) {
return "cache-local.xml";
} else if (CachingOptions.Mechanism.ispn.name().equals(value)) {
return "cache-ispn.xml";
return resolveConfigFile("cache-ispn.xml", null);
} else
return null;
})
@ -107,16 +102,11 @@ final class CachingPropertyMappers {
}
private static String resolveConfigFile(String value, ConfigSourceInterceptorContext context) {
String pathPrefix;
String homeDir = Environment.getHomeDir();
if (homeDir == null) {
pathPrefix = "";
} else {
pathPrefix = homeDir + File.separator + "conf" + File.separator;
}
return pathPrefix + value;
return homeDir == null ?
value :
homeDir + File.separator + "conf" + File.separator + value;
}
private static String getDefaultKeystorePathValue() {