diff options
author | Florian Reimair <florian.reimair@iaik.tugraz.at> | 2015-08-07 13:24:09 +0200 |
---|---|---|
committer | Florian Reimair <florian.reimair@iaik.tugraz.at> | 2015-08-07 13:24:09 +0200 |
commit | f71531346c6be197957311712ba093e024545e37 (patch) | |
tree | 450a1480dd65b61a98a71588e635bf91c1613cb7 /id/server/stork2-saml-engine/src/main/java/eu/stork/peps/configuration/ConfigurationCreator.java | |
parent | b92da70a3071e1dbf910ee38ff4efbe61ecc8be6 (diff) | |
download | moa-id-spss-f71531346c6be197957311712ba093e024545e37.tar.gz moa-id-spss-f71531346c6be197957311712ba093e024545e37.tar.bz2 moa-id-spss-f71531346c6be197957311712ba093e024545e37.zip |
preparing the old code for the merge
Diffstat (limited to 'id/server/stork2-saml-engine/src/main/java/eu/stork/peps/configuration/ConfigurationCreator.java')
-rw-r--r-- | id/server/stork2-saml-engine/src/main/java/eu/stork/peps/configuration/ConfigurationCreator.java | 199 |
1 files changed, 95 insertions, 104 deletions
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 c53e18662..6e76c52a6 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 @@ -35,108 +35,99 @@ import java.util.Properties; */ 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<String, Map<String, Object>> createConfiguration( - final Map<String, InstanceEngine> instanceConfs) throws STORKSAMLEngineException { - - final HashMap<String, Map<String, Object>> instances = - new HashMap<String, Map<String, Object>>(); - - LOGGER.info("Create configuration."); - try { - // Only create instances for SAMLEngine configuration. - // INSTANCE - for (Map.Entry<String, InstanceEngine> entry : instanceConfs - .entrySet()) { - final InstanceEngine iEngine = entry.getValue(); - - final Map<String, Object> intance = new HashMap<String, Object>(); - - // 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 { - InputStream fileEngineProp = null; - - // 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 += "/"; - } - } else { - base = "/"; - } - - LOGGER.info("Create file configuration properties to Stork Saml Engine: " + base + fileName); - - try { - - if (null != base) - fileEngineProp = new FileInputStream(base + fileName); - else - fileEngineProp = ConfigurationCreator.class - .getResourceAsStream(base + 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: " + base + fileName); - throw new STORKSAMLEngineException(e); - } finally { - IOUtils.closeQuietly(fileEngineProp); - } - } - - /** - * Instantiates a new instance creator. - */ - private 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<String, Map<String, Object>> createConfiguration(final Map<String, InstanceEngine> instanceConfs) throws STORKSAMLEngineException { + + final HashMap<String, Map<String, Object>> instances = new HashMap<String, Map<String, Object>>(); + + LOGGER.info("Create configuration."); + try { + // Only create instances for SAMLEngine configuration. + // INSTANCE + for (Map.Entry<String, InstanceEngine> entry : instanceConfs.entrySet()) { + final InstanceEngine iEngine = entry.getValue(); + + final Map<String, Object> intance = new HashMap<String, Object>(); + + // 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 { + InputStream fileEngineProp = null; + + // 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 += "/"; + } + } else { + base = "/"; + } + + LOGGER.info("Create file configuration properties to Stork Saml Engine: " + base + fileName); + + try { + + if (null != base) + fileEngineProp = new FileInputStream(base + fileName); + else + fileEngineProp = ConfigurationCreator.class.getResourceAsStream(base + 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: " + base + fileName); + throw new STORKSAMLEngineException(e); + } finally { + IOUtils.closeQuietly(fileEngineProp); + } + } + + /** + * Instantiates a new instance creator. + */ + private ConfigurationCreator() { + } }
\ No newline at end of file |