/*******************************************************************************
* 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.
******************************************************************************/
/*
* Copyright 2003 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;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Map;
import java.util.Properties;
import at.gv.egiz.eaaf.core.exceptions.EAAFConfigurationException;
import at.gv.egiz.eaaf.core.impl.idp.conf.AbstractConfigurationImpl;
import at.gv.egiz.eaaf.modules.pvp2.impl.opensaml.initialize.EAAFDefaultSAML2Bootstrap;
import at.gv.egovernment.moa.id.commons.api.ConfigurationProvider;
import at.gv.egovernment.moa.id.commons.api.exceptions.ConfigurationException;
import at.gv.egovernment.moa.id.commons.config.SpringProfileConstants;
import at.gv.egovernment.moa.logging.Logger;
import at.gv.util.config.EgovUtilPropertiesConfiguration;
/**
* Base class for AuthConfigurationProvider
and ProxyConfigurationProvider
,
* providing functions common to both of them.
*
* @author Paul Ivancsics
* @version $Id$
*/
public abstract class ConfigurationProviderImpl extends AbstractConfigurationImpl implements ConfigurationProvider{
/**
* Constructor
* @throws EAAFConfigurationException
*/
public ConfigurationProviderImpl(String configFilePath) throws EAAFConfigurationException {
super(configFilePath);
}
private EgovUtilPropertiesConfiguration eGovUtilsConfig = null;
/**
* The name of the system property which contains the file name of the
* configuration file.
*/
public static final String CONFIG_PROPERTY_NAME =
"moa.id.configuration";
/**
* The name of the system property which contains the file name of the
* configuration file.
*/
public static final String PROXY_CONFIG_PROPERTY_NAME =
"moa.id.proxy.configuration";
/**
* The name of the generic configuration property giving the certstore directory path.
*/
public static final String DIRECTORY_CERTSTORE_PARAMETER_PROPERTY =
"DirectoryCertStoreParameters.RootDir";
/**
* The name of the generic configuration property switching the ssl revocation checking on/off
*/
public static final String TRUST_MANAGER_REVOCATION_CHECKING =
"TrustManager.RevocationChecking";
/**
* Deactivate TargetFriendlyName validation in Authblock
*/
public static final String VALIDATION_AUTHBLOCK_TARGETFRIENDLYNAME = "configuration.validate.authblock.targetfriendlyname";
/**
* A Map
which contains generic configuration information. Maps a
* configuration name (a String
) to a configuration value (also a
* String
).
*/
protected Map genericConfiguration;
/** The default chaining mode. */
protected String defaultChainingMode = "pkix";
public String getDefaultChainingMode() {
return defaultChainingMode;
}
/**
* Get the DB configuration properties from MOA-ID-Auth configuration file
*
* @return
*/
public Properties getDBConnectionConfiguration() {
return getFullConfigurationProperties();
}
/**
* @param properties
* @throws ConfigurationException
* @throws org.opensaml.xml.ConfigurationException
* @throws MalformedURLException
*/
protected void initial(Properties props) throws ConfigurationException, org.opensaml.xml.ConfigurationException, MalformedURLException {
//Initial Hibernate Framework
Logger.trace("Initializing Hibernate framework.");
try {
// read MOAID Session Hibernate properties
Properties moaSessionProp = new Properties();
for (Object key : props.keySet()) {
String propPrefix = "moasession.";
if (key.toString().startsWith(propPrefix+"hibernate")) {
String propertyName = key.toString().substring(propPrefix.length());
moaSessionProp.put(propertyName, props.get(key.toString()));
}
if (key.toString().startsWith(propPrefix+"dbcp")) {
String propertyName = "hibernate."+(key.toString().substring(propPrefix.length()));
moaSessionProp.put(propertyName, props.get(key.toString()));
}
}
// read Config Hibernate properties
Properties configProp = new Properties();
for (Object key : props.keySet()) {
String propPrefix = "configuration.";
if (key.toString().startsWith(propPrefix+"hibernate")) {
String propertyName = key.toString().substring(propPrefix.length());
configProp.put(propertyName, props.get(key.toString()));
}
}
// read advanced logging properties
Properties statisticProps = new Properties();
for (Object key : props.keySet()) {
String propPrefix = "advancedlogging.";
if (key.toString().startsWith(propPrefix+"hibernate")) {
String propertyName = key.toString().substring(propPrefix.length());
statisticProps.put(propertyName, props.get(key.toString()));
}
}
} catch (ExceptionInInitializerError e) {
throw new ConfigurationException("config.17", null, e);
} finally {
}
//Initialize OpenSAML for STORK
Logger.info("Starting initialization of OpenSAML...");
EAAFDefaultSAML2Bootstrap.bootstrap();
//DefaultBootstrap.bootstrap();
Logger.debug("OpenSAML successfully initialized");
//read eGovUtils client configuration
Properties eGovUtilsConfigProp = new Properties();
for (Object key : props.keySet()) {
String propPrefix = "service.";
if (key.toString().startsWith(propPrefix+"egovutil")) {
String propertyName = key.toString().substring(propPrefix.length());
eGovUtilsConfigProp.put(propertyName, props.get(key.toString()));
}
}
if (!eGovUtilsConfigProp.isEmpty()) {
Logger.info("Start eGovUtils client implementation configuration ...");
eGovUtilsConfig =
new EgovUtilPropertiesConfiguration(eGovUtilsConfigProp, getConfigurationRootDirectory().toURL().toString());
}
this.generateActiveProfiles(props);
}
/**
* @return the eGovUtilsConfig
*/
public EgovUtilPropertiesConfiguration geteGovUtilsConfig() {
return eGovUtilsConfig;
}
private ArrayList activeProfiles = new ArrayList();
public void generateActiveProfiles(Properties props){
if (Boolean.valueOf(props.getProperty("configuration.advancedlogging.active", "false"))) {
activeProfiles.add(SpringProfileConstants.ADVANCED_LOG);
}else{
activeProfiles.add("advancedLogOff");
}
if (Boolean.valueOf(props.getProperty("redis.active", "false"))) {
activeProfiles.add(SpringProfileConstants.REDIS_BACKEND);
}else{
activeProfiles.add(SpringProfileConstants.DB_BACKEND);
}
if (Boolean.valueOf(props.getProperty("configuration.database.byteBasedValues", "false")))
activeProfiles.add(SpringProfileConstants.BYTEBASEDCONFIG);
}
public String[] getActiveProfiles(){
Logger.debug("Set active Spring-Profiles to: " + activeProfiles);
return activeProfiles.toArray(new String[0]);
}
public String getRootConfigFileDir() throws ConfigurationException {
try {
return getConfigurationRootDirectory().toURL().toString();
} catch (MalformedURLException e) {
Logger.error("Can not read Config-Root Directory.", e);
throw new ConfigurationException("config.03", null, e);
}
}
}