KEYCLOAK-12414 Remove the need to specify defaults in config file
This commit is contained in:
parent
35f622f48e
commit
b04932ede5
11 changed files with 73 additions and 183 deletions
|
@ -88,7 +88,8 @@ public class Config {
|
|||
|
||||
@Override
|
||||
public String get(String key, String defaultValue) {
|
||||
return System.getProperty(prefix + key, defaultValue);
|
||||
String v = System.getProperty(prefix + key, defaultValue);
|
||||
return v != null && !v.isEmpty() ? v : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -52,4 +52,9 @@ public class JpaUserSessionPersisterProviderFactory implements UserSessionPersis
|
|||
public String getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int order() {
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,7 +111,11 @@ public class QuarkusJpaConnectionProviderFactory implements JpaConnectionProvide
|
|||
public void postInit(KeycloakSessionFactory factory) {
|
||||
this.factory = factory;
|
||||
checkJtaEnabled(factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int order() {
|
||||
return 100;
|
||||
}
|
||||
|
||||
protected void checkJtaEnabled(KeycloakSessionFactory factory) {
|
||||
|
|
|
@ -53,4 +53,9 @@ public class QuarkusJtaTransactionManagerLookup implements JtaTransactionManager
|
|||
public String getId() {
|
||||
return "quarkus";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int order() {
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,45 +1,8 @@
|
|||
# Main
|
||||
|
||||
admin.realm = master
|
||||
scheduled.interval = 900
|
||||
|
||||
# Theme
|
||||
theme.staticMaxAge = 2592000
|
||||
theme.cacheThemes = true
|
||||
theme.cacheTemplates = true
|
||||
#theme.dir = ${keycloak.home.dir}/themes
|
||||
|
||||
# Datasource
|
||||
datasource.url = jdbc:h2:mem:test;DB_CLOSE_DELAY=-1
|
||||
datasource.driver = org.h2.Driver
|
||||
datasource.username = sa
|
||||
datasource.password = keycloak
|
||||
|
||||
# SPIs
|
||||
|
||||
eventsListener.jboss-logging.success-level = debug
|
||||
eventsListener.jboss-logging.error-level = warn
|
||||
|
||||
connectionsJpa.provider = quarkus
|
||||
connectionsJpa.quarkus.initializeEmpty = true
|
||||
connectionsJpa.quarkus.migrationStrategy = update
|
||||
connectionsJpa.quarkus.showSql = false
|
||||
connectionsJpa.quarkus.formatSql = true
|
||||
connectionsJpa.quarkus.globalStatsInterval = -1
|
||||
|
||||
eventsStore.provider=jpa
|
||||
realm.provider=jpa
|
||||
user.provider=jpa
|
||||
userFederatedStorage.provider=jpa
|
||||
userSessionPersister.provider=jpa
|
||||
authorizationPersister.provider=jpa
|
||||
|
||||
userCache.enabled=true
|
||||
|
||||
timer.provider=basic
|
||||
|
||||
hostname.provider = default
|
||||
hostname.default.frontendUrl = ${keycloak.frontendUrl:}
|
||||
hostname.default.forceBackendUrlToFrontendUrl = false
|
||||
|
||||
jta-lookup.provider = quarkus
|
||||
|
|
|
@ -34,9 +34,4 @@ public interface HostnameProviderFactory extends ProviderFactory<HostnameProvide
|
|||
default void postInit(KeycloakSessionFactory factory) {
|
||||
}
|
||||
|
||||
@Override
|
||||
default int order() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,11 +34,13 @@ import org.keycloak.provider.Spi;
|
|||
import org.keycloak.services.resources.admin.permissions.AdminPermissions;
|
||||
import org.keycloak.theme.DefaultThemeManagerFactory;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
|
@ -181,18 +183,34 @@ public class DefaultKeycloakSessionFactory implements KeycloakSessionFactory, Pr
|
|||
|
||||
protected void checkProvider() {
|
||||
for (Spi spi : spis) {
|
||||
String provider = Config.getProvider(spi.getName());
|
||||
if (provider != null) {
|
||||
this.provider.put(spi.getProviderClass(), provider);
|
||||
if (getProviderFactory(spi.getProviderClass(), provider) == null) {
|
||||
String defaultProvider = Config.getProvider(spi.getName());
|
||||
if (defaultProvider != null) {
|
||||
if (getProviderFactory(spi.getProviderClass(), defaultProvider) == null) {
|
||||
throw new RuntimeException("Failed to find provider " + provider + " for " + spi.getName());
|
||||
}
|
||||
} else {
|
||||
Map<String, ProviderFactory> factories = factoriesMap.get(spi.getProviderClass());
|
||||
if (factories != null && factories.size() == 1) {
|
||||
provider = factories.values().iterator().next().getId();
|
||||
this.provider.put(spi.getProviderClass(), provider);
|
||||
defaultProvider = factories.values().iterator().next().getId();
|
||||
}
|
||||
|
||||
if (defaultProvider == null) {
|
||||
Optional<ProviderFactory> highestPriority = factories.values().stream().max(Comparator.comparing(ProviderFactory::order));
|
||||
if (highestPriority.isPresent() && highestPriority.get().order() > 0) {
|
||||
defaultProvider = highestPriority.get().getId();
|
||||
}
|
||||
}
|
||||
|
||||
if (defaultProvider == null && factories.containsKey("default")) {
|
||||
defaultProvider = "default";
|
||||
}
|
||||
}
|
||||
|
||||
if (defaultProvider != null) {
|
||||
this.provider.put(spi.getProviderClass(), defaultProvider);
|
||||
logger.debugv("Set default provider for {0} to {1}", spi.getName(), defaultProvider);
|
||||
} else {
|
||||
logger.debugv("No default provider for {0}", spi.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -257,69 +275,11 @@ public class DefaultKeycloakSessionFactory implements KeycloakSessionFactory, Pr
|
|||
return true;
|
||||
}
|
||||
|
||||
protected void loadSPIs(ProviderManager pm, List<Spi> spiList) {
|
||||
for (Spi spi : spiList) {
|
||||
spis.add(spi);
|
||||
|
||||
Map<String, ProviderFactory> factories = new HashMap<String, ProviderFactory>();
|
||||
factoriesMap.put(spi.getProviderClass(), factories);
|
||||
|
||||
String provider = Config.getProvider(spi.getName());
|
||||
if (provider != null) {
|
||||
this.provider.put(spi.getProviderClass(), provider);
|
||||
|
||||
ProviderFactory factory = pm.load(spi, provider);
|
||||
if (factory == null) {
|
||||
throw new RuntimeException("Failed to find provider " + provider + " for " + spi.getName());
|
||||
}
|
||||
|
||||
Config.Scope scope = Config.scope(spi.getName(), provider);
|
||||
factory.init(scope);
|
||||
|
||||
if (spi.isInternal() && !isInternal(factory)) {
|
||||
ServicesLogger.LOGGER.spiMayChange(factory.getId(), factory.getClass().getName(), spi.getName());
|
||||
}
|
||||
|
||||
factories.put(factory.getId(), factory);
|
||||
|
||||
logger.debugv("Loaded SPI {0} (provider = {1})", spi.getName(), provider);
|
||||
} else {
|
||||
for (ProviderFactory factory : pm.load(spi)) {
|
||||
Config.Scope scope = Config.scope(spi.getName(), factory.getId());
|
||||
if (scope.getBoolean("enabled", true)) {
|
||||
factory.init(scope);
|
||||
|
||||
if (spi.isInternal() && !isInternal(factory)) {
|
||||
ServicesLogger.LOGGER.spiMayChange(factory.getId(), factory.getClass().getName(), spi.getName());
|
||||
}
|
||||
|
||||
factories.put(factory.getId(), factory);
|
||||
} else {
|
||||
logger.debugv("SPI {0} provider {1} disabled", spi.getName(), factory.getId());
|
||||
}
|
||||
}
|
||||
|
||||
if (factories.size() == 1) {
|
||||
provider = factories.values().iterator().next().getId();
|
||||
this.provider.put(spi.getProviderClass(), provider);
|
||||
|
||||
logger.debugv("Loaded SPI {0} (provider = {1})", spi.getName(), provider);
|
||||
} else {
|
||||
logger.debugv("Loaded SPI {0} (providers = {1})", spi.getName(), factories.keySet());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public KeycloakSession create() {
|
||||
KeycloakSession session = new DefaultKeycloakSession(this);
|
||||
return session;
|
||||
}
|
||||
|
||||
<T extends Provider> String getDefaultProvider(Class<T> clazz) {
|
||||
return provider.get(clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Spi> getSpis() {
|
||||
return spis;
|
||||
|
|
|
@ -268,7 +268,7 @@ public class KeycloakApplication extends Application {
|
|||
}
|
||||
|
||||
public static void setupScheduledTasks(final KeycloakSessionFactory sessionFactory) {
|
||||
long interval = Config.scope("scheduled").getLong("interval", 60L) * 1000;
|
||||
long interval = Config.scope("scheduled").getLong("interval", 900L) * 1000;
|
||||
|
||||
KeycloakSession session = sessionFactory.create();
|
||||
try {
|
||||
|
|
|
@ -36,7 +36,7 @@ public class CacheControlUtil {
|
|||
public static CacheControl getDefaultCacheControl() {
|
||||
CacheControl cacheControl = new CacheControl();
|
||||
cacheControl.setNoTransform(false);
|
||||
Integer maxAge = Config.scope("theme").getInt("staticMaxAge");
|
||||
Integer maxAge = Config.scope("theme").getInt("staticMaxAge", 2592000);
|
||||
if (maxAge != null && maxAge > 0) {
|
||||
cacheControl.setMaxAge(maxAge);
|
||||
} else {
|
||||
|
|
|
@ -88,7 +88,8 @@ public class JsonConfigProvider implements Config.ConfigProvider {
|
|||
if (n == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
return replaceProperties(n.textValue());
|
||||
String v = replaceProperties(n.textValue());
|
||||
return !v.isEmpty() ? v : defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -126,7 +127,8 @@ public class JsonConfigProvider implements Config.ConfigProvider {
|
|||
return defaultValue;
|
||||
}
|
||||
if (n.isTextual()) {
|
||||
return Integer.parseInt(replaceProperties(n.textValue()));
|
||||
String v = replaceProperties(n.textValue());
|
||||
return !v.isEmpty() ? Integer.parseInt(v) : defaultValue;
|
||||
} else {
|
||||
return n.intValue();
|
||||
}
|
||||
|
@ -147,7 +149,8 @@ public class JsonConfigProvider implements Config.ConfigProvider {
|
|||
return defaultValue;
|
||||
}
|
||||
if (n.isTextual()) {
|
||||
return Long.parseLong(replaceProperties(n.textValue()));
|
||||
String v = replaceProperties(n.textValue());
|
||||
return !v.isEmpty() ? Long.parseLong(v) : defaultValue;
|
||||
} else {
|
||||
return n.longValue();
|
||||
}
|
||||
|
@ -168,7 +171,8 @@ public class JsonConfigProvider implements Config.ConfigProvider {
|
|||
return defaultValue;
|
||||
}
|
||||
if (n.isTextual()) {
|
||||
return Boolean.parseBoolean(replaceProperties(n.textValue()));
|
||||
String v = replaceProperties(n.textValue());
|
||||
return !v.isEmpty() ? Boolean.parseBoolean(v) : defaultValue;
|
||||
} else {
|
||||
return n.booleanValue();
|
||||
}
|
||||
|
|
|
@ -1,77 +1,48 @@
|
|||
{
|
||||
|
||||
"hostname": {
|
||||
"provider": "${keycloak.hostname.provider:default}",
|
||||
"provider": "${keycloak.hostname.provider:}",
|
||||
|
||||
"default": {
|
||||
"frontendUrl": "${keycloak.frontendUrl:}",
|
||||
"adminUrl": "${keycloak.adminUrl:}",
|
||||
"forceBackendUrlToFrontendUrl": "${keycloak.hostname.default.forceBackendUrlToFrontendUrl:false}"
|
||||
"forceBackendUrlToFrontendUrl": "${keycloak.hostname.default.forceBackendUrlToFrontendUrl:}"
|
||||
}
|
||||
},
|
||||
|
||||
"admin": {
|
||||
"realm": "master"
|
||||
},
|
||||
|
||||
"eventsStore": {
|
||||
"provider": "${keycloak.eventsStore.provider:jpa}"
|
||||
},
|
||||
|
||||
"eventsListener": {
|
||||
"jboss-logging" : {
|
||||
"success-level": "debug",
|
||||
"error-level": "warn"
|
||||
}
|
||||
"provider": "${keycloak.eventsStore.provider:}"
|
||||
},
|
||||
|
||||
"realm": {
|
||||
"provider": "${keycloak.realm.provider:jpa}"
|
||||
"provider": "${keycloak.realm.provider:}"
|
||||
},
|
||||
|
||||
"user": {
|
||||
"provider": "${keycloak.user.provider:jpa}"
|
||||
"provider": "${keycloak.user.provider:}"
|
||||
},
|
||||
|
||||
"userFederatedStorage": {
|
||||
"provider": "${keycloak.userFederatedStorage.provider:jpa}"
|
||||
"provider": "${keycloak.userFederatedStorage.provider:}"
|
||||
},
|
||||
|
||||
"userSessionPersister": {
|
||||
"provider": "${keycloak.userSessionPersister.provider:jpa}"
|
||||
"provider": "${keycloak.userSessionPersister.provider:}"
|
||||
},
|
||||
|
||||
"authorizationPersister": {
|
||||
"provider": "${keycloak.authorization.provider:jpa}"
|
||||
},
|
||||
|
||||
"userCache": {
|
||||
"default" : {
|
||||
"enabled": true
|
||||
}
|
||||
},
|
||||
|
||||
"timer": {
|
||||
"provider": "basic"
|
||||
"provider": "${keycloak.authorization.provider:}"
|
||||
},
|
||||
|
||||
"theme": {
|
||||
"staticMaxAge": "${keycloak.theme.staticMaxAge:2592000}",
|
||||
"cacheTemplates": "${keycloak.theme.cacheTemplates:true}",
|
||||
"cacheThemes": "${keycloak.theme.cacheThemes:true}",
|
||||
"staticMaxAge": "${keycloak.theme.staticMaxAge:}",
|
||||
"cacheTemplates": "${keycloak.theme.cacheTemplates:}",
|
||||
"cacheThemes": "${keycloak.theme.cacheThemes:}",
|
||||
"folder": {
|
||||
"dir": "${keycloak.theme.dir}"
|
||||
}
|
||||
},
|
||||
|
||||
"scheduled": {
|
||||
"interval": 900
|
||||
},
|
||||
|
||||
"connectionsHttpClient": {
|
||||
"default": {}
|
||||
},
|
||||
|
||||
"connectionsJpa": {
|
||||
"default": {
|
||||
"url": "${keycloak.connectionsJpa.url:jdbc:h2:mem:test;DB_CLOSE_DELAY=-1}",
|
||||
|
@ -79,17 +50,9 @@
|
|||
"driverDialect": "${keycloak.connectionsJpa.driverDialect:}",
|
||||
"user": "${keycloak.connectionsJpa.user:sa}",
|
||||
"password": "${keycloak.connectionsJpa.password:}",
|
||||
"initializeEmpty": true,
|
||||
"migrationStrategy": "update",
|
||||
"showSql": "${keycloak.connectionsJpa.showSql:false}",
|
||||
"formatSql": "${keycloak.connectionsJpa.formatSql:true}",
|
||||
"globalStatsInterval": "${keycloak.connectionsJpa.globalStatsInterval:-1}"
|
||||
}
|
||||
},
|
||||
|
||||
"realmCache": {
|
||||
"default" : {
|
||||
"enabled": true
|
||||
"showSql": "${keycloak.connectionsJpa.showSql:}",
|
||||
"formatSql": "${keycloak.connectionsJpa.formatSql:}",
|
||||
"globalStatsInterval": "${keycloak.connectionsJpa.globalStatsInterval:}"
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -98,13 +61,13 @@
|
|||
"jgroupsUdpMcastAddr": "${keycloak.connectionsInfinispan.jgroupsUdpMcastAddr:234.56.78.90}",
|
||||
"nodeName": "${keycloak.connectionsInfinispan.nodeName,jboss.node.name:}",
|
||||
"siteName": "${keycloak.connectionsInfinispan.siteName,jboss.site.name:}",
|
||||
"clustered": "${keycloak.connectionsInfinispan.clustered:false}",
|
||||
"async": "${keycloak.connectionsInfinispan.async:false}",
|
||||
"sessionsOwners": "${keycloak.connectionsInfinispan.sessionsOwners:1}",
|
||||
"l1Lifespan": "${keycloak.connectionsInfinispan.l1Lifespan:600000}",
|
||||
"remoteStoreEnabled": "${keycloak.connectionsInfinispan.remoteStoreEnabled:false}",
|
||||
"remoteStoreHost": "${keycloak.connectionsInfinispan.remoteStoreServer:localhost}",
|
||||
"remoteStorePort": "${keycloak.connectionsInfinispan.remoteStorePort:11222}",
|
||||
"clustered": "${keycloak.connectionsInfinispan.clustered:}",
|
||||
"async": "${keycloak.connectionsInfinispan.async:}",
|
||||
"sessionsOwners": "${keycloak.connectionsInfinispan.sessionsOwners:}",
|
||||
"l1Lifespan": "${keycloak.connectionsInfinispan.l1Lifespan:}",
|
||||
"remoteStoreEnabled": "${keycloak.connectionsInfinispan.remoteStoreEnabled:}",
|
||||
"remoteStoreHost": "${keycloak.connectionsInfinispan.remoteStoreServer:}",
|
||||
"remoteStorePort": "${keycloak.connectionsInfinispan.remoteStorePort:}",
|
||||
"hotrodProtocolVersion": "${keycloak.connectionsInfinispan.hotrodProtocolVersion}",
|
||||
"embedded": "${keycloak.connectionsInfinispan.embedded:true}"
|
||||
}
|
||||
|
@ -114,11 +77,7 @@
|
|||
},
|
||||
|
||||
"jta-lookup": {
|
||||
"provider": "${keycloak.jta.lookup.provider:jboss}",
|
||||
"jboss" : {
|
||||
"enabled": true
|
||||
}
|
||||
|
||||
"provider": "${keycloak.jta.lookup.provider:}"
|
||||
},
|
||||
|
||||
"login-protocol": {
|
||||
|
@ -131,24 +90,18 @@
|
|||
},
|
||||
|
||||
"x509cert-lookup": {
|
||||
"provider": "${keycloak.x509cert.lookup.provider:default}",
|
||||
"default": {
|
||||
"enabled": true
|
||||
},
|
||||
"provider": "${keycloak.x509cert.lookup.provider:}",
|
||||
"haproxy": {
|
||||
"enabled": true,
|
||||
"sslClientCert": "x-ssl-client-cert",
|
||||
"sslCertChainPrefix": "x-ssl-client-cert-chain",
|
||||
"certificateChainLength": 1
|
||||
},
|
||||
"apache": {
|
||||
"enabled": true,
|
||||
"sslClientCert": "x-ssl-client-cert",
|
||||
"sslCertChainPrefix": "x-ssl-client-cert-chain",
|
||||
"certificateChainLength": 1
|
||||
},
|
||||
"nginx": {
|
||||
"enabled": true,
|
||||
"sslClientCert": "x-ssl-client-cert",
|
||||
"sslCertChainPrefix": "x-ssl-client-cert-chain",
|
||||
"certificateChainLength": 1
|
||||
|
|
Loading…
Reference in a new issue