diff options
author | Christian Wagner <c.wagner@datentechnik-innovation.com> | 2015-01-19 15:57:51 +0100 |
---|---|---|
committer | Thomas Lenz <tlenz@iaik.tugraz.at> | 2015-06-19 11:07:56 +0200 |
commit | 4791f1f77125e1c4c76d189f441924fd62874091 (patch) | |
tree | 97246d83a0a32d9422cb8ea3c4c710cf87cfca56 /id/server/moa-id-commons/src/main/java/at/gv | |
parent | f2ebaedd107e0660150faeee6dbe06be5094ac0a (diff) | |
download | moa-id-spss-4791f1f77125e1c4c76d189f441924fd62874091.tar.gz moa-id-spss-4791f1f77125e1c4c76d189f441924fd62874091.tar.bz2 moa-id-spss-4791f1f77125e1c4c76d189f441924fd62874091.zip |
add writer to store the configuration in key-value database
use solely kv database within 'AuthConfigurationProvider'
add constants declaring db keys
Diffstat (limited to 'id/server/moa-id-commons/src/main/java/at/gv')
4 files changed, 221 insertions, 28 deletions
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); + } + +} |