aboutsummaryrefslogtreecommitdiff
path: root/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/config/BasicConfigurationProvider.java
diff options
context:
space:
mode:
Diffstat (limited to 'connector_lib/src/main/java/at/asitplus/eidas/specific/connector/config/BasicConfigurationProvider.java')
-rw-r--r--connector_lib/src/main/java/at/asitplus/eidas/specific/connector/config/BasicConfigurationProvider.java219
1 files changed, 114 insertions, 105 deletions
diff --git a/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/config/BasicConfigurationProvider.java b/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/config/BasicConfigurationProvider.java
index 4a9bc8e4..355c63f2 100644
--- a/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/config/BasicConfigurationProvider.java
+++ b/connector_lib/src/main/java/at/asitplus/eidas/specific/connector/config/BasicConfigurationProvider.java
@@ -1,6 +1,6 @@
-/*******************************************************************************
+/*
* Copyright 2018 A-SIT Plus GmbH
- * AT-specific eIDAS Connector has been developed in a cooperation between EGIZ,
+ * AT-specific eIDAS Connector has been developed in a cooperation between EGIZ,
* A-SIT Plus GmbH, A-SIT, and Graz University of Technology.
*
* Licensed under the EUPL, Version 1.2 or - as soon they will be approved by
@@ -19,21 +19,21 @@
* 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.asitplus.eidas.specific.connector.config;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
+import java.util.Map.Entry;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
-import at.asitplus.eidas.specific.connector.MSeIDASNodeConstants;
+import at.asitplus.eidas.specific.connector.MsEidasNodeConstants;
import at.gv.egiz.eaaf.core.api.idp.ISpConfiguration;
import at.gv.egiz.eaaf.core.exceptions.EaafConfigurationException;
import at.gv.egiz.eaaf.core.exceptions.EaafException;
@@ -41,104 +41,113 @@ import at.gv.egiz.eaaf.core.impl.idp.conf.AbstractConfigurationImpl;
import at.gv.egiz.eaaf.core.impl.utils.KeyValueUtils;
@Service("BasicMSSpecificNodeConfig")
-public class BasicConfigurationProvider extends AbstractConfigurationImpl{
- private static final Logger log = LoggerFactory.getLogger(BasicConfigurationProvider.class);
-
- private Map<String, ISpConfiguration> spConfigCache = new HashMap<String, ISpConfiguration>();
-
- public BasicConfigurationProvider(String configPath) throws EaafConfigurationException {
- super(configPath);
-
- }
-
- @Override
- public ISpConfiguration getServiceProviderConfiguration(String entityId) throws EaafConfigurationException {
- if (!spConfigCache.containsKey(entityId)) {
- log.debug("SP: " + entityId + " is NOT cached. Starting load operation ... ");
- Map<String, String> allSPs = getBasicConfigurationWithPrefix(MSeIDASNodeConstants.PROP_CONFIG_SP_LIST_PREFIX);
- for (String key : allSPs.keySet()) {
- if (key.endsWith(MSeIDASNodeConstants.PROP_CONFIG_SP_UNIQUEIDENTIFIER) &&
- allSPs.get(key).equals(entityId)) {
- String listId = KeyValueUtils.getParentKey(key);
- log.trace("Find SP configuration with list-Id: " + listId + ". Extracting configuration elements ... ");
- Map<String, String> spConfig = KeyValueUtils.getSubSetWithPrefix(allSPs, listId + KeyValueUtils.KEY_DELIMITER);
- spConfigCache.put(entityId,
- new ServiceProviderConfiguration(spConfig, this));
- break;
- }
- }
-
- if (spConfigCache.containsKey(entityId))
- log.info("SP: " + entityId + " is loaded. Continuing auth. process ... ");
- else {
- log.warn("SP: " + entityId + " is NOT found in configuration. Stopping auth. process ... ");
- return null;
-
- }
-
- } else
- log.trace("SP: " + entityId + " is already cached. Use configuration from there ... ");
-
-
- return spConfigCache.get(entityId);
- }
-
- @Override
- public <T> T getServiceProviderConfiguration(String entityId, Class<T> decorator) throws EaafConfigurationException {
- ISpConfiguration spConfig = getServiceProviderConfiguration(entityId);
- if (spConfig != null && decorator != null) {
- if (decorator.isInstance(spConfig))
- return (T)spConfig;
- else
- log.error("SPConfig: " + spConfig.getClass().getName() + " is NOT instance of: " + decorator.getName());
-
- }
-
- return null;
-
- }
-
- @Override
- public String validateIdpUrl(URL url) throws EaafException {
- log.trace("Validate requested URL: " + url);
- String urlPrefixFromConfig = getBasicConfiguration(MSeIDASNodeConstants.PROP_CONFIG_APPLICATION_PUBLIC_URL_PREFIX);
- if (StringUtils.isEmpty(urlPrefixFromConfig)) {
- log.warn("Application config containts NO URL prefix");
- throw new EaafConfigurationException("config.27",
- new Object[] {"Application config containts NO "
- + getApplicationSpecificKeyPrefix() + MSeIDASNodeConstants.PROP_CONFIG_APPLICATION_PUBLIC_URL_PREFIX });
-
- }
-
- //remove last slash
- if (urlPrefixFromConfig.endsWith("/"))
- urlPrefixFromConfig = urlPrefixFromConfig.substring(0, urlPrefixFromConfig.length()-1);
-
- if (getBasicConfigurationBoolean(
- MSeIDASNodeConstants.PROP_CONFIG_APPLICATION_PUBLIC_URL_REQUEST_VALIDATION, false)) {
- if (url != null && url.toExternalForm().startsWith(urlPrefixFromConfig))
- return urlPrefixFromConfig;
-
- log.info("URL: " + url + " does NOT match to allowed application prefix: " + urlPrefixFromConfig);
- return null;
-
- } else {
- return urlPrefixFromConfig;
-
- }
- }
-
- @Override
- public String getApplicationSpecificKeyPrefix() {
- return MSeIDASNodeConstants.PROP_CONFIG_APPLICATION_PREFIX;
-
- }
-
- @Override
- protected String getBackupConfigPath() {
- return null;
-
- }
-
+public class BasicConfigurationProvider extends AbstractConfigurationImpl {
+ private static final Logger log = LoggerFactory.getLogger(BasicConfigurationProvider.class);
+
+ private final Map<String, ISpConfiguration> spConfigCache = new HashMap<>();
+
+ public BasicConfigurationProvider(String configPath) throws EaafConfigurationException {
+ super(configPath);
+
+ }
+
+ @Override
+ public ISpConfiguration getServiceProviderConfiguration(String entityId) throws EaafConfigurationException {
+ if (!spConfigCache.containsKey(entityId)) {
+ log.debug("SP: " + entityId + " is NOT cached. Starting load operation ... ");
+ final Map<String, String> allSPs = getBasicConfigurationWithPrefix(
+ MsEidasNodeConstants.PROP_CONFIG_SP_LIST_PREFIX);
+ for (Entry<String, String> entry : allSPs.entrySet()) {
+ if (entry.getKey().endsWith(MsEidasNodeConstants.PROP_CONFIG_SP_UNIQUEIDENTIFIER)
+ && entry.getValue().equals(entityId)) {
+ final String listId = KeyValueUtils.getParentKey(entry.getKey());
+ log.trace("Find SP configuration with list-Id: " + listId
+ + ". Extracting configuration elements ... ");
+ final Map<String, String> spConfig = KeyValueUtils.getSubSetWithPrefix(allSPs, listId
+ + KeyValueUtils.KEY_DELIMITER);
+ spConfigCache.put(entityId,
+ new ServiceProviderConfiguration(spConfig, this));
+ break;
+ }
+ }
+
+ if (spConfigCache.containsKey(entityId)) {
+ log.info("SP: " + entityId + " is loaded. Continuing auth. process ... ");
+ } else {
+ log.warn("SP: " + entityId + " is NOT found in configuration. Stopping auth. process ... ");
+ return null;
+
+ }
+
+ } else {
+ log.trace("SP: " + entityId + " is already cached. Use configuration from there ... ");
+ }
+
+ return spConfigCache.get(entityId);
+ }
+
+ @Override
+ public <T> T getServiceProviderConfiguration(String entityId, Class<T> decorator)
+ throws EaafConfigurationException {
+ final ISpConfiguration spConfig = getServiceProviderConfiguration(entityId);
+ if (spConfig != null && decorator != null) {
+ if (decorator.isInstance(spConfig)) {
+ return (T) spConfig;
+ } else {
+ log.error("SPConfig: " + spConfig.getClass().getName() + " is NOT instance of: " + decorator
+ .getName());
+ }
+
+ }
+
+ return null;
+
+ }
+
+ @Override
+ public String validateIdpUrl(URL url) throws EaafException {
+ log.trace("Validate requested URL: " + url);
+ String urlPrefixFromConfig = getBasicConfiguration(
+ MsEidasNodeConstants.PROP_CONFIG_APPLICATION_PUBLIC_URL_PREFIX);
+ if (StringUtils.isEmpty(urlPrefixFromConfig)) {
+ log.warn("Application config containts NO URL prefix");
+ throw new EaafConfigurationException("config.27",
+ new Object[] { "Application config containts NO "
+ + getApplicationSpecificKeyPrefix()
+ + MsEidasNodeConstants.PROP_CONFIG_APPLICATION_PUBLIC_URL_PREFIX });
+
+ }
+
+ // remove last slash
+ if (urlPrefixFromConfig.endsWith("/")) {
+ urlPrefixFromConfig = urlPrefixFromConfig.substring(0, urlPrefixFromConfig.length() - 1);
+ }
+
+ if (getBasicConfigurationBoolean(
+ MsEidasNodeConstants.PROP_CONFIG_APPLICATION_PUBLIC_URL_REQUEST_VALIDATION, false)) {
+ if (url != null && url.toExternalForm().startsWith(urlPrefixFromConfig)) {
+ return urlPrefixFromConfig;
+ }
+
+ log.info("URL: " + url + " does NOT match to allowed application prefix: " + urlPrefixFromConfig);
+ return null;
+
+ } else {
+ return urlPrefixFromConfig;
+
+ }
+ }
+
+ @Override
+ public String getApplicationSpecificKeyPrefix() {
+ return MsEidasNodeConstants.PROP_CONFIG_APPLICATION_PREFIX;
+
+ }
+
+ @Override
+ protected String getBackupConfigPath() {
+ return null;
+
+ }
}