From 59440840fea687c6198480f0f2af018e236cb52a Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Wed, 21 May 2014 09:35:01 +0100 Subject: [PATCH] Read keycloak-sever.json from /standalone/configuration if it exists --- distribution/appliance-dist/assembly.xml | 7 +++++++ distribution/war-zip/assembly.xml | 7 +++++++ .../services/DefaultProviderSessionFactory.java | 2 -- .../services/resources/KeycloakApplication.java | 16 +++++++++++++++- .../services/util/JsonConfigProvider.java | 8 ++++---- 5 files changed, 33 insertions(+), 7 deletions(-) diff --git a/distribution/appliance-dist/assembly.xml b/distribution/appliance-dist/assembly.xml index 957cc368db..049062a4cc 100755 --- a/distribution/appliance-dist/assembly.xml +++ b/distribution/appliance-dist/assembly.xml @@ -38,6 +38,13 @@ keycloak-ds.xml + + ${project.build.directory}/unpacked/deployments/auth-server.war/WEB-INF/classes/META-INF + keycloak/standalone/configuration + + keycloak-server.json + + ${project.build.directory}/unpacked/themes keycloak/standalone/configuration/themes diff --git a/distribution/war-zip/assembly.xml b/distribution/war-zip/assembly.xml index 89ed1aae8b..124b455846 100755 --- a/distribution/war-zip/assembly.xml +++ b/distribution/war-zip/assembly.xml @@ -19,5 +19,12 @@ deployments + + ${project.build.directory}/unpacked/deployments/auth-server.war/WEB-INF/classes/META-INF + configuration + + keycloak-server.json + + diff --git a/services/src/main/java/org/keycloak/services/DefaultProviderSessionFactory.java b/services/src/main/java/org/keycloak/services/DefaultProviderSessionFactory.java index 128c27200c..1dcf5fe303 100755 --- a/services/src/main/java/org/keycloak/services/DefaultProviderSessionFactory.java +++ b/services/src/main/java/org/keycloak/services/DefaultProviderSessionFactory.java @@ -33,7 +33,6 @@ public class DefaultProviderSessionFactory implements ProviderSessionFactory { ProviderFactory factory = loadProviderFactory(spi, provider); Config.Scope scope = Config.scope(spi.getName(), provider); factory.init(scope); - log.debug("Initialized " + factory.getClass().getName() + " (config = " + scope + ")"); factories.put(factory.getId(), factory); @@ -42,7 +41,6 @@ public class DefaultProviderSessionFactory implements ProviderSessionFactory { for (ProviderFactory factory : ServiceLoader.load(spi.getProviderFactoryClass())) { Config.Scope scope = Config.scope(spi.getName(), factory.getId()); factory.init(scope); - log.debug("Initialized " + factory.getClass().getName() + " (config = " + scope + ")"); factories.put(factory.getId(), factory); } diff --git a/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java b/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java index c677aa868c..24d7df8011 100755 --- a/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java +++ b/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java @@ -108,7 +108,19 @@ public class KeycloakApplication extends Application { protected void loadConfig() { try { - URL config = Thread.currentThread().getContextClassLoader().getResource("META-INF/keycloak-server.json"); + URL config = null; + + String configDir = System.getProperty("jboss.server.config.dir"); + if (configDir != null) { + File f = new File(configDir + File.separator + "keycloak-server.json"); + if (f.isFile()) { + config = f.toURI().toURL(); + } + } + + if (config == null) { + config = Thread.currentThread().getContextClassLoader().getResource("META-INF/keycloak-server.json"); + } if (config != null) { JsonNode node = new ObjectMapper().readTree(config); @@ -116,6 +128,8 @@ public class KeycloakApplication extends Application { log.info("Loaded config from " + config); return; + } else { + log.warn("Config 'keycloak-server.json' not found"); } } catch (IOException e) { throw new RuntimeException("Failed to load config", e); diff --git a/services/src/main/java/org/keycloak/services/util/JsonConfigProvider.java b/services/src/main/java/org/keycloak/services/util/JsonConfigProvider.java index 714e4dbe1d..0eb1cef453 100644 --- a/services/src/main/java/org/keycloak/services/util/JsonConfigProvider.java +++ b/services/src/main/java/org/keycloak/services/util/JsonConfigProvider.java @@ -74,11 +74,11 @@ public class JsonConfigProvider implements Config.ConfigProvider { if (n == null) { return null; } else if (n.isArray()) { - ArrayList l = new ArrayList(); - for (JsonNode e : n) { - l.add(StringPropertyReplacer.replaceProperties(e.getTextValue())); + String[] a = new String[n.size()]; + for (int i = 0; i < a.length; i++) { + a[i] = StringPropertyReplacer.replaceProperties(n.get(i).getTextValue()); } - return (String[]) l.toArray(); + return a; } else { return new String[] { StringPropertyReplacer.replaceProperties(n.getTextValue()) }; }