summaryrefslogtreecommitdiff
path: root/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/conf
diff options
context:
space:
mode:
authorThomas Lenz <thomas.lenz@egiz.gv.at>2019-12-04 19:43:32 +0100
committerThomas Lenz <thomas.lenz@egiz.gv.at>2019-12-04 19:43:32 +0100
commit759ac5f42c6aff901dbeede4fbf1a1d2e08cad0f (patch)
tree2132024fc058b1ef5338bf50df575a3244cc3f9f /eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/conf
parent4f15bdc45b08724d20c66c9fd74ea6a43a03c32f (diff)
downloadEAAF-Components-759ac5f42c6aff901dbeede4fbf1a1d2e08cad0f.tar.gz
EAAF-Components-759ac5f42c6aff901dbeede4fbf1a1d2e08cad0f.tar.bz2
EAAF-Components-759ac5f42c6aff901dbeede4fbf1a1d2e08cad0f.zip
common EGIZ code-style refactoring
Diffstat (limited to 'eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/conf')
-rw-r--r--eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/conf/AbstractConfigurationImpl.java437
-rw-r--r--eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/conf/AbstractSpringBootConfigurationImpl.java385
-rw-r--r--eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/conf/SPConfigurationImpl.java191
-rw-r--r--eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/conf/SpConfigurationImpl.java193
4 files changed, 605 insertions, 601 deletions
diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/conf/AbstractConfigurationImpl.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/conf/AbstractConfigurationImpl.java
index 55662326..e661a2a8 100644
--- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/conf/AbstractConfigurationImpl.java
+++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/conf/AbstractConfigurationImpl.java
@@ -1,29 +1,22 @@
-/*******************************************************************************
- * Copyright 2017 Graz University of Technology
- * EAAF-Core Components has been developed in a cooperation between EGIZ,
- * A-SIT Plus, A-SIT, and Graz University of Technology.
+/*
+ * Copyright 2017 Graz University of Technology EAAF-Core Components has been developed in a
+ * cooperation between EGIZ, A-SIT Plus, A-SIT, and Graz University of Technology.
*
- * Licensed under the EUPL, Version 1.2 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:
+ * Licensed under the EUPL, Version 1.2 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:
* https://joinup.ec.europa.eu/news/understanding-eupl-v12
*
- * 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.
- *
- * This product combines work with different licenses. See the "NOTICE" text
- * file for details on the various modules and licenses.
- * The "NOTICE" text file is part of the distribution. Any derivative works
- * that you distribute must include a readable copy of the "NOTICE" text file.
- *******************************************************************************/
-/*******************************************************************************
- *******************************************************************************/
-/*******************************************************************************
- *******************************************************************************/
+ * 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.
+ *
+ * This product combines work with different licenses. See the "NOTICE" text file for details on the
+ * various modules and licenses. The "NOTICE" text file is part of the distribution. Any derivative
+ * works that you distribute must include a readable copy of the "NOTICE" text file.
+*/
+
package at.gv.egiz.eaaf.core.impl.idp.conf;
import java.io.File;
@@ -34,201 +27,215 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
import java.util.Properties;
-
+import at.gv.egiz.eaaf.core.api.idp.IExtendedConfiguration;
+import at.gv.egiz.eaaf.core.exceptions.EaafConfigurationException;
+import at.gv.egiz.eaaf.core.impl.utils.KeyValueUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import at.gv.egiz.eaaf.core.api.idp.IExtendedConfiguration;
-import at.gv.egiz.eaaf.core.exceptions.EAAFConfigurationException;
-import at.gv.egiz.eaaf.core.impl.utils.KeyValueUtils;
-
public abstract class AbstractConfigurationImpl implements IExtendedConfiguration {
- private static final Logger log = LoggerFactory.getLogger(AbstractConfigurationImpl.class);
-
- private static final String URI_SCHEME_CLASSPATH = "classpath";
- private static final String URI_SCHEME_FILESYSTEM = "file";
-
- private final URI internalConfigPath;
- private final URI configRootDirectory;
- private final Properties properties;
-
- public AbstractConfigurationImpl(final String configPath) throws EAAFConfigurationException {
- InputStream is = null;
- try {
- log.debug("Starting EAAFCore initialization process .... ");
-
- if (StringUtils.isEmpty(configPath)) {
- log.debug("Primary configuration is empty. Search for backup configuration .... ");
- final String backupConfigPath = getBackupConfigPath();
- if (StringUtils.isEmpty(backupConfigPath)) {
- log.error("No configuration file found.");
- throw new EAAFConfigurationException("config.01", null);
-
- }
-
- internalConfigPath = new URI(getBackupConfigPath());
-
- } else
- internalConfigPath = new URI(configPath);
-
- log.info("Load EAAFCore configuration from " + internalConfigPath);
-
-
- //extract configuration root directory
- //TODO: check if it works with classpath
- final File propertiesFile = new File(internalConfigPath);
- if (!propertiesFile.exists()) {
- log.error("Configuration file: " + internalConfigPath + " is NOT found on filesystem");
- throw new EAAFConfigurationException("config.18", null);
-
- }
-
- final String configDir = propertiesFile.getParent();
- configRootDirectory = new File(configDir).toURI();
- log.debug("Set EAAFCore configuration root directory to " + configRootDirectory.toString());
-
-
- //get input stream from configuration path
- if (internalConfigPath.getScheme().equals(URI_SCHEME_FILESYSTEM)) {
- log.trace("Load config from filesystem");
- is = new FileInputStream(propertiesFile);
-
- } else if (internalConfigPath.getScheme().equals(URI_SCHEME_CLASSPATH)) {
- log.trace("Load config from classpath");
- is = this.getClass().getResourceAsStream(internalConfigPath.toString());
-
- } else {
- log.error("Can not load EAAFCore configuration. Unsupported prefix! (Only 'file:' and 'classpath:') ");
- throw new EAAFConfigurationException("config.24", new Object[] {internalConfigPath, "'file:'"});
-
- }
-
- if (is == null) {
- log.error("Can NOT load EAAFCore configuration from file " + internalConfigPath.toString());
- throw new EAAFConfigurationException("config.03",
- new Object[] {internalConfigPath.toString()});
-
- }
-
-
- //load EAAF core configuration into properties object
- properties = new Properties();
- properties.load(is);
-
- log.info("EAAFCore configuration loaded");
-
- } catch (URISyntaxException | IOException e) {
- log.error("Can not parse configuration path " + configPath + " or " + getBackupConfigPath());
- throw new EAAFConfigurationException("config.03", new Object[]{configPath + " or " + getBackupConfigPath()}, e);
-
- } finally {
- if (is != null) {
- try {
- is.close();
-
- } catch (final IOException e) {
- log.warn("Can not close inputstream from configuration loader!");
-
- }
- }
- }
-
- }
-
- @Override
- public String getBasicConfiguration(String key) {
- if (StringUtils.isNotEmpty(key)) {
- final String value = properties.getProperty(addPrefixToKey(key));
- if (value != null)
- return value.trim();
- }
-
- return null;
- }
-
- @Override
- public String getBasicConfiguration(String key, String defaultValue) {
- if (StringUtils.isNotEmpty(key)) {
- final String value = properties.getProperty(addPrefixToKey(key), defaultValue);
- if (value != null)
- return value.trim();
- }
-
- return defaultValue;
- }
-
-
- @Override
- public Boolean getBasicConfigurationBoolean(String key) {
- final String value = getBasicConfiguration(key);
- if (value != null)
- return Boolean.parseBoolean(value);
- else
- return null;
-
- }
-
-
- @Override
- public boolean getBasicConfigurationBoolean(String key, boolean defaultValue) {
- final Boolean result = getBasicConfigurationBoolean(key);
- if (result != null)
- return result;
- else
- return defaultValue;
-
- }
-
- @Override
- public Map<String, String> getBasicConfigurationWithPrefix(String prefix) {
- return KeyValueUtils.getSubSetWithPrefix(KeyValueUtils.convertPropertiesToMap(properties), addPrefixToKey(prefix));
-
- }
-
- @Override
- public Properties getFullConfigurationProperties() {
- return properties;
-
- }
-
- @Override
- public URI getConfigurationRootDirectory() {
- return configRootDirectory;
-
- }
-
- @Override
- public URI getConfigurationFilePath() {
- return internalConfigPath;
-
- }
-
- /**
- * Get the path to backup configuration
- *
- * @return A filepath file: or a classpath classpath:
- */
- abstract protected String getBackupConfigPath();
-
- /**
- * Get a specific configuration-key prefix for this software implementation
- *
- * @return
- */
- abstract public String getApplicationSpecificKeyPrefix();
-
-
- private String addPrefixToKey(String key) {
- if (StringUtils.isNotEmpty(getApplicationSpecificKeyPrefix())) {
- if (getApplicationSpecificKeyPrefix().endsWith(KeyValueUtils.KEY_DELIMITER))
- return getApplicationSpecificKeyPrefix() + key;
- else
- return getApplicationSpecificKeyPrefix() + KeyValueUtils.KEY_DELIMITER + key;
-
- }
-
- return key;
-
- }
+ private static final Logger log = LoggerFactory.getLogger(AbstractConfigurationImpl.class);
+
+ private static final String URI_SCHEME_CLASSPATH = "classpath";
+ private static final String URI_SCHEME_FILESYSTEM = "file";
+
+ private final URI internalConfigPath;
+ private final URI configRootDirectory;
+ private final Properties properties;
+
+ /**
+ * Basic configuration loader implementation.
+ *
+ * @param configPath Path to configuration
+ * @throws EaafConfigurationException In case of a configuration error
+ */
+ public AbstractConfigurationImpl(final String configPath) throws EaafConfigurationException {
+ InputStream is = null;
+ try {
+ log.debug("Starting EAAFCore initialization process .... ");
+
+ if (StringUtils.isEmpty(configPath)) {
+ log.debug("Primary configuration is empty. Search for backup configuration .... ");
+ final String backupConfigPath = getBackupConfigPath();
+ if (StringUtils.isEmpty(backupConfigPath)) {
+ log.error("No configuration file found.");
+ throw new EaafConfigurationException("config.01", null);
+
+ }
+
+ internalConfigPath = new URI(getBackupConfigPath());
+
+ } else {
+ internalConfigPath = new URI(configPath);
+ }
+
+ log.info("Load EAAFCore configuration from " + internalConfigPath);
+
+
+ // extract configuration root directory
+ // TODO: check if it works with classpath
+ final File propertiesFile = new File(internalConfigPath);
+ if (!propertiesFile.exists()) {
+ log.error("Configuration file: " + internalConfigPath + " is NOT found on filesystem");
+ throw new EaafConfigurationException("config.18", null);
+
+ }
+
+ final String configDir = propertiesFile.getParent();
+ configRootDirectory = new File(configDir).toURI();
+ log.debug("Set EAAFCore configuration root directory to " + configRootDirectory.toString());
+
+
+ // get input stream from configuration path
+ if (internalConfigPath.getScheme().equals(URI_SCHEME_FILESYSTEM)) {
+ log.trace("Load config from filesystem");
+ is = new FileInputStream(propertiesFile);
+
+ } else if (internalConfigPath.getScheme().equals(URI_SCHEME_CLASSPATH)) {
+ log.trace("Load config from classpath");
+ is = this.getClass().getResourceAsStream(internalConfigPath.toString());
+
+ } else {
+ log.error(
+ "Can not load EAAFCore configuration. Unsupported prefix! (Only 'file:' and 'classpath:') ");
+ throw new EaafConfigurationException("config.24",
+ new Object[] {internalConfigPath, "'file:'"});
+
+ }
+
+ if (is == null) {
+ log.error("Can NOT load EAAFCore configuration from file " + internalConfigPath.toString());
+ throw new EaafConfigurationException("config.03",
+ new Object[] {internalConfigPath.toString()});
+
+ }
+
+
+ // load EAAF core configuration into properties object
+ properties = new Properties();
+ properties.load(is);
+
+ log.info("EAAFCore configuration loaded");
+
+ } catch (URISyntaxException | IOException e) {
+ log.error("Can not parse configuration path " + configPath + " or " + getBackupConfigPath());
+ throw new EaafConfigurationException("config.03",
+ new Object[] {configPath + " or " + getBackupConfigPath()}, e);
+
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+
+ } catch (final IOException e) {
+ log.warn("Can not close inputstream from configuration loader!");
+
+ }
+ }
+ }
+
+ }
+
+ @Override
+ public String getBasicConfiguration(final String key) {
+ if (StringUtils.isNotEmpty(key)) {
+ final String value = properties.getProperty(addPrefixToKey(key));
+ if (value != null) {
+ return value.trim();
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public String getBasicConfiguration(final String key, final String defaultValue) {
+ if (StringUtils.isNotEmpty(key)) {
+ final String value = properties.getProperty(addPrefixToKey(key), defaultValue);
+ if (value != null) {
+ return value.trim();
+ }
+ }
+
+ return defaultValue;
+ }
+
+
+ @Override
+ public boolean getBasicConfigurationBoolean(final String key) {
+ final String value = getBasicConfiguration(key);
+ if (value != null) {
+ return Boolean.parseBoolean(value);
+ } else {
+ return false;
+ }
+
+ }
+
+
+ @Override
+ public boolean getBasicConfigurationBoolean(final String key, final boolean defaultValue) {
+ final Boolean result = getBasicConfigurationBoolean(key);
+ if (result != null) {
+ return result;
+ } else {
+ return defaultValue;
+ }
+
+ }
+
+ @Override
+ public Map<String, String> getBasicConfigurationWithPrefix(final String prefix) {
+ return KeyValueUtils.getSubSetWithPrefix(KeyValueUtils.convertPropertiesToMap(properties),
+ addPrefixToKey(prefix));
+
+ }
+
+ @Override
+ public Properties getFullConfigurationProperties() {
+ return properties;
+
+ }
+
+ @Override
+ public URI getConfigurationRootDirectory() {
+ return configRootDirectory;
+
+ }
+
+ @Override
+ public URI getConfigurationFilePath() {
+ return internalConfigPath;
+
+ }
+
+ /**
+ * Get the path to backup configuration.
+ *
+ * @return A filepath file: or a classpath classpath:
+ */
+ protected abstract String getBackupConfigPath();
+
+ /**
+ * Get a specific configuration-key prefix for this software implementation.
+ *
+ * @return
+ */
+ public abstract String getApplicationSpecificKeyPrefix();
+
+
+ private String addPrefixToKey(final String key) {
+ if (StringUtils.isNotEmpty(getApplicationSpecificKeyPrefix())) {
+ if (getApplicationSpecificKeyPrefix().endsWith(KeyValueUtils.KEY_DELIMITER)) {
+ return getApplicationSpecificKeyPrefix() + key;
+ } else {
+ return getApplicationSpecificKeyPrefix() + KeyValueUtils.KEY_DELIMITER + key;
+ }
+
+ }
+
+ return key;
+
+ }
}
diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/conf/AbstractSpringBootConfigurationImpl.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/conf/AbstractSpringBootConfigurationImpl.java
index dd13b534..3a6cc67d 100644
--- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/conf/AbstractSpringBootConfigurationImpl.java
+++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/conf/AbstractSpringBootConfigurationImpl.java
@@ -1,29 +1,22 @@
-/*******************************************************************************
- * Copyright 2017 Graz University of Technology
- * EAAF-Core Components has been developed in a cooperation between EGIZ,
- * A-SIT Plus, A-SIT, and Graz University of Technology.
+/*
+ * Copyright 2017 Graz University of Technology EAAF-Core Components has been developed in a
+ * cooperation between EGIZ, A-SIT Plus, A-SIT, and Graz University of Technology.
*
- * Licensed under the EUPL, Version 1.2 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:
+ * Licensed under the EUPL, Version 1.2 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:
* https://joinup.ec.europa.eu/news/understanding-eupl-v12
*
- * 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.
- *
- * This product combines work with different licenses. See the "NOTICE" text
- * file for details on the various modules and licenses.
- * The "NOTICE" text file is part of the distribution. Any derivative works
- * that you distribute must include a readable copy of the "NOTICE" text file.
- *******************************************************************************/
-/*******************************************************************************
- *******************************************************************************/
-/*******************************************************************************
- *******************************************************************************/
+ * 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.
+ *
+ * This product combines work with different licenses. See the "NOTICE" text file for details on the
+ * various modules and licenses. The "NOTICE" text file is part of the distribution. Any derivative
+ * works that you distribute must include a readable copy of the "NOTICE" text file.
+*/
+
package at.gv.egiz.eaaf.core.impl.idp.conf;
import java.net.URI;
@@ -32,9 +25,10 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
-
import javax.annotation.PostConstruct;
-
+import at.gv.egiz.eaaf.core.api.idp.IConfigurationWithSP;
+import at.gv.egiz.eaaf.core.exceptions.EaafConfigurationException;
+import at.gv.egiz.eaaf.core.impl.utils.KeyValueUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -45,175 +39,176 @@ import org.springframework.core.env.EnumerablePropertySource;
import org.springframework.core.env.Environment;
import org.springframework.core.env.PropertySource;
-import at.gv.egiz.eaaf.core.api.idp.IConfigurationWithSP;
-import at.gv.egiz.eaaf.core.exceptions.EAAFConfigurationException;
-import at.gv.egiz.eaaf.core.impl.utils.KeyValueUtils;
-
public abstract class AbstractSpringBootConfigurationImpl implements IConfigurationWithSP {
- private static final Logger log = LoggerFactory.getLogger(AbstractSpringBootConfigurationImpl.class);
-
- @Autowired private Environment env;
-
- public static final String PROP_CONFIG_ROOT_DIR = "core.configRootDir";
-
- @PostConstruct
- private void initialize() throws EAAFConfigurationException {
- if (getConfigurationRootDirectory() == null) {
- throw new EAAFConfigurationException("config.08", new Object[] {addPrefixToKey(PROP_CONFIG_ROOT_DIR)});
-
- }
-
- }
-
- @Override
- public String getBasicConfiguration(String key) {
- if (StringUtils.isNotEmpty(key)) {
- final String value = env.getProperty(addPrefixToKey(key));
- if (value != null)
- return value.trim();
- }
-
- return null;
- }
-
- @Override
- public String getBasicConfiguration(String key, String defaultValue) {
- if (StringUtils.isNotEmpty(key)) {
- final String value = env.getProperty(addPrefixToKey(key), defaultValue);
- if (value != null)
- return value.trim();
- }
-
- return defaultValue;
- }
-
- @Override
- public Map<String, String> getBasicConfigurationWithPrefix(String prefix) {
- final Map<String, String> configProps = getPropertiesStartingWith((ConfigurableEnvironment) env, addPrefixToKey(prefix));
- return KeyValueUtils.removePrefixFromKeys(configProps, addPrefixToKey(prefix) + ".");
-
-
- }
-
- @Override
- public Boolean getBasicConfigurationBoolean(String key) {
- final String value = getBasicConfiguration(key);
- if (StringUtils.isNotEmpty(value))
- return Boolean.valueOf(value.trim());
- else
- return null;
- }
-
- @Override
- public boolean getBasicConfigurationBoolean(String key, boolean defaultValue) {
- final Boolean value = getBasicConfigurationBoolean(key);
- if (value != null)
- return value;
- else
- return defaultValue;
- }
-
- @Override
- public URI getConfigurationRootDirectory() {
- try {
- return new URI(env.getRequiredProperty(addPrefixToKey(PROP_CONFIG_ROOT_DIR)));
-
- } catch (IllegalStateException | URISyntaxException e) {
- log.warn("ConfigRootDirectory is NOT set");
- return null;
-
- }
-
- }
-
-
- /**
- * Get the path to backup configuration
- *
- * @return A filepath file: or a classpath classpath:
- */
- abstract protected String getBackupConfigPath();
-
- /**
- * Get a specific configuration-key prefix for this software implementation
- *
- * @return
- */
- abstract public String getApplicationSpecificKeyPrefix();
-
-
- private String addPrefixToKey(String key) {
- if (StringUtils.isNotEmpty(getApplicationSpecificKeyPrefix())) {
- if (getApplicationSpecificKeyPrefix().endsWith(KeyValueUtils.KEY_DELIMITER))
- return getApplicationSpecificKeyPrefix() + key;
- else
- return getApplicationSpecificKeyPrefix() + KeyValueUtils.KEY_DELIMITER + key;
-
- }
-
- return key;
-
- }
-
- private static Map<String, String> getPropertiesStartingWith( ConfigurableEnvironment aEnv, String aKeyPrefix ) {
- final Map<String,String> result = new HashMap<>();
- final Map<String,Object> map = getAllProperties(aEnv);
-
- for (final Entry<String, Object> entry : map.entrySet()) {
- final String key = entry.getKey();
-
- if ( key.startsWith( aKeyPrefix ) )
- {
- result.put( key, (String) entry.getValue() );
- }
- }
-
- return result;
- }
-
- private static Map<String,Object> getAllProperties( ConfigurableEnvironment aEnv ) {
- final Map<String,Object> result = new HashMap<>();
- aEnv.getPropertySources().forEach( ps -> addAll( result, getAllProperties( ps ) ) );
- return result;
-
- }
-
- private static Map<String,Object> getAllProperties( PropertySource<?> aPropSource ) {
- final Map<String,Object> result = new HashMap<>();
-
- if ( aPropSource instanceof CompositePropertySource)
- {
- final CompositePropertySource cps = (CompositePropertySource) aPropSource;
- cps.getPropertySources().forEach( ps -> addAll( result, getAllProperties( ps ) ) );
- return result;
- }
-
- if ( aPropSource instanceof EnumerablePropertySource<?> )
- {
- final EnumerablePropertySource<?> ps = (EnumerablePropertySource<?>) aPropSource;
- Arrays.asList( ps.getPropertyNames() ).forEach( key -> result.put( key, ps.getProperty( key ) ) );
- return result;
- }
-
- // note: Most descendants of PropertySource are EnumerablePropertySource. There are some
- // few others like JndiPropertySource or StubPropertySource
- log.debug( "Given PropertySource is instanceof " + aPropSource.getClass().getName()
- + " and cannot be iterated" );
-
- return result;
-
- }
-
- private static void addAll( Map<String, Object> aBase, Map<String, Object> aToBeAdded )
- {
- for (final Entry<String, Object> entry : aToBeAdded.entrySet())
- {
- if ( aBase.containsKey( entry.getKey() ) )
- {
- continue;
- }
-
- aBase.put( entry.getKey(), entry.getValue() );
- }
- }
+ private static final Logger log =
+ LoggerFactory.getLogger(AbstractSpringBootConfigurationImpl.class);
+
+ @Autowired
+ private Environment env;
+
+ public static final String PROP_CONFIG_ROOT_DIR = "core.configRootDir";
+
+ @PostConstruct
+ private void initialize() throws EaafConfigurationException {
+ if (getConfigurationRootDirectory() == null) {
+ throw new EaafConfigurationException("config.08",
+ new Object[] {addPrefixToKey(PROP_CONFIG_ROOT_DIR)});
+
+ }
+
+ }
+
+ @Override
+ public String getBasicConfiguration(final String key) {
+ if (StringUtils.isNotEmpty(key)) {
+ final String value = env.getProperty(addPrefixToKey(key));
+ if (value != null) {
+ return value.trim();
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public String getBasicConfiguration(final String key, final String defaultValue) {
+ if (StringUtils.isNotEmpty(key)) {
+ final String value = env.getProperty(addPrefixToKey(key), defaultValue);
+ if (value != null) {
+ return value.trim();
+ }
+ }
+
+ return defaultValue;
+ }
+
+ @Override
+ public Map<String, String> getBasicConfigurationWithPrefix(final String prefix) {
+ final Map<String, String> configProps =
+ getPropertiesStartingWith((ConfigurableEnvironment) env, addPrefixToKey(prefix));
+ return KeyValueUtils.removePrefixFromKeys(configProps, addPrefixToKey(prefix) + ".");
+
+
+ }
+
+ @Override
+ public boolean getBasicConfigurationBoolean(final String key) {
+ final String value = getBasicConfiguration(key);
+ if (StringUtils.isNotEmpty(value)) {
+ return Boolean.valueOf(value.trim());
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean getBasicConfigurationBoolean(final String key, final boolean defaultValue) {
+ final Boolean value = getBasicConfigurationBoolean(key);
+ if (value != null) {
+ return value;
+ } else {
+ return defaultValue;
+ }
+ }
+
+ @Override
+ public URI getConfigurationRootDirectory() {
+ try {
+ return new URI(env.getRequiredProperty(addPrefixToKey(PROP_CONFIG_ROOT_DIR)));
+
+ } catch (IllegalStateException | URISyntaxException e) {
+ log.warn("ConfigRootDirectory is NOT set");
+ return null;
+
+ }
+
+ }
+
+
+ /**
+ * Get the path to backup configuration.
+ *
+ * @return A filepath file: or a classpath classpath:
+ */
+ protected abstract String getBackupConfigPath();
+
+ /**
+ * Get a specific configuration-key prefix for this software implementation.
+ *
+ * @return
+ */
+ public abstract String getApplicationSpecificKeyPrefix();
+
+
+ private String addPrefixToKey(final String key) {
+ if (StringUtils.isNotEmpty(getApplicationSpecificKeyPrefix())) {
+ if (getApplicationSpecificKeyPrefix().endsWith(KeyValueUtils.KEY_DELIMITER)) {
+ return getApplicationSpecificKeyPrefix() + key;
+ } else {
+ return getApplicationSpecificKeyPrefix() + KeyValueUtils.KEY_DELIMITER + key;
+ }
+
+ }
+
+ return key;
+
+ }
+
+ private static Map<String, String> getPropertiesStartingWith(final ConfigurableEnvironment aenv,
+ final String akeyPrefix) {
+ final Map<String, String> result = new HashMap<>();
+ final Map<String, Object> map = getAllProperties(aenv);
+
+ for (final Entry<String, Object> entry : map.entrySet()) {
+ final String key = entry.getKey();
+
+ if (key.startsWith(akeyPrefix)) {
+ result.put(key, (String) entry.getValue());
+ }
+ }
+
+ return result;
+ }
+
+ private static Map<String, Object> getAllProperties(final ConfigurableEnvironment aenv) {
+ final Map<String, Object> result = new HashMap<>();
+ aenv.getPropertySources().forEach(ps -> addAll(result, getAllProperties(ps)));
+ return result;
+
+ }
+
+ private static Map<String, Object> getAllProperties(final PropertySource<?> apropSource) {
+ final Map<String, Object> result = new HashMap<>();
+
+ if (apropSource instanceof CompositePropertySource) {
+ final CompositePropertySource cps = (CompositePropertySource) apropSource;
+ cps.getPropertySources().forEach(ps -> addAll(result, getAllProperties(ps)));
+ return result;
+ }
+
+ if (apropSource instanceof EnumerablePropertySource<?>) {
+ final EnumerablePropertySource<?> ps = (EnumerablePropertySource<?>) apropSource;
+ Arrays.asList(ps.getPropertyNames()).forEach(key -> result.put(key, ps.getProperty(key)));
+ return result;
+ }
+
+ // note: Most descendants of PropertySource are EnumerablePropertySource. There are some
+ // few others like JndiPropertySource or StubPropertySource
+ log.debug("Given PropertySource is instanceof " + apropSource.getClass().getName()
+ + " and cannot be iterated");
+
+ return result;
+
+ }
+
+ private static void addAll(final Map<String, Object> abase,
+ final Map<String, Object> atoBeAdded) {
+ for (final Entry<String, Object> entry : atoBeAdded.entrySet()) {
+ if (abase.containsKey(entry.getKey())) {
+ continue;
+ }
+
+ abase.put(entry.getKey(), entry.getValue());
+ }
+ }
}
diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/conf/SPConfigurationImpl.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/conf/SPConfigurationImpl.java
deleted file mode 100644
index 1b99ce50..00000000
--- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/conf/SPConfigurationImpl.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/*******************************************************************************
- * Copyright 2017 Graz University of Technology
- * EAAF-Core Components has been developed in a cooperation between EGIZ,
- * A-SIT Plus, A-SIT, and Graz University of Technology.
- *
- * Licensed under the EUPL, Version 1.2 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:
- * https://joinup.ec.europa.eu/news/understanding-eupl-v12
- *
- * 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.
- *
- * This product combines work with different licenses. See the "NOTICE" text
- * file for details on the various modules and licenses.
- * The "NOTICE" text file is part of the distribution. Any derivative works
- * that you distribute must include a readable copy of the "NOTICE" text file.
- *******************************************************************************/
-/*******************************************************************************
- *******************************************************************************/
-/*******************************************************************************
- *******************************************************************************/
-package at.gv.egiz.eaaf.core.impl.idp.conf;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import at.gv.egiz.eaaf.core.api.data.EAAFConfigConstants;
-import at.gv.egiz.eaaf.core.api.data.EAAFConstants;
-import at.gv.egiz.eaaf.core.api.idp.IConfiguration;
-import at.gv.egiz.eaaf.core.api.idp.ISPConfiguration;
-import at.gv.egiz.eaaf.core.impl.utils.KeyValueUtils;
-
-public class SPConfigurationImpl implements ISPConfiguration {
- private static final long serialVersionUID = 688541755446463453L;
-
- private static final Logger log = LoggerFactory.getLogger(SPConfigurationImpl.class);
-
- private final Map<String, String> spConfiguration;
- private final List<String> targetAreasWithNoInteralBaseIdRestriction;
- private final List<String> targetAreasWithNoBaseIdTransmissionRestriction;
-
- public SPConfigurationImpl(final Map<String, String> spConfig, IConfiguration authConfig) {
- this.spConfiguration = spConfig;
-
- //set oa specific restrictions
- targetAreasWithNoInteralBaseIdRestriction = Collections.unmodifiableList(
- KeyValueUtils.getListOfCSVValues(
- authConfig.getBasicConfiguration(
- CONFIG_KEY_RESTRICTIONS_BASEID_INTERNAL,
- EAAFConstants.URN_PREFIX_CDID)));
-
- targetAreasWithNoBaseIdTransmissionRestriction = Collections.unmodifiableList(
- KeyValueUtils.getListOfCSVValues(
- authConfig.getBasicConfiguration(
- CONFIG_KEY_RESTRICTIONS_BASEID_TRANSMISSION,
- EAAFConstants.URN_PREFIX_CDID)));
-
- if (log.isTraceEnabled()) {
- log.trace("Internal policy for OA: " + getUniqueIdentifier());
- for (String el : targetAreasWithNoInteralBaseIdRestriction)
- log.trace(" Allow baseID processing for prefix " + el);
- for (String el : targetAreasWithNoBaseIdTransmissionRestriction)
- log.trace(" Allow baseID transfer for prefix " + el);
-
- }
- }
-
-
- @Override
- public final Map<String, String> getFullConfiguration() {
- return this.spConfiguration;
-
- }
-
- @Override
- public final String getConfigurationValue(String key) {
- if (key == null)
- return null;
- else
- return this.spConfiguration.get(key);
-
- }
-
- @Override
- public final String getConfigurationValue(String key, String defaultValue) {
- String value = getConfigurationValue(key);
- if (value == null)
- return defaultValue;
- else
- return value;
- }
-
-
- @Override
- public final Boolean isConfigurationValue(String key) {
- String value = getConfigurationValue(key);
- if (value != null) {
- return Boolean.parseBoolean(value);
-
- }
-
- return null;
- }
-
-
- @Override
- public final boolean isConfigurationValue(String key, boolean defaultValue) {
- String value = getConfigurationValue(key);
- if (value != null) {
- return Boolean.parseBoolean(value);
-
- }
-
- return defaultValue;
- }
-
- @Override
- public final boolean containsConfigurationKey(String key) {
- if (key == null)
- return false;
- else
- return this.spConfiguration.containsKey(key);
-
- }
-
- @Override
- public String getUniqueIdentifier() {
- return getConfigurationValue(EAAFConfigConstants.SERVICE_UNIQUEIDENTIFIER);
-
- }
-
- @Override
- public boolean hasBaseIdInternalProcessingRestriction() {
- return false;
-
- }
-
- @Override
- public boolean hasBaseIdTransferRestriction() {
- return true;
-
- }
-
-
- @Override
- public final List<String> getTargetsWithNoBaseIdInternalProcessingRestriction() {
- return this.targetAreasWithNoInteralBaseIdRestriction;
- }
-
-
- @Override
- public final List<String> getTargetsWithNoBaseIdTransferRestriction() {
- return this.targetAreasWithNoBaseIdTransmissionRestriction;
- }
-
-
- @Override
- public List<String> getRequiredLoA() {
- log.warn("Method not implemented: " + SPConfigurationImpl.class.getName() + " 'getRequiredLoA()'");
- return null;
- }
-
- @Override
- public String getLoAMatchingMode() {
- log.warn("Method not implemented: " + SPConfigurationImpl.class.getName() + " 'getLoAMatchingMode()'");
- return null;
- }
-
- @Override
- public String getAreaSpecificTargetIdentifier() {
- log.warn("Method not implemented: " + SPConfigurationImpl.class.getName() + " 'getAreaSpecificTargetIdentifier()'");
- return null;
- }
-
-
- @Override
- public String getFriendlyName() {
- log.warn("Method not implemented: " + SPConfigurationImpl.class.getName() + " 'getFriendlyName()'");
- return null;
- }
-
-}
diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/conf/SpConfigurationImpl.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/conf/SpConfigurationImpl.java
new file mode 100644
index 00000000..07284cd3
--- /dev/null
+++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/conf/SpConfigurationImpl.java
@@ -0,0 +1,193 @@
+/*
+ * Copyright 2017 Graz University of Technology EAAF-Core Components has been developed in a
+ * cooperation between EGIZ, A-SIT Plus, A-SIT, and Graz University of Technology.
+ *
+ * Licensed under the EUPL, Version 1.2 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:
+ * https://joinup.ec.europa.eu/news/understanding-eupl-v12
+ *
+ * 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.
+ *
+ * This product combines work with different licenses. See the "NOTICE" text file for details on the
+ * various modules and licenses. The "NOTICE" text file is part of the distribution. Any derivative
+ * works that you distribute must include a readable copy of the "NOTICE" text file.
+*/
+
+package at.gv.egiz.eaaf.core.impl.idp.conf;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import at.gv.egiz.eaaf.core.api.data.EAAFConfigConstants;
+import at.gv.egiz.eaaf.core.api.data.EAAFConstants;
+import at.gv.egiz.eaaf.core.api.idp.IConfiguration;
+import at.gv.egiz.eaaf.core.api.idp.IspConfiguration;
+import at.gv.egiz.eaaf.core.impl.utils.KeyValueUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SpConfigurationImpl implements IspConfiguration {
+ private static final long serialVersionUID = 688541755446463453L;
+
+ private static final Logger log = LoggerFactory.getLogger(SpConfigurationImpl.class);
+
+ private final Map<String, String> spConfiguration;
+ private final List<String> targetAreasWithNoInteralBaseIdRestriction;
+ private final List<String> targetAreasWithNoBaseIdTransmissionRestriction;
+
+ /**
+ * Service-provider configuration holder.
+ *
+ * @param spConfig Key/value based configuration
+ * @param authConfig Basic application configuration
+ */
+ public SpConfigurationImpl(final Map<String, String> spConfig, final IConfiguration authConfig) {
+ this.spConfiguration = spConfig;
+
+ // set oa specific restrictions
+ targetAreasWithNoInteralBaseIdRestriction = Collections
+ .unmodifiableList(KeyValueUtils.getListOfCsvValues(authConfig.getBasicConfiguration(
+ CONFIG_KEY_RESTRICTIONS_BASEID_INTERNAL, EAAFConstants.URN_PREFIX_CDID)));
+
+ targetAreasWithNoBaseIdTransmissionRestriction = Collections
+ .unmodifiableList(KeyValueUtils.getListOfCsvValues(authConfig.getBasicConfiguration(
+ CONFIG_KEY_RESTRICTIONS_BASEID_TRANSMISSION, EAAFConstants.URN_PREFIX_CDID)));
+
+ if (log.isTraceEnabled()) {
+ log.trace("Internal policy for OA: " + getUniqueIdentifier());
+ for (final String el : targetAreasWithNoInteralBaseIdRestriction) {
+ log.trace(" Allow baseID processing for prefix " + el);
+ }
+ for (final String el : targetAreasWithNoBaseIdTransmissionRestriction) {
+ log.trace(" Allow baseID transfer for prefix " + el);
+ }
+
+ }
+ }
+
+
+ @Override
+ public final Map<String, String> getFullConfiguration() {
+ return this.spConfiguration;
+
+ }
+
+ @Override
+ public final String getConfigurationValue(final String key) {
+ if (key == null) {
+ return null;
+ } else {
+ return this.spConfiguration.get(key);
+ }
+
+ }
+
+ @Override
+ public final String getConfigurationValue(final String key, final String defaultValue) {
+ final String value = getConfigurationValue(key);
+ if (value == null) {
+ return defaultValue;
+ } else {
+ return value;
+ }
+ }
+
+
+ @Override
+ public final boolean isConfigurationValue(final String key) {
+ final String value = getConfigurationValue(key);
+ if (value != null) {
+ return Boolean.parseBoolean(value);
+
+ }
+
+ return false;
+ }
+
+
+ @Override
+ public final boolean isConfigurationValue(final String key, final boolean defaultValue) {
+ final String value = getConfigurationValue(key);
+ if (value != null) {
+ return Boolean.parseBoolean(value);
+
+ }
+
+ return defaultValue;
+ }
+
+ @Override
+ public final boolean containsConfigurationKey(final String key) {
+ if (key == null) {
+ return false;
+ } else {
+ return this.spConfiguration.containsKey(key);
+ }
+
+ }
+
+ @Override
+ public String getUniqueIdentifier() {
+ return getConfigurationValue(EAAFConfigConstants.SERVICE_UNIQUEIDENTIFIER);
+
+ }
+
+ @Override
+ public boolean hasBaseIdInternalProcessingRestriction() {
+ return false;
+
+ }
+
+ @Override
+ public boolean hasBaseIdTransferRestriction() {
+ return true;
+
+ }
+
+
+ @Override
+ public final List<String> getTargetsWithNoBaseIdInternalProcessingRestriction() {
+ return this.targetAreasWithNoInteralBaseIdRestriction;
+ }
+
+
+ @Override
+ public final List<String> getTargetsWithNoBaseIdTransferRestriction() {
+ return this.targetAreasWithNoBaseIdTransmissionRestriction;
+ }
+
+
+ @Override
+ public List<String> getRequiredLoA() {
+ log.warn(
+ "Method not implemented: " + SpConfigurationImpl.class.getName() + " 'getRequiredLoA()'");
+ return null;
+ }
+
+ @Override
+ public String getLoAMatchingMode() {
+ log.warn("Method not implemented: " + SpConfigurationImpl.class.getName()
+ + " 'getLoAMatchingMode()'");
+ return null;
+ }
+
+ @Override
+ public String getAreaSpecificTargetIdentifier() {
+ log.warn("Method not implemented: " + SpConfigurationImpl.class.getName()
+ + " 'getAreaSpecificTargetIdentifier()'");
+ return null;
+ }
+
+
+ @Override
+ public String getFriendlyName() {
+ log.warn(
+ "Method not implemented: " + SpConfigurationImpl.class.getName() + " 'getFriendlyName()'");
+ return null;
+ }
+
+}