/* * Copyright 2014 Federal Chancellery Austria * MOA-ID has been developed in a cooperation between BRZ, the Federal * Chancellery Austria - ICT staff unit, and Graz University of Technology. * * 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/ * * 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.egovernment.moa.id.auth.modules.eidas.config; import java.io.File; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Map.Entry; import java.util.Properties; import at.gv.egiz.eaaf.core.impl.utils.FileUtils; import at.gv.egovernment.moa.id.commons.api.exceptions.ConfigurationException; import at.gv.egovernment.moa.id.config.auth.AuthConfigurationProviderFactory; import at.gv.egovernment.moa.logging.Logger; import eu.eidas.samlengineconfig.ConfigurationParameter; import eu.eidas.samlengineconfig.InstanceConfiguration; import eu.eidas.samlengineconfig.StringParameter; /** * @author tlenz * */ public class MOAeIDASSAMLInstanceConfigurationImpl extends InstanceConfiguration { public void addParameter(ConfigurationParameter param) { if (param != null) { List paramList = super.getParameters(); if (paramList == null) { paramList = new ArrayList(); super.setParameters(paramList); } paramList.add(param); } } public void addParameter(String key, String value) { StringParameter param = new StringParameter(); param.setName(key); param.setValue(value); addParameter(param); } public void addParameter(Properties parameters) { Iterator> paramInterator = parameters.entrySet().iterator(); while (paramInterator.hasNext()) { Entry next = paramInterator.next(); StringParameter param = new StringParameter(); String keyName = (String) next.getKey(); param.setName(keyName); //make path to binary files absolute if (Arrays.asList(MOAeIDASSAMLEngineConfigurationImpl.BINARY_PARAMETERS).contains(keyName)) try { String absoluteConfigFile = FileUtils.makeAbsoluteURL( (String)next.getValue(), AuthConfigurationProviderFactory.getInstance().getRootConfigFileDir()); URI uri = new URL(absoluteConfigFile).toURI(); File file = new File(uri); if (file.exists()) param.setValue(file.getCanonicalPath()); else { Logger.error("eIDAS-configuration fileparameter with key:" + param.getName() + " and path:" + uri.toString() + " NOT exist!"); param.setValue(null); } } catch (ConfigurationException | URISyntaxException | IOException e) { //TODO: make final!!!! e.printStackTrace(); param.setValue(next.getValue()); } else param.setValue(next.getValue()); addParameter(param); } } }