/* * 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.auth; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.util.List; import java.util.Properties; import org.hibernate.cfg.Configuration; import org.w3c.dom.Element; import org.w3c.dom.Node; import at.gv.egovernment.moa.id.commons.db.ConfigurationDBUtils; import at.gv.egovernment.moa.id.commons.db.ConfigurationUtil; import at.gv.egovernment.moa.id.commons.db.MOASessionUtil; import at.gv.egovernment.moa.id.commons.db.dao.config.OnlineApplication; import at.gv.egovernment.moa.id.commons.db.dao.session.AssertionStore; import at.gv.egovernment.moa.id.commons.db.dao.session.AuthenticatedSessionStore; import at.gv.egovernment.moa.id.commons.db.dao.session.OASessionStore; import at.gv.egovernment.moa.id.commons.db.dao.session.OldSSOSessionIDStore; import at.gv.egovernment.moa.id.config.ConfigurationBuilder; import at.gv.egovernment.moa.id.config.ConfigurationException; import at.gv.egovernment.moa.id.config.ConfigurationProvider; import at.gv.egovernment.moa.id.config.ConnectionParameter; import at.gv.egovernment.moa.id.config.stork.STORKConfig; import at.gv.egovernment.moa.logging.Logger; import at.gv.egovernment.moa.util.DOMUtils; import at.gv.egovernment.moa.util.FileUtils; import at.gv.egovernment.moa.util.MiscUtil; import at.gv.egovernment.moa.util.XPathUtils; import eu.stork.vidp.messages.common.STORKBootstrap; /** * A class providing access to the Auth Part of the MOA-ID configuration data. * *
Configuration data is read from an XML file, whose location is given by
* the moa.id.configuration
system property.
This class implements the Singleton pattern. The reload()
* method can be used to update the configuration data. Therefore, it is not
* guaranteed that consecutive calls to getInstance()
will return
* the same AuthConfigurationProvider
all the time. During the
* processing of a web service request, the current
* TransactionContext
should be used to obtain the
* AuthConfigurationProvider
local to that request.
BKUSelectionType
*/
public static final String BKU_SELECTION_TYPE_HTMLCOMPLETE =
"HTMLComplete";
/**
* BKUSelectionType HTMLSelect, according to schema type BKUSelectionType
*/
public static final String BKU_SELECTION_TYPE_HTMLSELECT =
"HTMLSelect";
/**
* The name of the generic configuration property allowing https connection to
* the user frontend servlets ("StartAuthentication" and "SelectBKU" servlets)
*/
public static final String FRONTEND_SERVLETS_ENABLE_HTTP_CONNECTION_PROPERTY =
"FrontendServlets.EnableHTTPConnection";
/**
* The name of the generic configuration property allowing to set a individual
* DATA URL used to communicate with the BKU (SecurityLayer)
*/
public static final String INDIVIDUAL_DATA_URL_PREFIX =
"FrontendServlets.DataURLPrefix";
/** Singleton instance. null
, if none has been created. */
private static AuthConfigurationProvider instance;
//
// configuration data
//
/**
* configuration files containing transformations for rendering in the
* secure viewer of the security layer implementation;
* multiple files can be given for different mime types
*/
private String[] transformsInfoFileNames;
/**
* transformations for rendering in the secure viewer of the security layer implementation,
* read from {@link transformsInfoFileNames};
* multiple transformation can be given for different mime types
*/
private String[] transformsInfos;
/**
* parameters for connection to MOA SP component
*/
private ConnectionParameter moaSpConnectionParameter;
/**
* trust profile ID to be used for verifying the identity link signature via MOA ID SP
*/
private String moaSpIdentityLinkTrustProfileID;
/**
* trust profile ID to be used for verifying the AUTH block signature via MOA ID SP
*/
private String moaSpAuthBlockTrustProfileID;
/**
* transformations to be used for verifying the AUTH block signature via MOA ID SP
*/
private String[] moaSpAuthBlockVerifyTransformsInfoIDs;
/**
* X509 SubjectNames which will be trusted
*/
private List identityLinkX509SubjectNames;
/**
* default parameters for verifying additional infoboxes.
*/
private VerifyInfoboxParameters defaultVerifyInfoboxParameters;
/**
* configuration parameters for online applications
*/
private OAAuthParameter[] onlineApplicationAuthParameters;
/**
* the Selection Type of the bku Selection Element
*/
private String bKUSelectionType;
/**
* is the bku Selection Element present?
*/
private boolean bKUSelectable;
/**
* the bku Selection Connection Parameters
*/
private ConnectionParameter bKUConnectionParameter;
/**
* parameter for connection to SZR-GW GetIdentityLink
*/
private ConnectionParameter foreignIDConnectionParameter;
/**
* parameter for connection to OnlineMandates Service
*/
private ConnectionParameter onlineMandatesConnectionParameter;
/**
* Parameter for trusted BKUs
*/
private List trustedBKUs;
/**
* Parameter for trusted Template URLs
*/
private List trustedTemplateURLs;
/**
* Holds general information for STORK (e.g. C-PEPS connection parameter, SAML signing parameters, etc.)
*/
private STORKConfig storkConfig;
/**
* Return the single instance of configuration data.
*
* @return AuthConfigurationProvider The current configuration data.
* @throws ConfigurationException
*/
public static synchronized AuthConfigurationProvider getInstance()
throws ConfigurationException {
if (instance == null) {
reload();
}
return instance;
}
/**
* Reload the configuration data and set it if successful.
*
* @return AuthConfigurationProvider The loaded configuration data.
* @throws ConfigurationException Failure to load the configuration data.
*/
public static synchronized AuthConfigurationProvider reload()
throws ConfigurationException {
String fileName = System.getProperty(ConfigurationProvider.CONFIG_PROPERTY_NAME);
if (fileName == null) {
throw new ConfigurationException("config.01", null);
}
Logger.info("Loading MOA-ID-AUTH configuration " + fileName);
instance = new AuthConfigurationProvider(fileName);
return instance;
}
/**
* Constructor for AuthConfigurationProvider.
* @param fileName
* @throws ConfigurationException
*/
public AuthConfigurationProvider(String fileName)
throws ConfigurationException {
load(fileName);
}
/**
* Load the configuration data from XML file with the given name and build
* the internal data structures representing the MOA ID configuration.
*
* @param fileName The name of the XML file to load.
* @throws ConfigurationException The MOA configuration could not be
* read/built.
*/
private void load(String fileName) throws ConfigurationException {
InputStream stream = null;
Element configElem;
ConfigurationBuilder builder;
try {
// load the main config file
stream = new BufferedInputStream(new FileInputStream(fileName));
configElem = DOMUtils.parseXmlValidating(stream);
} catch (Throwable t) {
throw new ConfigurationException("config.03", null, t);
}
finally {
try {
if (stream != null) {
stream.close();
}
} catch (IOException e) {
}
}
try {
//Initial Hibernate Framework
Logger.trace("Initializing Hibernate framework.");
//Load MOAID-2.0 properties file
String propertiesFileLocation = System.getProperty("moa.id.config");
MiscUtil.assertNotNull(propertiesFileLocation, "propertiesFileName");
File propertiesFile = new File(propertiesFileLocation);
FileInputStream fis;
Properties props = new Properties();
//TODO: determine from new config file path
// determine the directory of the root config file
rootConfigFileDir = new File(fileName).getParent();
try {
rootConfigFileDir = new File(rootConfigFileDir).toURL().toString();
} catch (MalformedURLException t) {
throw new ConfigurationException("config.03", null, t);
}
try {
fis = new FileInputStream(propertiesFile);
props.load(fis);
// read MOAID Session Hibernate properties
Properties moaSessionProp = new Properties();
for (Object key : props.keySet()) {
String propPrefix = "moasession.";
if (key.toString().startsWith(propPrefix)) {
String propertyName = 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)) {
String propertyName = key.toString().substring(propPrefix.length());
configProp.put(propertyName, props.get(key.toString()));
}
}
// initialize hibernate
synchronized (AuthConfigurationProvider.class) {
//Initial config Database
ConfigurationUtil.initHibernate(configProp);
//initial MOAID Session Database
Configuration config = new Configuration();
config.addAnnotatedClass(AssertionStore.class);
config.addAnnotatedClass(AuthenticatedSessionStore.class);
config.addAnnotatedClass(OASessionStore.class);
config.addAnnotatedClass(OldSSOSessionIDStore.class);
config.addProperties(moaSessionProp);
MOASessionUtil.initHibernate(config, moaSessionProp);
}
Logger.trace("Hibernate initialization finished.");
} catch (FileNotFoundException e) {
throw new ConfigurationException("config.03", null, e);
} catch (IOException e) {
throw new ConfigurationException("config.03", null, e);
} catch (ExceptionInInitializerError e) {
throw new ConfigurationException("config.17", null, e);
}
//Initialize OpenSAML for STORK
Logger.info("Starting initialization of OpenSAML...");
STORKBootstrap.bootstrap();
Logger.debug("OpenSAML successfully initialized");
//TODO: load from Legacy if legacy.xml.configuration != null
// MOAIDConfiguration moaconfig = BuildFromLegacyConfig.build(fileName, rootConfigFileDir);
// ConfigurationUtil.save(moaconfig);
//TODO: Save MOAID 2.0 config to XML
// JAXBContext jc = JAXBContext.newInstance("at.gv.egovernment.moa.id.commons.db.dao.config");
// Marshaller m = jc.createMarshaller();
// m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
// File test = new File("D:/moa2.0_config.xml");
// m.marshal(moaconfig, test);
// // build the internal datastructures
builder = new ConfigurationBuilder(configElem, rootConfigFileDir);
bKUConnectionParameter = builder.buildAuthBKUConnectionParameter();
bKUSelectable = (bKUConnectionParameter!=null);
bKUSelectionType = builder.buildAuthBKUSelectionType();
genericConfiguration = builder.buildGenericConfiguration();
transformsInfoFileNames = builder.buildTransformsInfoFileNames(builder.getConfigElem(), ConfigurationBuilder.AUTH_SECLAYER_TRANSFORMS_INFO_FILENAME_XPATH);
transformsInfos = builder.loadTransformsInfos(transformsInfoFileNames);
moaSpConnectionParameter = builder.buildMoaSpConnectionParameter();
moaSpIdentityLinkTrustProfileID = builder.getMoaSpIdentityLinkTrustProfileID();
moaSpAuthBlockTrustProfileID = builder.getMoaSpAuthBlockTrustProfileID();
moaSpAuthBlockVerifyTransformsInfoIDs = builder.buildMoaSpAuthBlockVerifyTransformsInfoIDs();
defaultVerifyInfoboxParameters = null;
Node defaultVerifyInfoboxParamtersElem = XPathUtils.selectSingleNode(configElem, ConfigurationBuilder.AUTH_VERIFY_INFOBOXES_XPATH);
if (defaultVerifyInfoboxParamtersElem != null) {
defaultVerifyInfoboxParameters =
builder.buildVerifyInfoboxParameters((Element)defaultVerifyInfoboxParamtersElem, null, moaSpIdentityLinkTrustProfileID);
}
foreignIDConnectionParameter = builder.buildForeignIDConnectionParameter();
onlineMandatesConnectionParameter = builder.buildOnlineMandatesConnectionParameter();
onlineApplicationAuthParameters = builder.buildOnlineApplicationAuthParameters(defaultVerifyInfoboxParameters, moaSpIdentityLinkTrustProfileID);
identityLinkX509SubjectNames = builder.getIdentityLink_X509SubjectNames();
defaultChainingMode = builder.getDefaultChainingMode();
chainingModes = builder.buildChainingModes();
trustedCACertificates = builder.getTrustedCACertificates();
trustedCACertificates = FileUtils.makeAbsoluteURL(trustedCACertificates, rootConfigFileDir);
trustedBKUs = builder.getTrustedBKUs();
trustedTemplateURLs = builder.getTrustedTemplateURLs();
storkConfig = new STORKConfig(builder.buildSTORKSignatureCreationParameter(),builder.buildSTORKSignatureVerificationParameter(), builder.buildSTORKcPEPSMap());
} catch (Throwable t) {
throw new ConfigurationException("config.02", null, t);
}
}
/**
* Loads the transformsInfos
from files.
* @throws Exception on any exception thrown
*/
// private void loadTransformsInfos() throws Exception {
//
// transformsInfos = new String[transformsInfoFileNames.length];
// for (int i = 0; i < transformsInfoFileNames.length; i++) {
// String fileURL = transformsInfoFileNames[i];
//
// //if fileURL is relative to rootConfigFileDir make it absolute
// fileURL = FileUtils.makeAbsoluteURL(fileURL, rootConfigFileDir);
// String transformsInfo = FileUtils.readURL(fileURL, DEFAULT_ENCODING);
// transformsInfos[i] = transformsInfo;
// }
// }
// /**
// * Loads the transformsInfos
from files.
// * @throws Exception on any exception thrown
// */
// private String[] loadTransformsInfos(String[] transformsInfoFileNames) throws Exception {
//
// String[] transformsInfos = new String[transformsInfoFileNames.length];
// for (int i = 0; i < transformsInfoFileNames.length; i++) {
// String fileURL = transformsInfoFileNames[i];
//
// //if fileURL is relative to rootConfigFileDir make it absolute
// fileURL = FileUtils.makeAbsoluteURL(fileURL, rootConfigFileDir);
// String transformsInfo = FileUtils.readURL(fileURL, DEFAULT_ENCODING);
// transformsInfos[i] = transformsInfo;
// }
// return transformsInfos;
// }
/**
* Return a string array with all filenames leading
* to the Transforms Information for the Security Layer
* @return String[] of filenames to the Security Layer Transforms Information
*/
//TODO: only for testing
// public String[] getTransformsInfoFileNames() {
// return transformsInfoFileNames;
// }
/**
* Build an array of the OnlineApplication Parameters containing information
* about the authentication component
* @return An OAProxyParameter array containing beans
* with all relevant information for theauthentication component of the online
* application
*/
public OAAuthParameter[] getOnlineApplicationParameters() {
return onlineApplicationAuthParameters;
}
/**
* Provides configuration information regarding the online application behind
* the given URL, relevant to the MOA-ID Auth component.
*
* @param oaURL URL requested for an online application
* @return an OAAuthParameter
, or null
* if none is applicable
*/
public OAAuthParameter getOnlineApplicationParameter(String oaURL) {
// return ConfigurationDBUtils.getOnlineApplication(oaURL);
OAAuthParameter[] oaParams = getOnlineApplicationParameters();
for (int i = 0; i < oaParams.length; i++) {
OAAuthParameter oaParam = oaParams[i];
if (oaURL.indexOf(oaParam.getPublicURLPrefix()) == 0)
return oaParam;
}
return null;
}
/**
* Return a string with a url-reference to the VerifyAuthBlock trust
* profile id within the moa-sp part of the authentication component
*
* @return String with a url-reference to the VerifyAuthBlock trust profile ID
*/
public String getMoaSpAuthBlockTrustProfileID() {
return moaSpAuthBlockTrustProfileID;
}
/**
* Return a string array with references to all verify transform info
* IDs within the moa-sp part of the authentication component
* @return A string array containing all urls to the
* verify transform info IDs
*/
public String[] getMoaSpAuthBlockVerifyTransformsInfoIDs() {
return moaSpAuthBlockVerifyTransformsInfoIDs;
}
/**
* Return a ConnectionParameter bean containing all information
* of the authentication component moa-sp element
* @return ConnectionParameter of the authentication component moa-sp element
*/
public ConnectionParameter getMoaSpConnectionParameter() {
return moaSpConnectionParameter;
}
/**
* Return a ConnectionParameter bean containing all information
* of the authentication component foreigid element
* @return ConnectionParameter of the authentication component foreignid element
*/
public ConnectionParameter getForeignIDConnectionParameter() {
return foreignIDConnectionParameter;
}
/**
* Return a ConnectionParameter bean containing all information
* of the authentication component OnlineMandates element
* @return ConnectionParameter of the authentication component OnlineMandates element
*/
public ConnectionParameter getOnlineMandatesConnectionParameter() {
return onlineMandatesConnectionParameter;
}
/**
* Return a string with a url-reference to the VerifyIdentityLink trust
* profile id within the moa-sp part of the authentication component
* @return String with a url-reference to the VerifyIdentityLink trust profile ID
*/
public String getMoaSpIdentityLinkTrustProfileID() {
return moaSpIdentityLinkTrustProfileID;
}
/**
* Returns the transformsInfos.
* @return String[]
*/
public String[] getTransformsInfos() {
return transformsInfos;
}
/**
* Returns the identityLinkX509SubjectNames.
* @return List
*/
public List getIdentityLinkX509SubjectNames() {
return identityLinkX509SubjectNames;
}
/**
* Returns the trustBKUs.
* @return List
*/
public List getTrustedBKUs() {
return this.trustedBKUs;
}
/**
* Returns the trustedTemplateURLs.
* @return List
*/
public List getTrustedTemplateURLs() {
return this.trustedTemplateURLs;
}
/**
* Returns the bKUConnectionParameter.
* @return ConnectionParameter
*/
public ConnectionParameter getBKUConnectionParameter() {
return bKUConnectionParameter;
}
/**
* Returns the bKUSelectable.
* @return boolean
*/
public boolean isBKUSelectable() {
return bKUSelectable;
}
/**
* Returns the bKUSelectionType.
* @return String
*/
public String getBKUSelectionType() {
return bKUSelectionType;
}
/**
* Returns the defaultVerifyInfoboxParameters.
*
* @return The defaultVerifyInfoboxParameters.
*/
public VerifyInfoboxParameters getDefaultVerifyInfoboxParameters() {
return defaultVerifyInfoboxParameters;
}
/**
* Retruns the STORK Configuration
* @return STORK Configuration
*/
public STORKConfig getStorkConfig() {
return storkConfig;
}
}