/******************************************************************************* *******************************************************************************/ package at.gv.egiz.eidas.specific.connector.config; import java.net.URL; import java.util.HashMap; import java.util.Map; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; 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; import at.gv.egiz.eaaf.core.impl.idp.conf.AbstractConfigurationImpl; import at.gv.egiz.eaaf.core.impl.utils.KeyValueUtils; import at.gv.egiz.eidas.specific.connector.MSeIDASNodeConstants; @Service("BasicMSSpecificNodeConfig") public class BasicConfigurationProvider extends AbstractConfigurationImpl{ private static final Logger log = LoggerFactory.getLogger(BasicConfigurationProvider.class); private Map 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 ... "); Map allSPs = getBasicMOAIDConfigurationWithPrefix(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 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 getServiceProviderConfiguration(String entityId, Class 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 (getBasicMOAIDConfigurationBoolean( 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; } }