/* * 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.config.webgui; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.util.Properties; import org.opensaml.DefaultBootstrap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import at.gv.egiz.eaaf.core.impl.utils.FileUtils; import at.gv.egovernment.moa.id.commons.config.MOAIDConfigurationConstants; import at.gv.egovernment.moa.id.config.webgui.exception.ConfigurationException; import at.gv.egovernment.moa.util.MiscUtil; /** * @author tlenz * */ @Service public class MOAIDWebGUIConfiguration { private static final String SYSTEM_PROP_CONFIG = "moa.id.webconfig"; private static final Logger log = LoggerFactory.getLogger(MOAIDWebGUIConfiguration.class); private Properties props; private String configFileName; private String configRootDir; /* (non-Javadoc) * @see at.gv.egovernment.moa.id.commons.config.persistence.LocalConfigurationBean#getLocalDatabaseProperties() */ private static MOAIDWebGUIConfiguration instance = null; public static MOAIDWebGUIConfiguration getInstance() throws ConfigurationException { if (instance == null) { instance = new MOAIDWebGUIConfiguration(); } return instance; } MOAIDWebGUIConfiguration() throws ConfigurationException { configFileName = System.getProperty(SYSTEM_PROP_CONFIG); if (configFileName == null) { throw new ConfigurationException("config.05"); } try { URI fileURI = new URI(configFileName); // determine the directory of the root config file configRootDir = new File(fileURI).getParent(); log.info("Loading MOA-ID WebGUI configuration from file " + fileURI); //Load MOAID-2.0 properties file File propertiesFile = new File(fileURI); FileInputStream fis; props = new Properties(); fis = new FileInputStream(propertiesFile); props.load(fis); fis.close(); log.debug("OpenSAML initialization started ..."); DefaultBootstrap.bootstrap(); log.info("OpenSAML initialization complete."); log.info("Pre-Initialization step of MOA-ID WebGUI module finished ... "); } catch (FileNotFoundException e) { throw new ConfigurationException("config.01", new Object[]{configFileName}, e); } catch (IOException e) { throw new ConfigurationException("config.02", new Object[]{configFileName}, e); } catch (org.opensaml.xml.ConfigurationException e) { throw new ConfigurationException("config.04", e); } catch (URISyntaxException e) { throw new ConfigurationException("config.06", new Object[]{MOAIDConfigurationConstants.FILE_URI_PREFIX, configFileName}, e); } } // @Override // protected Properties getLocalDatabaseProperties() { // return this.props; // } public String getConfigFile() { return configFileName; } public String getConfigRootDir() { return configRootDir; } public String getCertStoreDirectory() throws ConfigurationException { String dir = props.getProperty("general.ssl.certstore"); if (MiscUtil.isNotEmpty(dir)) return FileUtils.makeAbsoluteURL(dir, configRootDir); else throw new ConfigurationException("No SSLCertStore configured use default JAVA TrustStore."); } public String getTrustStoreDirectory() throws ConfigurationException { String dir = props.getProperty("general.ssl.truststore"); if (MiscUtil.isNotEmpty(dir)) return FileUtils.makeAbsoluteURL(dir, configRootDir); else throw new ConfigurationException("No SSLTrustStore configured use default JAVA TrustStore."); } public boolean isPVPMetadataSchemaValidationActive() { return Boolean.parseBoolean(props.getProperty("general.pvp.schemavalidation", "true")); } }