diff options
10 files changed, 300 insertions, 50 deletions
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java index 5fc416b16..a4eab51d9 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/config/auth/AuthConfigurationProvider.java @@ -69,7 +69,10 @@ import at.gv.egovernment.moa.id.auth.AuthenticationServer; import at.gv.egovernment.moa.id.auth.MOAIDAuthConstants; import at.gv.egovernment.moa.id.commons.db.ConfigurationDBRead; import at.gv.egovernment.moa.id.commons.db.ConfigurationDBUtils; +import at.gv.egovernment.moa.id.commons.db.NewConfigurationDBWrite; +import at.gv.egovernment.moa.id.commons.db.MOAIDConfigurationConstants; import at.gv.egovernment.moa.id.commons.db.MOASessionDBUtils; +import at.gv.egovernment.moa.id.commons.db.NewConfigurationDBRead; import at.gv.egovernment.moa.id.commons.db.StatisticLogDBUtils; import at.gv.egovernment.moa.id.commons.db.dao.config.AuthComponentGeneral; import at.gv.egovernment.moa.id.commons.db.dao.config.ChainingModes; @@ -337,7 +340,7 @@ public class AuthConfigurationProvider extends ConfigurationProvider implements synchronized (AuthConfigurationProvider.class) { //Initial config Database - ConfigurationDBUtils.initHibernate(configProp); + // ConfigurationDBUtils.initHibernate(configProp); //initial MOAID Session Database Configuration config = new Configuration(); @@ -413,14 +416,24 @@ public class AuthConfigurationProvider extends ConfigurationProvider implements //check if XML config should be used if (MiscUtil.isNotEmpty(legacyconfig) || MiscUtil.isNotEmpty(xmlconfig)) { Logger.warn("WARNING! MOA-ID 2.0 is started with XML configuration. This setup overstrike the actual configuration in the Database!"); - moaidconfig = ConfigurationDBRead.getMOAIDConfiguration(); - if (moaidconfig != null) - ConfigurationDBUtils.delete(moaidconfig); + //moaidconfig = ConfigurationDBRead.getMOAIDConfiguration(); + moaidconfig = NewConfigurationDBRead.getMOAIDConfiguration(); + if (moaidconfig.getAuthComponentGeneral()!= null || moaidconfig.getChainingModes() != null || moaidconfig.getTrustedCACertificates() != null || moaidconfig.getDefaultBKUs() != null + || moaidconfig.getSLRequestTemplates() != null || moaidconfig.getTimestampItem() != null || moaidconfig.getPvp2RefreshItem() != null) { + + // ConfigurationDBUtils.delete(moaidconfig); + for(String key : MOAIDConfigurationConstants.getMOAIDConfigurationKeys()){ + NewConfigurationDBWrite.delete(key); + } + } + - List<OnlineApplication> oas = ConfigurationDBRead.getAllOnlineApplications(); + //List<OnlineApplication> oas = ConfigurationDBRead.getAllOnlineApplications(); + List<OnlineApplication> oas = NewConfigurationDBRead.getAllOnlineApplications(); if (oas != null && oas.size() > 0) { - for (OnlineApplication oa : oas) - ConfigurationDBUtils.delete(oa); + // for (OnlineApplication oa : oas) + // ConfigurationDBUtils.delete(oa); + NewConfigurationDBWrite.delete("getOnlineApplications"); } } @@ -431,17 +444,19 @@ public class AuthConfigurationProvider extends ConfigurationProvider implements MOAIDConfiguration moaconfig = BuildFromLegacyConfig.build(new File(legacyconfig), rootConfigFileDir, null); List<OnlineApplication> oas = moaconfig.getOnlineApplication(); - for (OnlineApplication oa : oas) - ConfigurationDBUtils.save(oa); + // for (OnlineApplication oa : oas) + // ConfigurationDBUtils.save(oa); + NewConfigurationDBWrite.saveOnlineApplications(oas); moaconfig.setOnlineApplication(null); - ConfigurationDBUtils.save(moaconfig); + // ConfigurationDBUtils.save(moaconfig); + NewConfigurationDBWrite.save(moaconfig); Logger.info("Legacy Configuration load is completed."); } - + //load MOA-ID 2.x config from XML if (MiscUtil.isNotEmpty(xmlconfig)) { Logger.warn("Load configuration from MOA-ID 2.x XML configuration"); @@ -454,12 +469,15 @@ public class AuthConfigurationProvider extends ConfigurationProvider implements //ConfigurationDBUtils.save(moaconfig); List<OnlineApplication> importoas = moaconfig.getOnlineApplication(); - for (OnlineApplication importoa : importoas) { - ConfigurationDBUtils.saveOrUpdate(importoa); - } + // for (OnlineApplication importoa : importoas) { + // ConfigurationDBUtils.saveOrUpdate(importoa); + // } + + NewConfigurationDBWrite.saveOnlineApplications(importoas); moaconfig.setOnlineApplication(null); - ConfigurationDBUtils.saveOrUpdate(moaconfig); + //ConfigurationDBUtils.saveOrUpdate(moaconfig); + NewConfigurationDBWrite.save(moaconfig); } catch (Exception e) { Logger.warn("MOA-ID XML configuration can not be loaded from File.", e); @@ -479,7 +497,8 @@ public class AuthConfigurationProvider extends ConfigurationProvider implements public synchronized void reloadDataBaseConfig() throws ConfigurationException { Logger.info("Read MOA-ID 2.0 configuration from database."); - moaidconfig = ConfigurationDBRead.getMOAIDConfiguration(); + //moaidconfig = ConfigurationDBRead.getMOAIDConfiguration(); + moaidconfig = NewConfigurationDBRead.getMOAIDConfiguration(); Logger.info("MOA-ID 2.0 is loaded."); if (moaidconfig == null) { @@ -759,7 +778,7 @@ public class AuthConfigurationProvider extends ConfigurationProvider implements } //close Database - ConfigurationDBUtils.closeSession(); + // ConfigurationDBUtils.closeSession(); date = new Date(); } diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationFromDBExtractor.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationFromDBExtractor.java index d657ed16a..78cd8a670 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationFromDBExtractor.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/ConfigurationFromDBExtractor.java @@ -45,47 +45,47 @@ public class ConfigurationFromDBExtractor { return result; } - @JsonProperty("getAuthComponentGeneral") + @JsonProperty(MOAIDConfigurationConstants.AUTH_COMPONENT_GENERAL_KEY) public static AuthComponentGeneral getAuthComponentGeneral() { return getSingleValue("from AuthComponentGeneral", AuthComponentGeneral.class); } - @JsonProperty("getChainingModes") + @JsonProperty(MOAIDConfigurationConstants.CHAINING_MODES_KEY) public static ChainingModes getChainingModes() { return (ChainingModes) getSingleValue("from ChainingModes", ChainingModes.class); } - @JsonProperty("getOnlineApplications") + @JsonProperty(MOAIDConfigurationConstants.ONLINE_APPLICATIONS_KEY) public static List<OnlineApplication> getOnlineApplications() { return getListOfValues("from OnlineApplication", OnlineApplication.class); } - @JsonProperty("getGenericConfigurations") + @JsonProperty(MOAIDConfigurationConstants.GENERIC_CONFIGURATION_KEY) public static List<GenericConfiguration> getGenericConfigurations() { return getListOfValues("from GenericConfiguration", GenericConfiguration.class); } - @JsonProperty("getTrustedCACertificates") + @JsonProperty(MOAIDConfigurationConstants.TRUSTED_CERTIFICATES_KEY) public static String getTrustedCACertificates() { return getSingleValue("select trustedCACertificates from MOAIDConfiguration", String.class); } - @JsonProperty("getDefaultBKUs") + @JsonProperty(MOAIDConfigurationConstants.DEFAULT_BKUS_KEY) public static DefaultBKUs getDefaultBKUs() { return getSingleValue("select defaultBKUs from MOAIDConfiguration", DefaultBKUs.class); } - @JsonProperty("getSLRequestTemplates") + @JsonProperty(MOAIDConfigurationConstants.SLREQUEST_TEMPLATES_KEY) public static SLRequestTemplates getSLRequestTemplates() { return getSingleValue("select SLRequestTemplates from MOAIDConfiguration", SLRequestTemplates.class); } - @JsonProperty("getTimeStampItem") + @JsonProperty(MOAIDConfigurationConstants.TIMESTAMP_ITEM_KEY) public static Date getTimeStampItem() { return getSingleValue("select timestampItem from MOAIDConfiguration", Date.class); } - @JsonProperty("getPvp2RefreshItem") + @JsonProperty(MOAIDConfigurationConstants.PVP2REFRESH_ITEM_KEY) public static Date getPvp2RefreshItem() { return getSingleValue("select pvp2RefreshItem from MOAIDConfiguration", Date.class); } diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/MOAIDConfigurationConstants.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/MOAIDConfigurationConstants.java new file mode 100644 index 000000000..dc7c92a1d --- /dev/null +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/MOAIDConfigurationConstants.java @@ -0,0 +1,35 @@ +package at.gv.egovernment.moa.id.commons.db; + +import at.gv.egovernment.moa.id.commons.db.dao.config.MOAIDConfiguration; + +/** + * + * + */ +public final class MOAIDConfigurationConstants { + + private MOAIDConfigurationConstants() { + // restrict instantiation + } + + // keys for the object in the key-value database + public static final String ONLINE_APPLICATIONS_KEY = "OnlineApplications"; + public static final String AUTH_COMPONENT_GENERAL_KEY = "AuthComponentGeneral"; + public static final String CHAINING_MODES_KEY = "ChainingModes"; + public static final String TRUSTED_CERTIFICATES_KEY = "TruestedCertificates"; + public static final String DEFAULT_BKUS_KEY = "DefaultBKUs"; + public static final String SLREQUEST_TEMPLATES_KEY = "SLRequestTemplates"; + public static final String TIMESTAMP_ITEM_KEY = "TimestampItem"; + public static final String PVP2REFRESH_ITEM_KEY = "Pvp2RefreshItem"; + public static final String GENERIC_CONFIGURATION_KEY = "GenericConfiguration"; + + /** + * Returns all relevant (database-) keys that {@link MOAIDConfiguration} contains. + * @return the keys as {@code String[]} + */ + public static final String[] getMOAIDConfigurationKeys() { + String[] keys = new String[] { AUTH_COMPONENT_GENERAL_KEY, CHAINING_MODES_KEY, TRUSTED_CERTIFICATES_KEY, DEFAULT_BKUS_KEY, SLREQUEST_TEMPLATES_KEY, + TIMESTAMP_ITEM_KEY, PVP2REFRESH_ITEM_KEY }; + return keys; + } +} diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBRead.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBRead.java index 29bf02ba9..124a2e46a 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBRead.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBRead.java @@ -67,7 +67,7 @@ public class NewConfigurationDBRead { Logger.trace("Get All OnlineApplications from database."); // select onlineapplication from OnlineApplication onlineapplication - return conf.getList("getOnlineApplications", OnlineApplication.class); + return conf.getList(MOAIDConfigurationConstants.ONLINE_APPLICATIONS_KEY, OnlineApplication.class); } @@ -104,28 +104,29 @@ public class NewConfigurationDBRead { public static MOAIDConfiguration getMOAIDConfiguration() { Logger.trace("Load MOAID Configuration from database."); - AuthComponentGeneral authComponent = (AuthComponentGeneral) conf.get("getAuthComponentGeneral", + AuthComponentGeneral authComponent = (AuthComponentGeneral) conf.get(MOAIDConfigurationConstants.AUTH_COMPONENT_GENERAL_KEY, AuthComponentGeneral.class); - ChainingModes chainingModes = (ChainingModes) conf.get("getChainingModes", ChainingModes.class); - List<OnlineApplication> oas = (List<OnlineApplication>) conf.getList("getOnlineApplications", + + ChainingModes chainingModes = (ChainingModes) conf.get(MOAIDConfigurationConstants.CHAINING_MODES_KEY, ChainingModes.class); + List<OnlineApplication> oas = (List<OnlineApplication>) conf.getList(MOAIDConfigurationConstants.ONLINE_APPLICATIONS_KEY, OnlineApplication.class); List<GenericConfiguration> genericConfigurations = (List<GenericConfiguration>) conf.getList( - "getGenericConfigurations", GenericConfiguration.class); - String trustedCaCertificates = (String) conf.get("getTrustedCACertificates", String.class); - DefaultBKUs defaultBKUs = (DefaultBKUs) conf.get("getDefaultBKUs", DefaultBKUs.class); - SLRequestTemplates slrRequestRemplates = (SLRequestTemplates) conf.get("getSLRequestTemplates", + MOAIDConfigurationConstants.GENERIC_CONFIGURATION_KEY, GenericConfiguration.class); + String trustedCaCertificates = (String) conf.get(MOAIDConfigurationConstants.TRUSTED_CERTIFICATES_KEY, String.class); + DefaultBKUs defaultBKUs = (DefaultBKUs) conf.get(MOAIDConfigurationConstants.DEFAULT_BKUS_KEY, DefaultBKUs.class); + SLRequestTemplates slrRequestRemplates = (SLRequestTemplates) conf.get(MOAIDConfigurationConstants.SLREQUEST_TEMPLATES_KEY, SLRequestTemplates.class); - Date timeStamp = (Date) conf.get("getTimeStampItem", Date.class); - Date pvp2Refresh = (Date) conf.get("getPvp2RefreshItem", Date.class); - - if (authComponent == null || chainingModes == null || trustedCaCertificates == null || defaultBKUs == null - || slrRequestRemplates == null || timeStamp == null || pvp2Refresh == null - - ) { - // TODO: is there a better approach in case of error? - Logger.trace("Not all necessary data available. Create fresh instance."); - return new MOAIDConfiguration(); - } + Date timeStamp = (Date) conf.get(MOAIDConfigurationConstants.TIMESTAMP_ITEM_KEY, Date.class); + Date pvp2Refresh = (Date) conf.get(MOAIDConfigurationConstants.PVP2REFRESH_ITEM_KEY, Date.class); + + // if (authComponent == null || chainingModes == null || trustedCaCertificates == null || defaultBKUs == null + // || slrRequestRemplates == null || timeStamp == null || pvp2Refresh == null + // + // ) { + // // TODO: is there a better approach in case of error? + // Logger.trace("Not all necessary data available. Create fresh instance."); + // return new MOAIDConfiguration(); + // } // select moaidconfiguration from MOAIDConfiguration moaidconfiguration MOAIDConfiguration result = new MOAIDConfiguration(); diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBWrite.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBWrite.java new file mode 100644 index 000000000..d8ac55b4e --- /dev/null +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/db/NewConfigurationDBWrite.java @@ -0,0 +1,157 @@ +package at.gv.egovernment.moa.id.commons.db; + +import java.util.Date; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import at.gv.egovernment.moa.id.commons.db.dao.config.AuthComponentGeneral; +import at.gv.egovernment.moa.id.commons.db.dao.config.ChainingModes; +import at.gv.egovernment.moa.id.commons.db.dao.config.DefaultBKUs; +import at.gv.egovernment.moa.id.commons.db.dao.config.GenericConfiguration; +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.id.commons.db.dao.config.SLRequestTemplates; +import at.gv.egovernment.moa.id.commons.db.dao.config.UserDatabase; + +import com.datentechnik.moa.id.conf.persistence.Configuration; + +/** + * + * + */ +@Component +public class NewConfigurationDBWrite { + + private static Configuration conf; + + @Autowired(required = true) + public void setConfiguration(Configuration conf) { + // https://jira.spring.io/browse/SPR-3845 + NewConfigurationDBWrite.conf = conf; + } + + private static boolean saveAuthComponentGeneral(AuthComponentGeneral dbo) { + + conf.set(MOAIDConfigurationConstants.AUTH_COMPONENT_GENERAL_KEY, dbo); + return true; + } + + private static boolean saveChainingModes(ChainingModes dbo) { + conf.set(MOAIDConfigurationConstants.CHAINING_MODES_KEY, dbo); + return true; + } + + private static boolean saveOnlineApplication(OnlineApplication dbo) { + + List<OnlineApplication> storedObjects = conf.getList(MOAIDConfigurationConstants.ONLINE_APPLICATIONS_KEY, OnlineApplication.class); + storedObjects.add(dbo); + conf.set(MOAIDConfigurationConstants.ONLINE_APPLICATIONS_KEY, storedObjects); + + return true; + } + + private static boolean saveGenericConfiguration(GenericConfiguration dbo) { + + List<GenericConfiguration> storedObjects = conf.getList(MOAIDConfigurationConstants.GENERIC_CONFIGURATION_KEY, GenericConfiguration.class); + storedObjects.add(dbo); + conf.set(MOAIDConfigurationConstants.GENERIC_CONFIGURATION_KEY, storedObjects); + return true; + } + + private static boolean saveTrustedCACertificates(String dbo) { + + conf.set(MOAIDConfigurationConstants.TRUSTED_CERTIFICATES_KEY, dbo); + return true; + } + + private static boolean saveDefaultBKUs(DefaultBKUs dbo) { + + conf.set(MOAIDConfigurationConstants.DEFAULT_BKUS_KEY, dbo); + return true; + } + + private static boolean saveSLRequestTemplates(SLRequestTemplates dbo) { + + conf.set(MOAIDConfigurationConstants.SLREQUEST_TEMPLATES_KEY, dbo); + return true; + } + + private static boolean saveTimeStampItem(Date dbo) { + + conf.set(MOAIDConfigurationConstants.TIMESTAMP_ITEM_KEY, dbo); + return true; + } + + private static boolean savePvp2RefreshItem(Date dbo) { + + conf.set(MOAIDConfigurationConstants.PVP2REFRESH_ITEM_KEY, dbo); + return true; + } + + /** + * Saves the given list of {@link OnlineApplication} objects to database. + * @param oas the list + * @return {@code true} on success; {@code false} otherwise. + */ + public static boolean saveOnlineApplications(List<OnlineApplication> oas) { + + conf.set(MOAIDConfigurationConstants.ONLINE_APPLICATIONS_KEY, oas); + return true; + } + + /** + * Saves the given list of {@link GenericConfiguration} objects to database. + * @param gcs the list + * @return {@code true} on success; {@code false} otherwise. + */ + public static boolean saveGenericConfigurations(List<GenericConfiguration> gcs) { + + return conf.set(MOAIDConfigurationConstants.GENERIC_CONFIGURATION_KEY, gcs); + } + + + /** + * Saves the given object to database + * @param dbo the object to save + * @return {@code true} on success; {@code false} otherwise. + */ + public static boolean save(Object dbo) { + + boolean result = false; + + if (dbo instanceof OnlineApplication) { + + result = saveOnlineApplication((OnlineApplication) dbo); + + } else if (dbo instanceof MOAIDConfiguration) { + + MOAIDConfiguration moaconfig = (MOAIDConfiguration) dbo; + result = true; + + result &= saveAuthComponentGeneral(moaconfig.getAuthComponentGeneral()); + result &= saveChainingModes(moaconfig.getChainingModes()); + result &= saveDefaultBKUs(moaconfig.getDefaultBKUs()); + result &= saveGenericConfigurations(moaconfig.getGenericConfiguration()); + result &= savePvp2RefreshItem(moaconfig.getPvp2RefreshItem()); + result &= saveSLRequestTemplates(moaconfig.getSLRequestTemplates()); + result &= saveTrustedCACertificates(moaconfig.getTrustedCACertificates()); + result &= saveTimeStampItem(moaconfig.getTimestampItem()); + + } else if (dbo instanceof UserDatabase) { + // TODO implement user handling + } + + return result; + } + + /** + * Deletes the object associated with the given key. + * @param key the key + */ + public static void delete(String key) { + conf.delete(key); + } + +} diff --git a/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/Configuration.java b/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/Configuration.java index 6ec43c583..43f7d9454 100644 --- a/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/Configuration.java +++ b/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/Configuration.java @@ -27,7 +27,7 @@ public interface Configuration { * @param key * @param value */ - void set(String key, Object value); + boolean set(String key, Object value); /** * @@ -45,4 +45,11 @@ public interface Configuration { * @return */ <T> List<T> getList(String key, Class<T> clazz); + + /** + * + * @param key + * @return + */ + void delete(String key); }
\ No newline at end of file diff --git a/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/ConfigurationImpl.java b/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/ConfigurationImpl.java index 7a52d0c9d..eebecf509 100644 --- a/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/ConfigurationImpl.java +++ b/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/ConfigurationImpl.java @@ -66,7 +66,7 @@ public class ConfigurationImpl implements Configuration { } @Override - public void set(String key, Object value) { + public boolean set(String key, Object value) { ConfigProperty keyValue = new ConfigProperty(); keyValue.setKey(key); @@ -74,10 +74,11 @@ public class ConfigurationImpl implements Configuration { keyValue.setValue(mapper.serialize(value)); // System.out.println(">> key - value: " + keyValue.getKey() + " - " + keyValue.getValue() + "\n"); configPropertyDao.saveProperty(keyValue); - + return true; } catch (JsonProcessingException e) { // TODO do proper error handling e.printStackTrace(); + return false; } } @@ -98,6 +99,10 @@ public class ConfigurationImpl implements Configuration { public <T> List<T> getList(String key, Class<T> clazz) { CollectionType listType = TypeFactory.defaultInstance().constructCollectionType(List.class, clazz); + + if(configPropertyDao.getProperty(key)==null){ + return new ArrayList<T>(); + } String json = configPropertyDao.getProperty(key).getValue(); ObjectMapper mapper = new ObjectMapper(); @@ -120,6 +125,12 @@ public class ConfigurationImpl implements Configuration { return property.getValue(); } + @Override + public void delete(String key) { + configPropertyDao.delete(key); + } + + /** * * @@ -178,4 +189,5 @@ public class ConfigurationImpl implements Configuration { }; + } diff --git a/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/dal/ConfigPropertyDao.java b/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/dal/ConfigPropertyDao.java index a11d23ce8..50dddd745 100644 --- a/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/dal/ConfigPropertyDao.java +++ b/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/dal/ConfigPropertyDao.java @@ -42,4 +42,11 @@ public interface ConfigPropertyDao { * @param properties The list containing all the properties to be persisted. */ public void saveProperties(Set<ConfigProperty> properties); + + /** + * Deletes the object associated with the given key. + * @param key the key + */ + public void delete(String key); + } diff --git a/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/dal/ConfigPropertyDaoImpl.java b/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/dal/ConfigPropertyDaoImpl.java index 2b28cb245..752c7dc09 100644 --- a/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/dal/ConfigPropertyDaoImpl.java +++ b/id/server/moa-id-commons/src/main/java/com/datentechnik/moa/id/conf/persistence/dal/ConfigPropertyDaoImpl.java @@ -64,12 +64,12 @@ public class ConfigPropertyDaoImpl implements ConfigPropertyDao { @Override public List<ConfigProperty> getProperties() { - + if (null == em) { log.error("No EntityManager set!"); return null; } - + log.debug("Retrieving all properties from database."); TypedQuery<ConfigProperty> query = em.createQuery("select mc from ConfigProperty mc", ConfigProperty.class); try { @@ -90,4 +90,14 @@ public class ConfigPropertyDaoImpl implements ConfigPropertyDao { em.flush(); } + @Override + public void delete(String key) { + log.debug("Deleting entry with key '{}'.", key); + try{ + em.remove(em.find(ConfigProperty.class, key)); + }catch (IllegalArgumentException e){ + log.trace("Error while deleting entry with key '{}':" + e.getMessage(), key); + } + } + } diff --git a/id/server/moa-id-commons/src/main/resources/configuration.beans.xml b/id/server/moa-id-commons/src/main/resources/configuration.beans.xml index ee906a407..87cccc7b2 100644 --- a/id/server/moa-id-commons/src/main/resources/configuration.beans.xml +++ b/id/server/moa-id-commons/src/main/resources/configuration.beans.xml @@ -25,6 +25,8 @@ <bean id="configRead" class="at.gv.egovernment.moa.id.commons.db.NewConfigurationDBRead"/> + <bean id="configWrite" class="at.gv.egovernment.moa.id.commons.db.NewConfigurationDBWrite"/> + <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" lazy-init="true" destroy-method="close"> <aop:scoped-proxy/> <property name="driverClassName" value="${dataSource.driverClassName}" /> |