From f2ebaedd107e0660150faeee6dbe06be5094ac0a Mon Sep 17 00:00:00 2001 From: Gerwin Gsenger Date: Mon, 19 Jan 2015 10:00:36 +0100 Subject: add workaround for static field bean initialization, rework getMOAIDConfiguration() --- .../moa/id/commons/db/NewConfigurationDBRead.java | 55 ++++++++++++++++++---- .../src/main/resources/configuration.beans.xml | 2 +- 2 files changed, 48 insertions(+), 9 deletions(-) (limited to 'id') 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 e39f598b1..29bf02ba9 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 @@ -2,12 +2,18 @@ package at.gv.egovernment.moa.id.commons.db; import java.util.ArrayList; import java.util.Collections; +import java.util.Date; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; +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 at.gv.egovernment.moa.logging.Logger; @@ -19,9 +25,14 @@ import com.datentechnik.moa.id.conf.persistence.Configuration; */ public class NewConfigurationDBRead { - @Autowired private static Configuration conf; + @Autowired(required = true) + public void setConfiguration(Configuration conf) { + // https://jira.spring.io/browse/SPR-3845 + NewConfigurationDBRead.conf = conf; + } + @SuppressWarnings("unchecked") public static > T nullGuard(T item) { if (item == null) { @@ -56,7 +67,8 @@ public class NewConfigurationDBRead { Logger.trace("Get All OnlineApplications from database."); // select onlineapplication from OnlineApplication onlineapplication - return conf.getList("getAllOnlineApplications", OnlineApplication.class); + return conf.getList("getOnlineApplications", OnlineApplication.class); + } /** @@ -92,14 +104,41 @@ public class NewConfigurationDBRead { public static MOAIDConfiguration getMOAIDConfiguration() { Logger.trace("Load MOAID Configuration from database."); - // select moaidconfiguration from MOAIDConfiguration moaidconfiguration - MOAIDConfiguration result = null; - result = conf.get("getMOAIDConfiguration", MOAIDConfiguration.class); - - if(result == null){ - Logger.trace("No entries found. Create fresh instance."); + AuthComponentGeneral authComponent = (AuthComponentGeneral) conf.get("getAuthComponentGeneral", + AuthComponentGeneral.class); + ChainingModes chainingModes = (ChainingModes) conf.get("getChainingModes", ChainingModes.class); + List oas = (List) conf.getList("getOnlineApplications", + OnlineApplication.class); + List genericConfigurations = (List) 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", + 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(); } + + // select moaidconfiguration from MOAIDConfiguration moaidconfiguration + MOAIDConfiguration result = new MOAIDConfiguration(); + result.setAuthComponentGeneral(authComponent); + result.setChainingModes(chainingModes); + result.setOnlineApplication(oas); + result.setGenericConfiguration(genericConfigurations); + result.setTrustedCACertificates(trustedCaCertificates); + result.setDefaultBKUs(defaultBKUs); + result.setSLRequestTemplates(slrRequestRemplates); + result.setTimestampItem(timeStamp); + result.setPvp2RefreshItem(pvp2Refresh); + return result; } 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 1a2e1fedd..ee906a407 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 @@ -23,7 +23,7 @@ - + -- cgit v1.2.3