From 6c7a6f8e222e4fb39a11c220b63e785f2037d428 Mon Sep 17 00:00:00 2001 From: Florian Reimair Date: Thu, 16 Jan 2014 08:55:06 +0100 Subject: fix added real source of stork modules --- .../peps/configuration/ConfigurationCreator.java | 127 +++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 id/server/stork2-saml-engine/src/main/java/eu/stork/peps/configuration/ConfigurationCreator.java (limited to 'id/server/stork2-saml-engine/src/main/java/eu/stork/peps/configuration/ConfigurationCreator.java') diff --git a/id/server/stork2-saml-engine/src/main/java/eu/stork/peps/configuration/ConfigurationCreator.java b/id/server/stork2-saml-engine/src/main/java/eu/stork/peps/configuration/ConfigurationCreator.java new file mode 100644 index 000000000..2fabff7d6 --- /dev/null +++ b/id/server/stork2-saml-engine/src/main/java/eu/stork/peps/configuration/ConfigurationCreator.java @@ -0,0 +1,127 @@ +/* + * Licensed under the EUPL, Version 1.1 or – as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. You may + * obtain a copy of the Licence at: + * + * http://www.osor.eu/eupl/european-union-public-licence-eupl-v.1.1 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * Licence for the specific language governing permissions and limitations under + * the Licence. + */ + +package eu.stork.peps.configuration; + +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.InvalidPropertiesFormatException; +import java.util.Map; +import java.util.Properties; + +import org.apache.commons.io.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import eu.stork.peps.exceptions.STORKSAMLEngineException; + +/** + * The Class InstanceCreator. + * + * @author fjquevedo + */ +public final class ConfigurationCreator { + + /** The Constant LOGGER. */ + private static final Logger LOGGER = LoggerFactory + .getLogger(ConfigurationCreator.class.getName()); + + /** + * Creates the configuration. + * + * @param instanceConfs the instance configuration + * + * @return the map< string, map< string, object>> + * + * @throws STORKSAMLEngineException the STORKSAML engine exception + */ + public static Map> createConfiguration( + final Map instanceConfs) throws STORKSAMLEngineException { + + final HashMap> instances = + new HashMap>(); + + LOGGER.info("Create configuration."); + try { + // Only create instances for SAMLEngine configuration. + // INSTANCE + for (Map.Entry entry : instanceConfs + .entrySet()) { + final InstanceEngine iEngine = entry.getValue(); + + final Map intance = new HashMap(); + + // CONFIGURATION + for (ConfigurationEngine configuration : iEngine + .getConfiguration()) { + // Properties only for configuration SamlEngine. + if (configuration.getName().equalsIgnoreCase( + "SamlEngineConf")) { + intance.put(configuration.getName(), + getNewInstance(configuration.getParameters() + .get("fileConfiguration"))); + } else { + intance.put(configuration.getName(), configuration + .getParameters()); + } + } + instances.put(entry.getKey(), intance); + } + } catch (STORKSAMLEngineException ex) { + LOGGER.error("Can not create instance from file configuration."); + throw new STORKSAMLEngineException(ex); + } + return instances; + } + + + /** + * Gets the new instance. + * + * @param fileName the file name + * + * @return the properties from the new instance + * + * @throws STORKSAMLEngineException the STORKSAML engine + * runtime exception + */ + private static Properties getNewInstance(final String fileName) + throws STORKSAMLEngineException { + LOGGER.info("Create file configuration properties to Stork Saml Engine."); + InputStream fileEngineProp = null; + try { + fileEngineProp = ConfigurationCreator.class + .getResourceAsStream("/" + fileName); + final Properties configuration = new Properties(); + configuration.loadFromXML(fileEngineProp); + return configuration; + } catch (InvalidPropertiesFormatException e) { + LOGGER.error("Invalid properties format."); + throw new STORKSAMLEngineException(e); + } catch (IOException e) { + LOGGER.error("Error read file: " + fileName); + throw new STORKSAMLEngineException(e); + } finally { + IOUtils.closeQuietly(fileEngineProp); + } + } + + /** + * Instantiates a new instance creator. + */ + private ConfigurationCreator() { + } +} \ No newline at end of file -- cgit v1.2.3 From 1c72a260e3633eb8e411992ac25fc747ec71513c Mon Sep 17 00:00:00 2001 From: Florian Reimair Date: Thu, 30 Jan 2014 17:43:18 +0100 Subject: fixed samlengine config loading --- .../eu/stork/peps/configuration/ConfigurationCreator.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'id/server/stork2-saml-engine/src/main/java/eu/stork/peps/configuration/ConfigurationCreator.java') diff --git a/id/server/stork2-saml-engine/src/main/java/eu/stork/peps/configuration/ConfigurationCreator.java b/id/server/stork2-saml-engine/src/main/java/eu/stork/peps/configuration/ConfigurationCreator.java index 2fabff7d6..b40e3f7dd 100644 --- a/id/server/stork2-saml-engine/src/main/java/eu/stork/peps/configuration/ConfigurationCreator.java +++ b/id/server/stork2-saml-engine/src/main/java/eu/stork/peps/configuration/ConfigurationCreator.java @@ -15,6 +15,7 @@ package eu.stork.peps.configuration; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.HashMap; @@ -103,8 +104,16 @@ public final class ConfigurationCreator { LOGGER.info("Create file configuration properties to Stork Saml Engine."); InputStream fileEngineProp = null; try { - fileEngineProp = ConfigurationCreator.class - .getResourceAsStream("/" + fileName); + // fetch base from system properties, give a default if there is nothing configured + String base = System.getProperty("eu.stork.samlengine.config.location"); + if(null != base) + if(!base.endsWith("/")) + base += "/"; + + if(null != base) + fileEngineProp = new FileInputStream(base + fileName); + else + fileEngineProp = ConfigurationCreator.class.getResourceAsStream("/" + fileName); final Properties configuration = new Properties(); configuration.loadFromXML(fileEngineProp); return configuration; -- cgit v1.2.3