aboutsummaryrefslogtreecommitdiff
path: root/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config
diff options
context:
space:
mode:
authorThomas Lenz <tlenz@iaik.tugraz.at>2015-07-02 07:26:30 +0200
committerThomas Lenz <tlenz@iaik.tugraz.at>2015-07-02 07:26:30 +0200
commit5bc01dab26425144a41dbece04b642fb963e1315 (patch)
tree543fe5f7b8d576c7e85ba711c1f9bf03d3dc699f /id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config
parent06e63a4fb89dd92583fc3e72e12750becdd6c8ef (diff)
downloadmoa-id-spss-5bc01dab26425144a41dbece04b642fb963e1315.tar.gz
moa-id-spss-5bc01dab26425144a41dbece04b642fb963e1315.tar.bz2
moa-id-spss-5bc01dab26425144a41dbece04b642fb963e1315.zip
devel
Diffstat (limited to 'id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config')
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/ConfigurationUtil.java479
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/MOAIDConfigurationConstants.java86
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/MigrateConfiguration.java206
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfiguration.java84
-rw-r--r--id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfigurationImpl.java273
5 files changed, 582 insertions, 546 deletions
diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/ConfigurationUtil.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/ConfigurationUtil.java
index 468e4a536..bac2d0011 100644
--- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/ConfigurationUtil.java
+++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/ConfigurationUtil.java
@@ -1,226 +1,253 @@
-//package at.gv.egovernment.moa.id.commons.config;
-//
-//import java.io.File;
-//import java.io.FileInputStream;
-//import java.io.FileNotFoundException;
-//import java.io.FileOutputStream;
-//import java.io.IOException;
-//import java.util.Enumeration;
-//import java.util.List;
-//import java.util.Properties;
-//
-//import javax.xml.bind.JAXBContext;
-//import javax.xml.bind.JAXBException;
-//import javax.xml.bind.Unmarshaller;
-//
-//import org.springframework.context.ApplicationContext;
-//import org.springframework.context.support.ClassPathXmlApplicationContext;
-//
-//import at.gv.egovernment.moa.id.commons.config.persistence.Configuration;
-//import at.gv.egovernment.moa.id.commons.config.persistence.JsonMapper;
-//import at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration;
-//
-//import com.fasterxml.jackson.core.JsonProcessingException;
-//
-//public class ConfigurationUtil {
-//
-// final boolean isOverwriteData;
-//
-// public ConfigurationUtil(boolean isOverwriteData){
-// this.isOverwriteData = isOverwriteData;
-// }
-//
-// /**
-// * Read an input MOAID 2 XML file, transfer it to properties and write the
-// * properties to a MOAID 3 property file.
-// *
-// * @param inStream
-// * the input stream to read from.
-// * @param outFile
-// * the output file to write to.
-// * @throws JAXBException
-// */
-// public void readFromXMLFileConvertToPropertyFile(FileInputStream inStream, File outFile) throws JAXBException {
-//
-// try (FileOutputStream outStream = new FileOutputStream(outFile);) {
-//
-// // get config from xml file
-// JAXBContext jc = JAXBContext.newInstance("at.gv.egovernment.moa.id.commons.db.dao.config");
-// Unmarshaller m = jc.createUnmarshaller();
-// MOAIDConfiguration config = (MOAIDConfiguration) m.unmarshal(inStream);
-//
-// // serialize config to JSON properties
-// Properties result = moaIdConfigToJsonProperties(config);
-//
-// // write to output stream
-// result.store(outStream, null);
-//
-// } catch (FileNotFoundException e) {
-// System.out.println("Could not find the output file.");
-// System.exit(1);
-// } catch (IOException e) {
-// System.out.println("Could not write to the output file.");
-// System.exit(1);
-// }
-// }
-//
-// /**
-// * Helper method to serialize a {@link MOAIDConfiguration} to Properties
-// * with JSON encoded values.
-// *
-// * @param config
-// * the MOAIDConfiguration to serialize
-// * @return {@link Properties} containing the database key and the serialized
-// * values
-// * @throws JsonProcessingException
-// * is thrown if problem occurred while serializing one of the
-// * database values
-// */
-// private Properties moaIdConfigToJsonProperties(MOAIDConfiguration config) throws JsonProcessingException {
-//
-// Properties result = new Properties();
-// boolean prettyPrint = true;
-// JsonMapper mapper = new JsonMapper(prettyPrint);
-//
-// // serialize config to JSON
-// String oaJson = mapper.serialize(config.getOnlineApplication());
-// String authCompGeneralJson = mapper.serialize(config.getAuthComponentGeneral());
-// String chainingModeJson = mapper.serialize(config.getChainingModes());
-// String defaultBKUJson = mapper.serialize(config.getDefaultBKUs());
-// String genericConfigJson = mapper.serialize(config.getGenericConfiguration());
-// String pvp2RefreshJson = mapper.serialize(config.getPvp2RefreshItem());
-// String slRequestTemplatesJson = mapper.serialize(config.getSLRequestTemplates());
-// String timestampJson = mapper.serialize(config.getTimestampItem());
-// String trustedCaCertJson = mapper.serialize(config.getTrustedCACertificates());
-//
-// // add to properties
-// result.put(MOAIDConfigurationConstants.ONLINE_APPLICATIONS_KEY, oaJson);
-// result.put(MOAIDConfigurationConstants.AUTH_COMPONENT_GENERAL_KEY, authCompGeneralJson);
-// result.put(MOAIDConfigurationConstants.CHAINING_MODES_KEY, chainingModeJson);
-// result.put(MOAIDConfigurationConstants.DEFAULT_BKUS_KEY, defaultBKUJson);
-// result.put(MOAIDConfigurationConstants.GENERIC_CONFIGURATION_KEY, genericConfigJson);
-// result.put(MOAIDConfigurationConstants.PVP2REFRESH_ITEM_KEY, pvp2RefreshJson);
-// result.put(MOAIDConfigurationConstants.SLREQUEST_TEMPLATES_KEY, slRequestTemplatesJson);
-// result.put(MOAIDConfigurationConstants.TIMESTAMP_ITEM_KEY, timestampJson);
-// result.put(MOAIDConfigurationConstants.TRUSTED_CERTIFICATES_KEY, trustedCaCertJson);
-//
-// return result;
-// }
-//
-// /**
-// * Exports a key-value database to a property file, where keys are the same
-// * as in the database, and the values are serialized JSON objects.
-// *
-// * @param inputDBConfigFilePath
-// * the path to the database properties, for the db the data is
-// * read from.
-// * @param outFile
-// * the destination file for the exported data.
-// */
-// public void readFromDBWriteToFile(String inputDBConfigFilePath, File outFile) {
-//
-// try (FileOutputStream outStream = new FileOutputStream(outFile);) {
-//
-// Properties result = new Properties();
-//
-// System.getProperties().setProperty("location", "file:" + inputDBConfigFilePath);
-// ApplicationContext context = new ClassPathXmlApplicationContext("configuration.beans.xml");
-// Configuration dbConfiguration = (Configuration) context.getBean("config");
-// boolean prettyPrint = true;
-// at.gv.egovernment.moa.id.commons.config.persistence.JsonMapper mapper = new JsonMapper(prettyPrint);
-//
-// for (String key : MOAIDConfigurationConstants.getAllMOAIDConfigurationKeys()) {
-//
-// // extract database value
-// Object value = dbConfiguration.get(key);
-//
-// // serialize value to JSON
-// String json = mapper.serialize(value);
-//
-// // add to properties
-// result.setProperty(key, json);
-// }
-//
-// // write to output stream
-// result.store(outStream, null);
-//
-// System.out.println("Property configuration written to:");
-// System.out.println(outFile.getAbsolutePath());
-//
-// } catch (FileNotFoundException e) {
-// System.out.println("Could not find the output file.");
-// System.exit(1);
-// } catch (IOException e) {
-// System.out.println("Could not write to the output file.");
-// System.exit(1);
-// }
-// }
-//
-// /**
-// * Read an input property file, deserialize it's values and write them to
-// * the given database.
-// *
-// * @param inStream
-// * the FileInputStream to read from.
-// * @param outputDBConfigFilePath
-// * the path to the database properties, for the db which is
-// * written.
-// * @throws IOException
-// * is thrown in case the properties could not be loaded from the
-// * stream
-// */
-// public void readFromFileWriteToDB(FileInputStream inStream, String outputDBConfigFilePath) throws IOException {
-//
-// Properties inProperties = new Properties();
-// inProperties.load(inStream);
-//
-// System.getProperties().setProperty("location", "file:" + outputDBConfigFilePath);
-// ApplicationContext context = new ClassPathXmlApplicationContext("configuration.beans.xml");
-// Configuration dbConfiguration = (Configuration) context.getBean("config");
-// boolean prettyPrint = true;
-// JsonMapper mapper = new JsonMapper(prettyPrint);
-//
-// List<String> keys = dbConfiguration.getAllKeys();
-//
-// if (keys == null) {
-// System.out.println("Database can not be read.");
-// System.exit(1);
-// }
-//
-// if (!keys.isEmpty() && !isOverwriteData) {
-// System.out.println("The database already contains configuration data.");
-// System.out.println("Use force switch if you want to override data)");
-// System.exit(1);
-// }
-//
-// if (isOverwriteData) {
-// // remove existing entries
-// for (String key : keys) {
-// dbConfiguration.set(key, null);
-// }
-// }
-//
-// Enumeration<?> propertyNames = inProperties.propertyNames();
-//
-// while (propertyNames.hasMoreElements()) {
-// String key = (String) propertyNames.nextElement();
-// // extract database value
-// String json = inProperties.getProperty(key);
-//
-// // deserialize value to object
-// Object value = mapper.deserialize(json, null);
-//
-// // add to database
-// boolean result = dbConfiguration.set(key, value);
-// if (!result) {
-// System.out.println("Could NOT persist the configuration file's information in the database.");
-// }
-// }
-// System.out.println("Data has been successfully written to the database.");
-// }
-//
-// private static void readFromDBWriteToDB(String inputDBConfigFilePath, String outputDBConfigFilePath) {
-// //TODO: implement
-// }
-//
-//}
+package at.gv.egovernment.moa.id.commons.config;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.transaction.annotation.Transactional;
+
+import at.gv.egiz.components.configuration.api.Configuration;
+import at.gv.egiz.components.configuration.api.ConfigurationException;
+import at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration;
+import at.gv.egovernment.moa.id.commons.db.dao.config.OnlineApplication;
+import at.gv.egovernment.moa.logging.Logger;
+import at.gv.egovernment.moa.util.MiscUtil;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+
+public class ConfigurationUtil {
+
+ final boolean isOverwriteData;
+
+ public ConfigurationUtil(boolean isOverwriteData){
+ this.isOverwriteData = isOverwriteData;
+ }
+
+ /**
+ * Read an input MOAID 2 XML file, transfer it to properties and write the
+ * properties to a MOAID 3 property file.
+ *
+ * @param inStream
+ * the input stream to read from.
+ * @param outFile
+ * the output file to write to.
+ * @throws JAXBException
+ */
+ public void readFromXMLFileConvertToPropertyFile(FileInputStream inStream, File outFile) throws JAXBException {
+
+ try (FileOutputStream outStream = new FileOutputStream(outFile);) {
+
+ // get config from xml file
+ JAXBContext jc = JAXBContext.newInstance("at.gv.egovernment.moa.id.commons.db.dao.config");
+ Unmarshaller m = jc.createUnmarshaller();
+ MOAIDConfiguration config = (MOAIDConfiguration) m.unmarshal(inStream);
+
+ // serialize config to JSON properties
+ Properties result = moaIdConfigToJsonProperties(config);
+
+ // write to output stream
+ result.store(outStream, null);
+
+ } catch (FileNotFoundException e) {
+ System.out.println("Could not find the output file.");
+ System.exit(1);
+ } catch (IOException e) {
+ System.out.println("Could not write to the output file.");
+ System.exit(1);
+ }
+ }
+
+ /**
+ * Helper method to serialize a {@link MOAIDConfiguration} to Properties
+ * with JSON encoded values.
+ *
+ * @param config
+ * the MOAIDConfiguration to serialize
+ * @return {@link Properties} containing the database key and the serialized
+ * values
+ * @throws JsonProcessingException
+ * is thrown if problem occurred while serializing one of the
+ * database values
+ */
+ private Properties moaIdConfigToJsonProperties(MOAIDConfiguration config) throws JsonProcessingException {
+
+ Properties result = new Properties();
+
+ //convert all online applications
+ List<OnlineApplication> oaList = config.getOnlineApplication();
+ for (int i=0; i<oaList.size(); i++) {
+ OnlineApplication oa = oaList.get(i);
+ Map<String, String> keyValueOA = ConfigurationMigrationUtils.convertHyberJaxBOnlineApplicationToKeyValue(oa);
+
+ String serviceIdentifier = keyValueOA.get(MOAIDConfigurationConstants.PREFIX_SERVICES);
+ if (MiscUtil.isEmpty(serviceIdentifier)) {
+ Logger.info("Use default ServiceIdentifier.");
+ serviceIdentifier = MOAIDConfigurationConstants.PREFIX_OA;
+ }
+
+ //write all OA key/value pairs to configuration
+ for (String key : keyValueOA.keySet()) {
+ if (MiscUtil.isNotEmpty(keyValueOA.get(key)))
+ result.put(MOAIDConfigurationConstants.PREFIX_MOAID_SERVICES
+ + "." + serviceIdentifier + "." + String.valueOf(i) + "."
+ + key,
+ keyValueOA.get(key));
+
+ }
+ }
+
+ Map<String, String> keyValueGeneral = ConfigurationMigrationUtils.convertHyberJaxBMOAIDConfigToKeyValue(config);
+ //write all OA key/value pairs to configuration
+ for (String key : keyValueGeneral.keySet()) {
+ if (MiscUtil.isNotEmpty(keyValueGeneral.get(key)))
+ result.put(key, keyValueGeneral.get(key));
+
+ }
+
+ return result;
+ }
+
+ /**
+ * Exports a key-value database to a property file, where keys are the same
+ * as in the database, and the values are serialized JSON objects.
+ *
+ * @param inputDBConfigFilePath
+ * the path to the database properties, for the db the data is
+ * read from.
+ * @param outFile
+ * the destination file for the exported data.
+ */
+ public void readFromDBWriteToFile(String inputDBConfigFilePath, File outFile) {
+
+ try (FileOutputStream outStream = new FileOutputStream(outFile);) {
+
+ Properties result = new Properties();
+
+ System.getProperties().setProperty("location", "file:" + inputDBConfigFilePath);
+ ApplicationContext context = new ClassPathXmlApplicationContext("configuration.beans.xml");
+ Configuration dbConfiguration = (Configuration) context.getBean("config");
+ String[] allKeys = dbConfiguration.getConfigurationIds();
+
+ for (String key : allKeys) {
+
+ // extract database value
+ String value = dbConfiguration.getStringValue(key);
+
+ // add to properties
+ result.setProperty(key, value);
+ }
+
+ // write to output stream
+ result.store(outStream, null);
+
+ System.out.println("Property configuration written to:");
+ System.out.println(outFile.getAbsolutePath());
+
+ } catch (FileNotFoundException e) {
+ System.out.println("Could not find the output file.");
+ System.exit(1);
+ } catch (IOException e) {
+ System.out.println("Could not write to the output file.");
+ System.exit(1);
+
+ } catch (ConfigurationException e) {
+ System.out.println("Could not read from database.");
+ System.exit(1);
+
+ }
+ }
+
+ /**
+ * Read an input property file, deserialize it's values and write them to
+ * the given database.
+ *
+ * @param inStream
+ * the FileInputStream to read from.
+ * @param outputDBConfigFilePath
+ * the path to the database properties, for the db which is
+ * written.
+ * @throws IOException
+ * is thrown in case the properties could not be loaded from the
+ * stream
+ */
+ @Transactional
+ public void readFromFileWriteToDB(FileInputStream inStream, String outputDBConfigFilePath) throws IOException {
+
+ Properties inProperties = new Properties();
+ inProperties.load(inStream);
+
+ System.getProperties().setProperty("location", "file:" + outputDBConfigFilePath);
+ ApplicationContext context = new ClassPathXmlApplicationContext("configuration.beans.xml");
+ Configuration dbConfiguration = (Configuration) context.getBean("moaidconfig");
+
+ List<String> keys = null;
+ try {
+ keys = Arrays.asList(dbConfiguration.getConfigurationIds());
+
+ } catch (ConfigurationException e1) {
+ System.out.println("Database can not be read.");
+ System.exit(1);
+ }
+
+ if (keys == null) {
+ System.out.println("Database can not be read.");
+ System.exit(1);
+ }
+
+ if (!keys.isEmpty() && !isOverwriteData) {
+ System.out.println("The database already contains configuration data.");
+ System.out.println("Use force switch if you want to override data)");
+ System.exit(1);
+ }
+
+ if (isOverwriteData) {
+ // remove existing entries
+ for (String key : keys) {
+ try {
+ dbConfiguration.setStringValue(key, null);
+ } catch (ConfigurationException e) {
+ System.out.println("Could NOT persist the configuration file's information in the database.");
+
+ }
+ }
+ }
+
+ Enumeration<?> propertyNames = inProperties.propertyNames();
+
+ while (propertyNames.hasMoreElements()) {
+ String key = (String) propertyNames.nextElement();
+ String json = inProperties.getProperty(key);
+
+ // add to database
+ try {
+ dbConfiguration.setStringValue(key, json);
+
+ } catch (ConfigurationException e) {
+ System.out.println("Could NOT persist the configuration file's information in the database.");
+
+ }
+
+
+
+ }
+ System.out.println("Data has been successfully written to the database.");
+ }
+
+ private static void readFromDBWriteToDB(String inputDBConfigFilePath, String outputDBConfigFilePath) {
+ //TODO: implement
+ }
+
+}
diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/MOAIDConfigurationConstants.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/MOAIDConfigurationConstants.java
index 6799fcb13..884587d36 100644
--- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/MOAIDConfigurationConstants.java
+++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/MOAIDConfigurationConstants.java
@@ -1,5 +1,9 @@
package at.gv.egovernment.moa.id.commons.config;
+import java.util.Collections;
+import java.util.Hashtable;
+import java.util.Map;
+
/**
*
*
@@ -10,6 +14,29 @@ public final class MOAIDConfigurationConstants {
// restrict instantiation
}
+ //general configuration constants
+
+ public static final String PREFIX_WPBK = "urn:publicid:gv.at:wbpk+";
+ public static final String PREFIX_STORK = "urn:publicid:gv.at:storkid+";
+
+ public static final String IDENIFICATIONTYPE_FN = "FN";
+ public static final String IDENIFICATIONTYPE_ERSB = "ERSB";
+ public static final String IDENIFICATIONTYPE_ZVR = "ZVR";
+ public static final String IDENIFICATIONTYPE_STORK = "STORK";
+
+ public static final Map<String, String> BUSINESSSERVICENAMES;
+
+ static {
+ Hashtable<String, String> tmp = new Hashtable<String, String>();
+ tmp.put(IDENIFICATIONTYPE_FN, "Firmenbuchnummer");
+ tmp.put(IDENIFICATIONTYPE_ZVR, "Vereinsnummer");
+ tmp.put(IDENIFICATIONTYPE_ERSB, "ERsB Kennzahl");
+ tmp.put(IDENIFICATIONTYPE_STORK, "STORK");
+
+ BUSINESSSERVICENAMES = Collections.unmodifiableMap(tmp);
+ }
+
+
//Basic key namespaces
public static final String PREFIX_MOAID = "moa.id";
public static final String PREFIX_GENERAL = "general";
@@ -27,10 +54,10 @@ public final class MOAIDConfigurationConstants {
public static final String PREFIX_MOAID_SERVICES_GATEWAY = PREFIX_MOAID_SERVICES + "." + PREFIX_GATEWAY;
//Namespaces for online applications
- public static final String SERVICE_UNIQUEIDENTIFIER = "uniqueID"; //publicURLPrefix
- public static final String SERVICE_FRIENDLYNAME = "friendlyName"; //friendlyName
- public static final String SERVICE_TYPE = "type"; //type
- public static final String SERVICE_ISACTIVE = "isActive"; //isActive
+ public static final String SERVICE_UNIQUEIDENTIFIER = "uniqueID"; //publicURLPrefix
+ public static final String SERVICE_FRIENDLYNAME = "friendlyName"; //friendlyName
+ public static final String SERVICE_BUSINESSSERVICE = "businessservice"; //type
+ public static final String SERVICE_ISACTIVE = "isActive"; //isActive
//service authentication keys
private static final String AUTH = "auth";
@@ -49,23 +76,37 @@ public final class MOAIDConfigurationConstants {
private static final String PVP2X = "pvp2x";
private static final String OPENID = "openID";
- public static final String SERVICE_AUTH_TARGET = AUTH + "." + TARGET;
- public static final String SERVICE_AUTH_TARGET_TYPE = SERVICE_AUTH_TARGET + ".type"; //targetFriendlyName or IdentificationType
- public static final String SERVICE_AUTH_TARGET_VALUE = SERVICE_AUTH_TARGET + ".value"; //target or IdentificationValue
-
+ private static final String SERVICE_AUTH_TARGET = AUTH + "." + TARGET;
+ private static final String SERVICE_AUTH_TARGET_PUBLIC = SERVICE_AUTH_TARGET + ".public";
+ private static final String SERVICE_AUTH_TARGET_BUSINESS = SERVICE_AUTH_TARGET + ".business";
+ public static final String SERVICE_AUTH_TARGET_BUSINESS_TYPE = SERVICE_AUTH_TARGET_BUSINESS + ".type";
+ public static final String SERVICE_AUTH_TARGET_BUSINESS_VALUE = SERVICE_AUTH_TARGET_BUSINESS + ".value";
+
+ public static final String SERVICE_AUTH_TARGET_PUBLIC_TARGET = SERVICE_AUTH_TARGET_PUBLIC + ".target";
+ public static final String SERVICE_AUTH_TARGET_PUBLIC_TARGET_SUB = SERVICE_AUTH_TARGET_PUBLIC + ".target.sub";
+ public static final String SERVICE_AUTH_TARGET_PUBLIC_USE_SUB = SERVICE_AUTH_TARGET_PUBLIC + ".use.sub";
+ public static final String SERVICE_AUTH_TARGET_PUBLIC_USE_OWN = SERVICE_AUTH_TARGET_PUBLIC + ".use.own";
+ public static final String SERVICE_AUTH_TARGET_PUBLIC_OWN_TARGET = SERVICE_AUTH_TARGET_PUBLIC + ".own.target";
+ public static final String SERVICE_AUTH_TARGET_PUBLIC_OWN_NAME = SERVICE_AUTH_TARGET_PUBLIC + ".own.name";
+
private static final String SERVICE_AUTH_BKU = AUTH + "." + BKU;
public static final String SERVICE_AUTH_BKU_ONLINE = SERVICE_AUTH_BKU + ".onlineBKU";
public static final String SERVICE_AUTH_BKU_LOCAL = SERVICE_AUTH_BKU + ".localBKU";
public static final String SERVICE_AUTH_BKU_HANDY = SERVICE_AUTH_BKU + ".handyBKU";
public static final String SERVICE_AUTH_BKU_KEYBOXIDENTIFIER = SERVICE_AUTH_BKU + ".keyBoxIdentifier";
- public static final String SERVICE_AUTH_BKU_TEMPLATE_LIST = SERVICE_AUTH_BKU + ".template"; //SecurityLayer Templates
- public static final String SERVICE_AUTH_BKU_TEMPLATE_LIST_VALUE = "url";
+ public static final String SERVICE_AUTH_BKU_TEMPLATE = SERVICE_AUTH_BKU + ".template"; //SecurityLayer Templates
+ public static final String SERVICE_AUTH_BKU_TEMPLATE_LEGACY = SERVICE_AUTH_BKU_TEMPLATE + ".legacy";
+ public static final String SERVICE_AUTH_BKU_TEMPLATE_FIRST_VALUE = SERVICE_AUTH_BKU_TEMPLATE + ".first.url";
+ public static final String SERVICE_AUTH_BKU_TEMPLATE_SECOND_VALUE = SERVICE_AUTH_BKU_TEMPLATE + ".second.url";
+ public static final String SERVICE_AUTH_BKU_TEMPLATE_THIRD_VALUE = SERVICE_AUTH_BKU_TEMPLATE + ".third.url";
public static final String SERVICE_AUTH_BKU_AUTHBLOCKTEXT = SERVICE_AUTH_BKU + "authblock.additionaltext";
public static final String SERVICE_AUTH_BKU_AUTHBLOCK_REMOVEBPK = SERVICE_AUTH_BKU + "authblock.removebPK";
private static final String SERVICE_AUTH_TEMPLATES = AUTH + "." + TEMPLATES;
public static final String SERVICE_AUTH_TEMPLATES_BKUSELECTION = SERVICE_AUTH_TEMPLATES + ".bkuselection";
+ public static final String SERVICE_AUTH_TEMPLATES_BKUSELECTION_FILENAME = SERVICE_AUTH_TEMPLATES + ".bkuselection.filename";
public static final String SERVICE_AUTH_TEMPLATES_SENDASSERTION = SERVICE_AUTH_TEMPLATES + ".sendAssertion";
+ public static final String SERVICE_AUTH_TEMPLATES_SENDASSERTION_FILENAME = SERVICE_AUTH_TEMPLATES + ".sendAssertion.filename";
private static final String SERVICE_AUTH_TEMPLATES_CUSTOMIZATION = SERVICE_AUTH_TEMPLATES + ".customize";
public static final String SERVICE_AUTH_TEMPLATES_CUSTOMIZATION_FONTTYPE = SERVICE_AUTH_TEMPLATES_CUSTOMIZATION + ".fonttype";
public static final String SERVICE_AUTH_TEMPLATES_CUSTOMIZATION_BACKGROUNDCOLOR = SERVICE_AUTH_TEMPLATES_CUSTOMIZATION + ".color.back";
@@ -85,10 +126,19 @@ public final class MOAIDConfigurationConstants {
public static final String SERVICE_AUTH_TESTCREDENTIALS_OIDs = SERVICE_AUTH_TESTCREDENTIALS + ".oids";
private static final String SERVICE_AUTH_MANDATES = AUTH + "." + MANDATES;
+ public static final String SERVICE_AUTH_MANDATES_USE = SERVICE_AUTH_MANDATES + "use";
public static final String SERVICE_AUTH_MANDATES_ONLY = SERVICE_AUTH_MANDATES + "only";
public static final String SERVICE_AUTH_MANDATES_PROFILES = SERVICE_AUTH_MANDATES + "profiles";
- public static final String SERVICE_AUTH_FOREIGNBPK = AUTH + "." + FOREIGNBPK; //complex attribute
+ public static final String SERVICE_AUTH_FOREIGNBPK = AUTH + "." + FOREIGNBPK;
+ public static final String SERVICE_AUTH_FOREIGNBPK_DECRYPT = SERVICE_AUTH_FOREIGNBPK + ".decrypt";
+ public static final String SERVICE_AUTH_FOREIGNBPK_DECRYPT_IV = SERVICE_AUTH_FOREIGNBPK_DECRYPT + ".iv";
+ public static final String SERVICE_AUTH_FOREIGNBPK_DECRYPT_BLOB = SERVICE_AUTH_FOREIGNBPK_DECRYPT + ".blob";
+ public static final String SERVICE_AUTH_FOREIGNBPK_DECRYPT_FILENAME= SERVICE_AUTH_FOREIGNBPK_DECRYPT + ".filename";
+ public static final String SERVICE_AUTH_FOREIGNBPK_DECRYPT_KEYSTORE = SERVICE_AUTH_FOREIGNBPK_DECRYPT + ".keystore";
+ public static final String SERVICE_AUTH_FOREIGNBPK_DECRYPT_KEYSTOREPASSWORD = SERVICE_AUTH_FOREIGNBPK_DECRYPT + ".keystore.password";
+ public static final String SERVICE_AUTH_FOREIGNBPK_DECRYPT_KEYALIAS = SERVICE_AUTH_FOREIGNBPK_DECRYPT + ".key.alias";
+ public static final String SERVICE_AUTH_FOREIGNBPK_DECRYPT_KEYPASSWORD = SERVICE_AUTH_FOREIGNBPK_DECRYPT + ".key.password";
private static final String SERVICE_AUTH_SSO = AUTH + "." + SSO;
public static final String SERVICE_AUTH_SSO_ENABLED = SERVICE_AUTH_SSO + ".enabled";
@@ -96,11 +146,14 @@ public final class MOAIDConfigurationConstants {
private static final String SERVICE_AUTH_STORK = AUTH + "." + STORK;
public static final String SERVICE_AUTH_STORK_ENABLED = SERVICE_AUTH_STORK + ".enabled";
+ public static final String SERVICE_AUTH_STORK_MINQAALEVEL = SERVICE_AUTH_STORK + ".minqaalevel";
public static final String SERVICE_AUTH_STORK_COUNTRIES_LIST = SERVICE_AUTH_STORK + ".countries";
public static final String SERVICE_AUTH_STORK_COUNTRIES_LIST_ENABLED = "enabled";
+ public static final String SERVICE_AUTH_STORK_COUNTRIES_LIST_COUNTRYCODE = "countrycode";
public static final String SERVICE_AUTH_STORK_ATTRIBUTES_LIST = SERVICE_AUTH_STORK + ".attributes";
public static final String SERVICE_AUTH_STORK_ATTRIBUTES_LIST_NAME = "name";
- public static final String SERVICE_AUTH_STORK_ATTRIBUTES_LIST_MANDATORY = "mandatory";
+ public static final String SERVICE_AUTH_STORK_ATTRIBUTES_LIST_MANDATORY = "mandatory";
+ public static final String SERVICE_AUTH_STORK_ATTRIBUTES_LIST_REQUESTED = "requested";
public static final String SERVICE_AUTH_STORK_REQUIRECONSENT = SERVICE_AUTH_STORK + ".requireConsent";
public static final String SERVICE_AUTH_STORK_ATTRIBUTPROVIDER_LIST = SERVICE_AUTH_STORK + ".attributeprovider";
public static final String SERVICE_AUTH_STORK_ATTRIBUTPROVIDER_LIST_NAME = "name";
@@ -120,6 +173,7 @@ public final class MOAIDConfigurationConstants {
public static final String SERVICE_PROTOCOLS_PVP2X_RELOAD = SERVICE_PROTOCOLS_PVP2X + ".reload";
public static final String SERVICE_PROTOCOLS_PVP2X_URL = SERVICE_PROTOCOLS_PVP2X + ".URL";
public static final String SERVICE_PROTOCOLS_PVP2X_CERTIFICATE = SERVICE_PROTOCOLS_PVP2X + ".certificate";
+ public static final String SERVICE_PROTOCOLS_PVP2X_CERTIFICATE_SUBJECT = SERVICE_PROTOCOLS_PVP2X + ".certificate.subject";
private static final String SERVICE_PROTOCOLS_OPENID = PROTOCOLS + "." + OPENID;
public static final String SERVICE_PROTOCOLS_OPENID_CLIENTID = SERVICE_PROTOCOLS_OPENID + ".clientID";
@@ -139,9 +193,9 @@ public final class MOAIDConfigurationConstants {
//Namespaces for general MOA-ID config
- public static final String GENERAL_PUBLICURLPREFIX = "publicURLPrefix";
+ public static final String GENERAL_PUBLICURLPREFIX = PREFIX_MOAID_GENERAL + ".publicURLPrefix";
- private static final String GENERAL_DEFAULTS = "defaults";
+ private static final String GENERAL_DEFAULTS = PREFIX_MOAID_GENERAL + ".defaults";
private static final String GENERAL_DEFAULTS_BKU = GENERAL_DEFAULTS + "." + BKU;
public static final String GENERAL_DEFAULTS_BKU_ONLINE = GENERAL_DEFAULTS_BKU + ".onlineBKU";
public static final String GENERAL_DEFAULTS_BKU_HANDY = GENERAL_DEFAULTS_BKU + ".handyBKU";
@@ -151,7 +205,7 @@ public final class MOAIDConfigurationConstants {
public static final String GENERAL_DEFAULTS_TEMPLATES_HANDY = GENERAL_DEFAULTS_TEMPLATES + ".handyBKU";
public static final String GENERAL_DEFAULTS_TEMPLATES_ONLINE = GENERAL_DEFAULTS_TEMPLATES + ".onlineBKU";
- private static final String GENERAL_AUTH = "auth";
+ private static final String GENERAL_AUTH = PREFIX_MOAID_GENERAL + ".auth";
public static final String GENERAL_AUTH_CERTSTORE_URL = GENERAL_AUTH + ".certstore.url";
public static final String GENERAL_AUTH_TRUSTSTORE_URL = GENERAL_AUTH + ".truststore.url";
public static final String GENERAL_AUTH_REVOCATIONCHECKING = GENERAL_AUTH + ".revocationchecking";
@@ -175,7 +229,7 @@ public final class MOAIDConfigurationConstants {
public static final String GENERAL_AUTH_SSO_TARGET = GENERAL_AUTH + "." + SSO + ".target";
public static final String GENERAL_AUTH_SSO_AUTHBLOCK_TEXT = GENERAL_AUTH + "." + SSO + ".authblock.text";
- public static final String GENERAL_PROTOCOLS = PROTOCOLS;
+ public static final String GENERAL_PROTOCOLS = PREFIX_MOAID_GENERAL + "." + PROTOCOLS;
public static final String GENERAL_PROTOCOLS_SAML1 = GENERAL_PROTOCOLS + "." + SAML1;
public static final String GENERAL_PROTOCOLS_PVP2X = GENERAL_PROTOCOLS + "." + PVP2X;
public static final String GENERAL_PROTOCOLS_OPENID = GENERAL_PROTOCOLS + "." + OPENID;
diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/MigrateConfiguration.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/MigrateConfiguration.java
index 32dd97148..4e8c7dffd 100644
--- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/MigrateConfiguration.java
+++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/MigrateConfiguration.java
@@ -1,103 +1,103 @@
-//package at.gv.egovernment.moa.id.commons.config;
-//
-//import java.io.File;
-//import java.io.FileInputStream;
-//import java.io.FileNotFoundException;
-//import java.io.IOException;
-//
-//import javax.xml.bind.JAXBException;
-//
-//import at.gv.egovernment.moa.id.commons.config.cli.MOAIDConfCLI;
-//import at.gv.egovernment.moa.id.commons.config.cli.MigrateConfigurationParams;
-//
-///**
-// * CLI tool which is able to perform the following tasks:
-// * <ul>
-// * <li>transform a MoaID 2 XML configuration XML file to a MoaID 3 property file
-// * </li>
-// * <li>read a property file and transfer it's content to a database</li>
-// * <li>write the content of a database to a property file</li>
-// * </ul>
-// */
-//public class MigrateConfiguration {
-//
-// public static void main(String[] args) {
-//
-// MOAIDConfCLI cli = new MOAIDConfCLI();
-// MigrateConfigurationParams parsedParameters = cli.parse(args);
-//
-// // consider settings of force switch
-// boolean isOverwriteData = parsedParameters.isOverwriteData();
-// ConfigurationUtil configUtil = new ConfigurationUtil(isOverwriteData);
-//
-// if (!parsedParameters.isInputDB() && (parsedParameters.getInputTarget() != null)) {
-// // read input from file
-// workWithInputFromFile(parsedParameters.getInputTarget(), parsedParameters, configUtil);
-//
-// } else if (parsedParameters.getInputDBConfig() != null) {
-// // read input from database
-// workWithImputFromDB(parsedParameters, configUtil);
-//
-// } else {
-// System.exit(1);
-// }
-// }
-//
-// /**
-// * Handle the case where input from a file is read.
-// *
-// * @param inputFileUrl
-// * the url of the input file.
-// * @param parsedParameters
-// * the command line parameters.
-// * @param configUtil
-// * the class for working with the configuration.
-// */
-// private static void workWithInputFromFile(String inputFileUrl, MigrateConfigurationParams parsedParameters,
-// ConfigurationUtil configUtil) {
-// File inFile = new File(inputFileUrl);
-// try (FileInputStream inStream = new FileInputStream(inFile);) {
-//
-// if (!parsedParameters.isOutputDB() && (parsedParameters.getOutputFile() != null)) {
-// // input from file and output to a file is desired
-// File outFile = new File(parsedParameters.getOutputFile());
-// configUtil.readFromXMLFileConvertToPropertyFile(inStream, outFile);
-//
-// } else if (parsedParameters.getOutputDBConfig() != null) {
-// // input from file and output to a database is desired
-// configUtil.readFromFileWriteToDB(inStream, parsedParameters.getOutputDBConfig());
-// }
-// } catch (JAXBException e) {
-// System.out.println("MOA-ID XML configuration can not be loaded from given file.");
-// System.exit(1);
-// } catch (FileNotFoundException e) {
-// System.out.println("Could not find the input file.");
-// System.exit(1);
-// } catch (IOException e) {
-// System.out.println("Could not read from the input file.");
-// System.exit(1);
-// }
-// }
-//
-// /**
-// * Handle the case where input is read from a database.
-// *
-// * @param parsedParameters
-// * the command line parameters.
-// * @param configUtil
-// * the class for working with the configuration.
-// */
-// private static void workWithImputFromDB(MigrateConfigurationParams parsedParameters, ConfigurationUtil configUtil) {
-// if (!parsedParameters.isOutputDB() && (parsedParameters.getOutputFile() != null)) {
-// // input from database and output to a file is desired
-// File outFile = new File(parsedParameters.getOutputFile());
-// String inputDBConfigFilePath = parsedParameters.getInputDBConfig();
-// configUtil.readFromDBWriteToFile(inputDBConfigFilePath, outFile);
-//
-// } else if (parsedParameters.getOutputDBConfig() != null) {
-// // input from database and output to a database is desired
-// // configUtil.readFromDBWriteToDB(inDBConfigFilePath,
-// // outDBConfigFilePath);
-// }
-// }
-//} \ No newline at end of file
+package at.gv.egovernment.moa.id.commons.config;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import javax.xml.bind.JAXBException;
+
+import at.gv.egovernment.moa.id.commons.config.cli.MOAIDConfCLI;
+import at.gv.egovernment.moa.id.commons.config.cli.MigrateConfigurationParams;
+
+/**
+ * CLI tool which is able to perform the following tasks:
+ * <ul>
+ * <li>transform a MoaID 2 XML configuration XML file to a MoaID 3 property file
+ * </li>
+ * <li>read a property file and transfer it's content to a database</li>
+ * <li>write the content of a database to a property file</li>
+ * </ul>
+ */
+public class MigrateConfiguration {
+
+ public static void main(String[] args) {
+
+ MOAIDConfCLI cli = new MOAIDConfCLI();
+ MigrateConfigurationParams parsedParameters = cli.parse(args);
+
+ // consider settings of force switch
+ boolean isOverwriteData = parsedParameters.isOverwriteData();
+ ConfigurationUtil configUtil = new ConfigurationUtil(isOverwriteData);
+
+ if (!parsedParameters.isInputDB() && (parsedParameters.getInputTarget() != null)) {
+ // read input from file
+ workWithInputFromFile(parsedParameters.getInputTarget(), parsedParameters, configUtil);
+
+ } else if (parsedParameters.getInputDBConfig() != null) {
+ // read input from database
+ workWithImputFromDB(parsedParameters, configUtil);
+
+ } else {
+ System.exit(1);
+ }
+ }
+
+ /**
+ * Handle the case where input from a file is read.
+ *
+ * @param inputFileUrl
+ * the url of the input file.
+ * @param parsedParameters
+ * the command line parameters.
+ * @param configUtil
+ * the class for working with the configuration.
+ */
+ private static void workWithInputFromFile(String inputFileUrl, MigrateConfigurationParams parsedParameters,
+ ConfigurationUtil configUtil) {
+ File inFile = new File(inputFileUrl);
+ try (FileInputStream inStream = new FileInputStream(inFile);) {
+
+ if (!parsedParameters.isOutputDB() && (parsedParameters.getOutputFile() != null)) {
+ // input from file and output to a file is desired
+ File outFile = new File(parsedParameters.getOutputFile());
+ configUtil.readFromXMLFileConvertToPropertyFile(inStream, outFile);
+
+ } else if (parsedParameters.getOutputDBConfig() != null) {
+ // input from file and output to a database is desired
+ configUtil.readFromFileWriteToDB(inStream, parsedParameters.getOutputDBConfig());
+ }
+ } catch (JAXBException e) {
+ System.out.println("MOA-ID XML configuration can not be loaded from given file.");
+ System.exit(1);
+ } catch (FileNotFoundException e) {
+ System.out.println("Could not find the input file.");
+ System.exit(1);
+ } catch (IOException e) {
+ System.out.println("Could not read from the input file.");
+ System.exit(1);
+ }
+ }
+
+ /**
+ * Handle the case where input is read from a database.
+ *
+ * @param parsedParameters
+ * the command line parameters.
+ * @param configUtil
+ * the class for working with the configuration.
+ */
+ private static void workWithImputFromDB(MigrateConfigurationParams parsedParameters, ConfigurationUtil configUtil) {
+ if (!parsedParameters.isOutputDB() && (parsedParameters.getOutputFile() != null)) {
+ // input from database and output to a file is desired
+ File outFile = new File(parsedParameters.getOutputFile());
+ String inputDBConfigFilePath = parsedParameters.getInputDBConfig();
+ configUtil.readFromDBWriteToFile(inputDBConfigFilePath, outFile);
+
+ } else if (parsedParameters.getOutputDBConfig() != null) {
+ // input from database and output to a database is desired
+ // configUtil.readFromDBWriteToDB(inDBConfigFilePath,
+ // outDBConfigFilePath);
+ }
+ }
+} \ No newline at end of file
diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfiguration.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfiguration.java
index 159b587df..fbb1597f3 100644
--- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfiguration.java
+++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfiguration.java
@@ -1,5 +1,6 @@
package at.gv.egovernment.moa.id.commons.config.persistence;
+import java.util.Map;
import java.util.Properties;
import at.gv.egiz.components.configuration.api.Configuration;
@@ -13,71 +14,42 @@ public interface MOAIDConfiguration extends Configuration {
/**
* Get all key/value pairs with a prefix
*
- * @param preFix A key prefix
- * @return All key/value pairs with this prefix. The prefix is removed from the key.
+ * @param preFix: A key prefix
+ * @param removePrefix: Indicates, if the prefix should be removed from the result key
+ * @return All key/value pairs with this prefix or null if no key is found. The prefix is removed from the key.
*
**/
- public Properties getPropertySubset(String preFix) throws ConfigurationException;
+ public Map<String, String> getPropertySubset(String preFix) throws ConfigurationException;
/**
+ * Searches the configuration use '*' or '%' for wildcards.
+ *
+ * Example:
+ *
+ * db.server1.url=...
+ * db.server1.user=...
+ * db.server1.password=...
+ * db.server1.driver=...
+ * db.server2.url=...
+ * db.server2.user=...
+ * db.server2.password=...
+ * db.server2.driver=...
+ *
+ * searchString: "db.server1.*" returns
+ * ["db.server1.url", "db.server1.user", "db.server1.password", "db.server1.driver"]
+ * @param searchkey The search string
+ * @return All key/value pairs with this prefix or null if no key is found. The prefix is not removed from the key.
+ * @throws ConfigurationException if something went wrong
+ */
+ public Map<String, String> searchPropertiesWithWildcard(String searchkey) throws ConfigurationException;
+
+ /**
* Load an OnlineApplication configuration and remove the OA key prefix
*
* @param publicURLPrefix: Unique identifier of online application
* @return Properties of the online application or null if no OA is found
* @throws ConfigurationException in case of an configuration access error
*/
- public Properties getOnlineApplication(String publicURLPrefix) throws ConfigurationException;
-
-
-// /**
-// * Gets all keys in the database. NOTE: may return an empty list or {@code null}.
-// * @return a List containing all keys in the database or {@code null}.
-// */
-// List<String> getAllKeys();
-//
-// /**
-// * Get the value associated with the given key as {@link Object}.
-// * @param key the key
-// * @return the String associated with the given key or {@code null} if the key does not exist or does not have a value.
-// */
-// String get(String key);
-//
-// /**
-// * Get the object of type {@code T} associated with the given key.
-// *
-// * @param key the key
-// * @param clazz the type of the requested object
-// * @return the object associated with the given key or {@code null} if the key does not exist or does not have a value.
-// */
-// <T> T get(String key, Class<T> clazz);
-//
-// /**
-// * Store an object associated with a key. If the given object is set to {@code null} then the entry associated with the key is deleted.
-// *
-// * @param key the key under which the value is stored, respectively key determining the entry to be deleted.
-// * @param value the String to store. if value is set to {@code null} then the entry associated with key {@code key} is deleted.
-// * @return {@code true} if the operation was carried out successfully, {@code false} otherwise.
-// */
-// boolean set(String key, String value);
-//
-// /**
-// * Get the object of type {@code T} associated with the given key from the database. If the key does not exist or does not have a value, the given default
-// * value is returned.
-// *
-// * @param key the key
-// * @param clazz the type of the requested object
-// * @param defaultValue the default value to return
-// * @return the object associated with the given key or {@code defaultValue} if the key does not exist or does not have a value.
-// */
-// <T> T get(String key, Class<T> clazz, Object defaultValue);
-//
-// /**
-// * Get a list of objects associated with the given key. The list may be empty or contain only a single object.
-// * @param key the key
-// * @param clazz the type of the requested object
-// * @return a list containing objects of type {@code T} or an empty list if no objects are associated with the key.
-// */
-// <T> List<T> getList(String key, Class<T> clazz);
-
+ public Map<String, String> getOnlineApplication(String publicURLPrefix) throws ConfigurationException;
} \ No newline at end of file
diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfigurationImpl.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfigurationImpl.java
index 2d652d748..06e174942 100644
--- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfigurationImpl.java
+++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/config/persistence/MOAIDConfigurationImpl.java
@@ -1,51 +1,108 @@
package at.gv.egovernment.moa.id.commons.config.persistence;
+import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
-import java.util.Properties;
+import java.util.Map;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
-import org.springframework.beans.factory.annotation.Required;
import org.springframework.stereotype.Component;
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+import org.springframework.transaction.annotation.Transactional;
import at.gv.egiz.components.configuration.api.Configuration;
import at.gv.egiz.components.configuration.api.ConfigurationException;
import at.gv.egovernment.moa.id.commons.config.MOAIDConfigurationConstants;
import at.gv.egovernment.moa.id.commons.db.dao.config.ConfigProperty;
-import at.gv.egovernment.moa.id.commons.db.dao.config.ConfigPropertyDaoImpl;
+import at.gv.egovernment.moa.id.commons.db.dao.config.DatabaseConfigPropertyImpl;
+import at.gv.egovernment.moa.id.commons.utils.KeyValueUtils;
import at.gv.egovernment.moa.logging.Logger;
/**
* The implementation of a key-value configuration implementing the {@link Configuration} interface.
* It employs the {@link ConfigPropertyDao} to persist configuration data.
*/
-@Component
-public class MOAIDConfigurationImpl extends ConfigPropertyDaoImpl implements MOAIDConfiguration {
-
- Configuration configPropertyDao;
-// private JsonMapper mapper = new JsonMapper();
+@Repository
+@EnableTransactionManagement
+@Transactional("transactionManager")
+public class MOAIDConfigurationImpl extends DatabaseConfigPropertyImpl implements MOAIDConfiguration {
- /**
- * Sets the {@link ConfigPropertyDao}.
- * @param configPropertyDao the ConfigPropertyDao
+// Configuration configPropertyDao;
+//
+// /**
+// * Sets the {@link ConfigPropertyDao}.
+// * @param configPropertyDao the ConfigPropertyDao
+// */
+// @Required
+// public void setConfigPropertyDao(Configuration configPropertyDao) {
+// this.configPropertyDao = configPropertyDao;
+// }
+
+ /* (non-Javadoc)
+ * @see at.gv.egovernment.moa.id.commons.config.persistence.MOAIDConfiguration#getPropertySubset(java.lang.String)
*/
- @Required
- public void setConfigPropertyDao(Configuration configPropertyDao) {
- this.configPropertyDao = configPropertyDao;
- }
+ public Map<String, String> getPropertySubset(String preFix) throws ConfigurationException{
+ EntityManager em = this.getPersistenceContext();
+ if (null == em) {
+ Logger.error("No EntityManager set!");
+ throw new ConfigurationException("No EntityManager set!");
+
+ }
+
+ TypedQuery<ConfigProperty> configQuery = em.createQuery("select * from ConfigProperty dbconfig where dbconfig.key like :key", ConfigProperty.class);
+ configQuery.setParameter("key", preFix + ".%");
+ List<ConfigProperty> configResult = configQuery.getResultList();
+ if (configResult == null || configResult.isEmpty()) {
+ Logger.warn("Found no configuration keys with prefix: " + preFix + ".%");
+ return null;
+
+ }
+ Logger.trace("Find " + configResult.size() + " key/value pairs with prefix: " + preFix + ".%");
+
+ //build key/value configuration map from database entries
+ Map<String, String> result = getKeyValueFromDatabaseDAO(
+ configResult.iterator(), preFix, true);
+ return result;
+
+ }
/* (non-Javadoc)
- * @see at.gv.egovernment.moa.id.commons.config.persistence.MOAIDConfiguration#getPropertySubset(java.lang.String)
+ * @see at.gv.egovernment.moa.id.commons.config.persistence.MOAIDConfiguration#searchPropertiesWithWildcard(java.lang.String)
*/
- public Properties getPropertySubset(String preFix) throws ConfigurationException{
- // TODO Auto-generated method stub
- return null;
+ @Override
+ public Map<String, String> searchPropertiesWithWildcard(String searchKey)
+ throws ConfigurationException {
+ EntityManager em = this.getPersistenceContext();
+ if (null == em) {
+ Logger.error("No EntityManager set!");
+ throw new ConfigurationException("No EntityManager set!");
+
+ }
+
+ TypedQuery<ConfigProperty> configQuery = em.createQuery("select * from ConfigProperty dbconfig where dbconfig.key like :key", ConfigProperty.class);
+ configQuery.setParameter("key", searchKey.replace("*", "%"));
+ List<ConfigProperty> configResult = configQuery.getResultList();
+
+ if (configResult == null || configResult.isEmpty()) {
+ Logger.warn("Found no configuration keys with searchKey: " + searchKey);
+ return null;
+
+ }
+ Logger.trace("Find " + configResult.size() + " key/value pairs with searchKey: " + searchKey);
+
+ //build key/value configuration map from database entries
+ Map<String, String> result = getKeyValueFromDatabaseDAO(
+ configResult.iterator(), null, false);
+ return result;
+
}
@Override
- public Properties getOnlineApplication(String publicURLPrefix)
+ public Map<String, String> getOnlineApplication(String publicURLPrefix)
throws ConfigurationException {
EntityManager em = this.getPersistenceContext();
if (null == em) {
@@ -54,148 +111,74 @@ public class MOAIDConfigurationImpl extends ConfigPropertyDaoImpl implements MOA
}
+ //search key prefix for online application with this publicURLPrefix
String keyId = MOAIDConfigurationConstants.PREFIX_MOAID_SERVICES
+ ".%."
+ MOAIDConfigurationConstants.SERVICE_UNIQUEIDENTIFIER;
- TypedQuery<ConfigProperty> query = em.createQuery("select * from ConfigProperty dbconfig where dbconfig.key like :key and dbconfig.value = SUBSTRING(:uniqueID, 1, LENGTH(dbconfig.value))", ConfigProperty.class);
- query.setParameter("key", keyId);
- query.setParameter("uniqueID", publicURLPrefix);
- List<ConfigProperty> result = query.getResultList();
+
+ TypedQuery<ConfigProperty> oaSearchQuery = em.createQuery("select dbconfig from ConfigProperty dbconfig where dbconfig.key like :key and dbconfig.value = SUBSTRING(:uniqueID, 1, LENGTH(dbconfig.value))", ConfigProperty.class);
+ oaSearchQuery.setParameter("key", keyId);
+ oaSearchQuery.setParameter("uniqueID", publicURLPrefix);
+ List<ConfigProperty> oaSearchResult = oaSearchQuery.getResultList();
- if (result.size() == 0) {
+ if (oaSearchResult.size() == 0) {
Logger.debug("No entries found.");
- return null;
- }
+ return null; }
- if (result.size() > 1) {
+ if (oaSearchResult.size() > 1) {
Logger.warn("OAIdentifier match to more then one DB-entry!");
return null;
}
- String oaKey = result.get(0).getKey();
- String oaValue = result.get(0).getValue();
- Logger.trace("Find online application with uniqueID: " + oaValue + " and keyID: " + oaKey);
+ String oaIdKey = oaSearchResult.get(0).getKey();
+ String oaIdValue = oaSearchResult.get(0).getValue();
+ Logger.trace("Find online application with uniqueID: " + oaIdValue + " and keyID: " + oaIdKey);
+ //load all online application key/value pairs from database
+ String oaType = KeyValueUtils.getFirstChildAfterPrefix(oaIdKey, MOAIDConfigurationConstants.PREFIX_MOAID_SERVICES);
+ String oaKey = KeyValueUtils.getPrefixFromKey(oaIdKey, MOAIDConfigurationConstants.SERVICE_UNIQUEIDENTIFIER);
-
- return null;
+ TypedQuery<ConfigProperty> oaConfigQuery = em.createQuery("select dbconfig from ConfigProperty dbconfig where dbconfig.key like :key", ConfigProperty.class);
+ oaConfigQuery.setParameter("key", oaKey + ".%");
+ List<ConfigProperty> oaConfigResult = oaConfigQuery.getResultList();
+
+ if (oaConfigResult == null) {
+ Logger.warn("Found no configuration keys with prefix: " + oaKey + ".%");
+ return null;
+ }
+ Logger.trace("Find " + oaConfigResult.size() + " key/value pairs with prefix: " + oaKey + ".%");
+
+ //build key/value configuration map from database entries
+ Map<String, String> result = getKeyValueFromDatabaseDAO(
+ oaConfigResult.iterator(), oaKey, true);
+ result.put(MOAIDConfigurationConstants.PREFIX_MOAID_SERVICES, oaType);
+
+ return result;
}
+
/**
- * Small helper method. NOTE: may return empty properties, but never {@code null}.
- * @param propPrefix the prefix of the desired property.
- * @return the {@link Properties}
+ * Small helper method. NOTE: may return empty configuration properties, but never {@code null}.
+ *
+ * @param propPrefix: the prefix of the desired property.
+ * @param input: List of database objects with key/value information.
+ * @param removePrefix: Indicates if the prefix should be removed from the result key
+ * @return the {@link Map} of configuration properties
*/
- private Properties getGeneralProperiesConfig(Properties input, final String propPrefix) {
-
- Properties configProp = new Properties();
- for (Object key : input.keySet()) {
- if (key.toString().startsWith(propPrefix)) {
- String propertyName = key.toString().substring(propPrefix.length());
- configProp.put(propertyName, input.get(key.toString()));
- }
+ private Map<String, String> getKeyValueFromDatabaseDAO(Iterator<ConfigProperty> input, final String prefix, boolean removePrefix) {
+ Map<String, String> configProp = new HashMap<String, String>();
+ while (input.hasNext()) {
+ ConfigProperty el = input.next();
+ if (removePrefix) {
+ if (el.getKey().startsWith(prefix)) {
+ String propertyName = KeyValueUtils.removePrefixFromKey(el.getKey(), prefix);
+ configProp.put(propertyName, el.getValue());
+
+ }
+ } else
+ configProp.put(el.getKey(), el.getValue());
+
}
return configProp;
}
-
-
-// @Override
-// public List<String> getAllKeys(){
-// try {
-// return Arrays.asList(this.configPropertyDao.getConfigurationIds());
-// } catch (Exception e) {
-// log.debug("Error while retrieving a list of all keys in the database.");
-// return null;
-// }
-// }
-//
-// @Override
-// public String get(String key) {
-// // return null if key does not exist
-// try {
-// return configPropertyDao.getStringValue(key);
-//
-// } catch (Exception e) {
-// log.debug("Error while searching value of key '{}' to object.", key);
-// return null;
-// }
-// }
-//
-// @Override
-// public <T> T get(String key, Class<T> clazz) {
-// // return null if key does not exist
-// try {
-// T property = configPropertyDao.getObjectValue(key, clazz);
-// return property;
-//
-// } catch (IllegalArgumentException e) {
-// log.debug("Error while searching for key '{}' in the database.", key);
-// return null;
-// } catch (Exception e) {
-// log.debug("Error while deserializing value of key '{}' to object of type {}.", key, clazz.getClass());
-// return null;
-// }
-// }
-//
-// @Override
-// public boolean set(String key, String value) {
-//
-// try {
-// //TODO: add delete
-// if (value == null) {
-// //configPropertyDao.delete(key);
-// return true;
-// } else {
-// configPropertyDao.setStringValue(key, value);
-// return true;
-// }
-// } catch (EntityExistsException e) {
-// log.debug("Property '{}' already exists!", key);
-// return false;
-// } catch (Exception e) {
-// log.debug("Error while setting value for key '{}' in the database.", key);
-// return false;
-// }
-// }
-// @Override
-// public <T> T get(String key, Class<T> clazz, Object defaultValue) {
-//
-// T value = get(key, clazz);
-// if (value != null) {
-// return value;
-// } else {
-// return clazz.cast(defaultValue);
-// }
-// }
-//
-// @SuppressWarnings("unchecked")
-// @Override
-// public <T> List<T> getList(String key, Class<T> clazz) {
-//
-// CollectionType listType = TypeFactory.defaultInstance().constructCollectionType(List.class, clazz);
-// try {
-// if ((configPropertyDao.getProperty(key) == null)
-// || (configPropertyDao.getProperty(key).getValue() == null)) {
-// return new ArrayList<T>();
-// }
-// String json = configPropertyDao.getProperty(key).getValue();
-// ObjectMapper mapper = new ObjectMapper();
-//
-// return (List<T>) mapper.readValue(json, listType);
-// } catch (JsonMappingException e) {
-// ArrayList<T> tmp = new ArrayList<T>();
-// T value = get(key, clazz);
-// if (value != null) {
-// tmp.add(value);
-// }
-// return tmp;
-// } catch (IOException e) {
-// log.debug("Error while deserializing value for key '{}' to List<{}>.", key, clazz.getClass());
-// return new ArrayList<T>();
-// } catch (Exception e){
-// log.debug("Error while searching key '{}' in the database.", key);
-// return new ArrayList<T>();
-// }
-// }
-
}