KEYCLOAK-15631 Disable clustering for 'dev' profile. Remove cluster.xml file from quarkus distribution packaging
This commit is contained in:
parent
12576e339d
commit
10859ebfc3
11 changed files with 93 additions and 146 deletions
|
@ -96,6 +96,16 @@
|
|||
<outputDirectory/>
|
||||
<filtered>true</filtered>
|
||||
</file>
|
||||
<file>
|
||||
<source>target/keycloak-quarkus-server/default-clustered-cache.xml</source>
|
||||
<outputDirectory>conf</outputDirectory>
|
||||
<destName>clustered-cache.xml</destName>
|
||||
</file>
|
||||
<file>
|
||||
<source>target/keycloak-quarkus-server/default-local-cache.xml</source>
|
||||
<outputDirectory>conf</outputDirectory>
|
||||
<destName>local-cache.xml</destName>
|
||||
</file>
|
||||
</files>
|
||||
|
||||
</assembly>
|
||||
|
|
|
@ -64,6 +64,12 @@
|
|||
<type>zip</type>
|
||||
<outputDirectory>target/</outputDirectory>
|
||||
</artifactItem>
|
||||
<artifactItem>
|
||||
<groupId>org.keycloak</groupId>
|
||||
<artifactId>keycloak-quarkus-server</artifactId>
|
||||
<type>jar</type>
|
||||
<outputDirectory>target/keycloak-quarkus-server</outputDirectory>
|
||||
</artifactItem>
|
||||
</artifactItems>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
|
|
@ -1,105 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<infinispan
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="urn:infinispan:config:10.1 http://www.infinispan.org/schemas/infinispan-config-10.1.xsd"
|
||||
xmlns="urn:infinispan:config:10.1">
|
||||
|
||||
<!-- Distributed Cache Container Configuration-->
|
||||
<cache-container name="keycloak">
|
||||
<transport lock-timeout="60000"/>
|
||||
<local-cache name="realms">
|
||||
<memory>
|
||||
<object size="10000"/>
|
||||
</memory>
|
||||
</local-cache>
|
||||
<local-cache name="users">
|
||||
<memory>
|
||||
<object size="10000"/>
|
||||
</memory>
|
||||
</local-cache>
|
||||
<distributed-cache name="sessions" owners="1"/>
|
||||
<distributed-cache name="authenticationSessions" owners="1"/>
|
||||
<distributed-cache name="offlineSessions" owners="1"/>
|
||||
<distributed-cache name="clientSessions" owners="1"/>
|
||||
<distributed-cache name="offlineClientSessions" owners="1"/>
|
||||
<distributed-cache name="loginFailures" owners="1"/>
|
||||
<local-cache name="authorization">
|
||||
<memory>
|
||||
<object size="10000"/>
|
||||
</memory>
|
||||
</local-cache>
|
||||
<replicated-cache name="work"/>
|
||||
<local-cache name="keys">
|
||||
<expiration max-idle="3600000"/>
|
||||
<memory>
|
||||
<object size="1000"/>
|
||||
</memory>
|
||||
</local-cache>
|
||||
<distributed-cache name="actionTokens" owners="2">
|
||||
<expiration max-idle="-1" interval="300000"/>
|
||||
<memory>
|
||||
<object size="-1"/>
|
||||
</memory>
|
||||
</distributed-cache>
|
||||
</cache-container>
|
||||
|
||||
<!-- Local Cache Container Configuration -->
|
||||
<!--
|
||||
<cache-container name="keycloak">
|
||||
<local-cache name="default">
|
||||
<transaction transaction-manager-lookup="org.infinispan.transaction.lookup.JBossStandaloneJTAManagerLookup"/>
|
||||
</local-cache>
|
||||
<local-cache name="realms">
|
||||
<memory>
|
||||
<object size="10000"/>
|
||||
</memory>
|
||||
</local-cache>
|
||||
<local-cache name="users">
|
||||
<memory>
|
||||
<object size="10000"/>
|
||||
</memory>
|
||||
</local-cache>
|
||||
<local-cache name="sessions"/>
|
||||
<local-cache name="authenticationSessions"/>
|
||||
<local-cache name="offlineSessions"/>
|
||||
<local-cache name="clientSessions"/>
|
||||
<local-cache name="offlineClientSessions"/>
|
||||
<local-cache name="loginFailures"/>
|
||||
<local-cache name="work"/>
|
||||
<local-cache name="authorization">
|
||||
<memory>
|
||||
<object size="10000"/>
|
||||
</memory>
|
||||
</local-cache>
|
||||
<local-cache name="keys">
|
||||
<expiration max-idle="3600000"/>
|
||||
<memory>
|
||||
<object size="10000"/>
|
||||
</memory>
|
||||
</local-cache>
|
||||
<local-cache name="actionTokens">
|
||||
<expiration max-idle="-1" interval="300000"/>
|
||||
<memory>
|
||||
<object size="-1"/>
|
||||
</memory>
|
||||
</local-cache>
|
||||
</cache-container>
|
||||
-->
|
||||
</infinispan>
|
26
pom.xml
26
pom.xml
|
@ -1227,6 +1227,23 @@
|
|||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Quarkus -->
|
||||
<dependency>
|
||||
<groupId>org.keycloak</groupId>
|
||||
<artifactId>keycloak-quarkus-server</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.keycloak</groupId>
|
||||
<artifactId>keycloak-quarkus-server-deployment</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.keycloak</groupId>
|
||||
<artifactId>keycloak-quarkus-server-app</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Openshift -->
|
||||
<dependency>
|
||||
<groupId>com.openshift</groupId>
|
||||
|
@ -1798,15 +1815,6 @@
|
|||
<modules>
|
||||
<module>quarkus</module>
|
||||
</modules>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.keycloak</groupId>
|
||||
<artifactId>keycloak-quarkus-server</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</profile>
|
||||
|
||||
</profiles>
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
<dependency>
|
||||
<groupId>org.keycloak</groupId>
|
||||
<artifactId>keycloak-quarkus-server</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
|
|
|
@ -21,11 +21,8 @@ import static org.keycloak.configuration.PropertyMapper.createWithDefault;
|
|||
import static org.keycloak.configuration.PropertyMapper.forBuildTimeProperty;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.base.Ascii;
|
||||
import io.quarkus.runtime.configuration.ProfileManager;
|
||||
import io.smallrye.config.ConfigSourceInterceptorContext;
|
||||
import io.smallrye.config.ConfigValue;
|
||||
|
@ -40,6 +37,7 @@ public final class PropertyMappers {
|
|||
configureDatabasePropertyMappers();
|
||||
configureHttpPropertyMappers();
|
||||
configureProxyMappers();
|
||||
configureClustering();
|
||||
}
|
||||
|
||||
private static void configureHttpPropertyMappers() {
|
||||
|
@ -133,6 +131,19 @@ public final class PropertyMappers {
|
|||
createWithDefault("db.pool.max-size", "quarkus.datasource.jdbc.max-size", String.valueOf(100), "The maximum size of the connection pool.");
|
||||
}
|
||||
|
||||
private static void configureClustering() {
|
||||
createWithDefault("cluster.enabled", "kc.spi.connections-infinispan.default.clustered", "placeholder", (value, context) -> {
|
||||
if ("true".equals(value) || "false".equals(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
// Clustering is disabled by default for the "dev" profile. Otherwise enabled
|
||||
value = ("dev".equalsIgnoreCase(ProfileManager.getActiveProfile())) ? "false" : "true";
|
||||
return value;
|
||||
|
||||
}, "Enables Clustering. Possible values are 'true' or 'false'.");
|
||||
}
|
||||
|
||||
static ConfigValue getValue(ConfigSourceInterceptorContext context, String name) {
|
||||
return PropertyMapper.MAPPERS.getOrDefault(name, PropertyMapper.IDENTITY)
|
||||
.getOrDefault(name, context, context.proceed(name));
|
||||
|
|
|
@ -42,7 +42,9 @@ public final class QuarkusCacheManagerProvider implements ManagedCacheManagerPro
|
|||
|
||||
private static final Logger log = Logger.getLogger(QuarkusCacheManagerProvider.class);
|
||||
|
||||
private static final String DEFAULT_CONFIGURATION_FILE_NAME = "cluster.xml";
|
||||
// Configuration files from the distribution
|
||||
private static final String DEFAULT_CLUSTER_CONFIGURATION_FILE = "clustered-cache.xml";
|
||||
private static final String DEFAULT_LOCAL_CONFIGURATION_FILE = "local-cache.xml";
|
||||
|
||||
@Override
|
||||
public <C> C getCacheManager(Config.Scope config) {
|
||||
|
@ -70,38 +72,39 @@ public final class QuarkusCacheManagerProvider implements ManagedCacheManagerPro
|
|||
|
||||
if (homeDir == null) {
|
||||
log.warn("Keycloak home directory not set.");
|
||||
return loadDefaultConfiguration(config);
|
||||
return loadDefaultConfiguration(config, "default-clustered-cache.xml", "default-local-cache.xml");
|
||||
}
|
||||
|
||||
Path configPath = Paths.get(homeDir + "/conf/" + getConfigFileName(config));
|
||||
String pathPrefix = homeDir + "/conf/";
|
||||
|
||||
if (configPath.toFile().exists()) {
|
||||
log.debugf("Loading cluster configuration from %s", configPath);
|
||||
return FileLookupFactory.newInstance()
|
||||
.lookupFileStrict(configPath.toUri(), Thread.currentThread().getContextClassLoader());
|
||||
// Always try to use "configFile" if explicitly specified
|
||||
String configFile = config.get("configFile");
|
||||
if (configFile != null) {
|
||||
Path configPath = Paths.get(pathPrefix + configFile);
|
||||
|
||||
if (configPath.toFile().exists()) {
|
||||
log.infof("Loading cache configuration from %s", configPath);
|
||||
return FileLookupFactory.newInstance()
|
||||
.lookupFileStrict(configPath.toUri(), Thread.currentThread().getContextClassLoader());
|
||||
} else {
|
||||
log.warnf("Cache configuration file does not exists at %s . Fallback to the default configuration file", configPath);
|
||||
}
|
||||
}
|
||||
|
||||
log.infof("Clustering configuration file not found at %s.", configPath);
|
||||
|
||||
return loadDefaultConfiguration(config);
|
||||
return loadDefaultConfiguration(config, pathPrefix + DEFAULT_CLUSTER_CONFIGURATION_FILE, pathPrefix + DEFAULT_LOCAL_CONFIGURATION_FILE);
|
||||
}
|
||||
|
||||
private InputStream loadDefaultConfiguration(Config.Scope config) throws FileNotFoundException {
|
||||
private InputStream loadDefaultConfiguration(Config.Scope config, String defaultClusterConfigFile, String defaultLocalConfigFile) throws FileNotFoundException {
|
||||
if (config.getBoolean("clustered", false)) {
|
||||
log.debugf("Using default clustered cache configuration.");
|
||||
log.infof("Using default clustered cache configuration from file %s", defaultClusterConfigFile);
|
||||
return FileLookupFactory.newInstance()
|
||||
.lookupFileStrict("default-clustered-cache.xml", Thread.currentThread().getContextClassLoader());
|
||||
.lookupFileStrict(defaultClusterConfigFile, Thread.currentThread().getContextClassLoader());
|
||||
}
|
||||
|
||||
log.debug("Using default local cache configuration.");
|
||||
log.infof("Using default local cache configuration from file %s", defaultLocalConfigFile);
|
||||
|
||||
return FileLookupFactory.newInstance()
|
||||
.lookupFileStrict("default-local-cache.xml", Thread.currentThread().getContextClassLoader());
|
||||
}
|
||||
|
||||
private String getConfigFileName(Config.Scope config) {
|
||||
String configFile = config.get("configFile");
|
||||
return configFile == null ? DEFAULT_CONFIGURATION_FILE_NAME : configFile;
|
||||
.lookupFileStrict(defaultLocalConfigFile, Thread.currentThread().getContextClassLoader());
|
||||
}
|
||||
|
||||
private void configureTransportStack(Config.Scope config, ConfigurationBuilderHolder builder) {
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
|
||||
<infinispan
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="urn:infinispan:config:9.4 http://www.infinispan.org/schemas/infinispan-config-9.4.xsd"
|
||||
xmlns="urn:infinispan:config:9.4">
|
||||
xsi:schemaLocation="urn:infinispan:config:10.1 http://www.infinispan.org/schemas/infinispan-config-10.1.xsd"
|
||||
xmlns="urn:infinispan:config:10.1">
|
||||
|
||||
<cache-container name="keycloak">
|
||||
<transport lock-timeout="60000"/>
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
|
||||
<infinispan
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="urn:infinispan:config:9.4 http://www.infinispan.org/schemas/infinispan-config-9.4.xsd"
|
||||
xmlns="urn:infinispan:config:9.4">
|
||||
xsi:schemaLocation="urn:infinispan:config:10.1 http://www.infinispan.org/schemas/infinispan-config-10.1.xsd"
|
||||
xmlns="urn:infinispan:config:10.1">
|
||||
|
||||
<cache-container name="keycloak">
|
||||
<local-cache name="default">
|
||||
|
|
|
@ -234,6 +234,23 @@ public class ConfigurationTest {
|
|||
Assert.assertEquals("foo-val3", config.getConfigValue("quarkus.datasource.bar").getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClusterConfig() {
|
||||
// Cluster enabled by default, but disabled for the "dev" profile
|
||||
Assert.assertTrue(initConfig("connectionsInfinispan", "default").getBoolean("clustered"));
|
||||
System.setProperty("kc.profile", "dev");
|
||||
Assert.assertFalse(initConfig("connectionsInfinispan", "default").getBoolean("clustered"));
|
||||
|
||||
// If explicitly set, then it is always used regardless of the profile
|
||||
System.clearProperty("kc.profile");
|
||||
System.setProperty("kc.config.args", "--cluster-enabled=true");
|
||||
|
||||
Assert.assertTrue(initConfig("connectionsInfinispan", "default").getBoolean("clustered"));
|
||||
System.setProperty("kc.profile", "dev");
|
||||
Assert.assertTrue(initConfig("connectionsInfinispan", "default").getBoolean("clustered"));
|
||||
|
||||
}
|
||||
|
||||
private Config.Scope initConfig(String... scope) {
|
||||
Config.init(new MicroProfileConfigProvider(createConfig()));
|
||||
return Config.scope(scope);
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
<dependency>
|
||||
<groupId>org.keycloak</groupId>
|
||||
<artifactId>keycloak-quarkus-server</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- This dependency should not be here but due to the structure of the modules we need to make sure it is built
|
||||
|
@ -26,7 +25,6 @@
|
|||
<dependency>
|
||||
<groupId>org.keycloak</groupId>
|
||||
<artifactId>keycloak-quarkus-server-deployment</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
|
|
Loading…
Reference in a new issue