From 3f2032efba5469589d5317b1796a0aec74457847 Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Tue, 16 Mar 2021 15:13:22 +0100 Subject: update MOA-SPSS initialization to mitigate suspect behavior in EAAF-Components module --- .../test/java/console/SchemaValidationTest.java | 52 ++++++++++++++++++++++ moaSig/common/src/test/resources/zuse/msg.xml | 7 +++ .../gv/egovernment/moa/spss/api/Configurator.java | 16 ++++++- .../moa/spss/server/init/ConfiguratorImpl.java | 31 ++++++++++--- .../server/init/StartupConfigurationHolder.java | 42 +++++++++++++++++ .../moa/spss/server/init/SystemInitializer.java | 34 ++++++++++---- moaSig/moa-sig/src/main/resources/log4j.properties | 13 +++--- moaSig/moa-sig/src/main/resources/logback.xml | 49 ++++++++++++++++++++ 8 files changed, 220 insertions(+), 24 deletions(-) create mode 100644 moaSig/common/src/test/java/console/SchemaValidationTest.java create mode 100644 moaSig/common/src/test/resources/zuse/msg.xml create mode 100644 moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/init/StartupConfigurationHolder.java create mode 100644 moaSig/moa-sig/src/main/resources/logback.xml (limited to 'moaSig') diff --git a/moaSig/common/src/test/java/console/SchemaValidationTest.java b/moaSig/common/src/test/java/console/SchemaValidationTest.java new file mode 100644 index 0000000..db3041b --- /dev/null +++ b/moaSig/common/src/test/java/console/SchemaValidationTest.java @@ -0,0 +1,52 @@ +package console; + +import java.io.InputStream; + +import org.w3c.dom.Element; + +import at.gv.egovernment.moaspss.util.DOMUtils; + +public class SchemaValidationTest { + + public static final String SCHEMA_ROOT = "/config/zuseSchema"; + + public static final String XML_NS_URI = "http://www.w3.org/XML/1998/namespace"; + public static final String XML_SCHEMA_LOCATION = SCHEMA_ROOT + "xml.xsd"; + + public static final String XSI_NS_URI = "http://www.w3.org/2001/XMLSchema-instance"; + public static final String XSI_SCHEMA_LOCATION = SCHEMA_ROOT + "XMLSchema-instance.xsd"; + + public static final String eDELIVERY20 = "http://reference.e-government.gv.at/namespace/zustellung/msg/phase2/20181206#"; + public static final String eDELIVERY20_SCHEMA_LOCATION = SCHEMA_ROOT + "zuse_p2.xsd"; + + public static final String eDELIVERY_PERSON_20 = "http://reference.e-government.gv.at/namespace/persondata/phase2/20181206#"; + public static final String eDELIVERY_PERSON_20_SCHEMA_LOCATION = SCHEMA_ROOT + "zuse_mypersondata_en_p2.xsd"; + + private static final String ZUSE_SCHEMAS = + (XML_NS_URI + " " + XML_SCHEMA_LOCATION + " ") + + (XSI_NS_URI + " " + XSI_SCHEMA_LOCATION + " ") + + (eDELIVERY20 + " " + eDELIVERY20_SCHEMA_LOCATION + " ") + + (eDELIVERY_PERSON_20 + " " + eDELIVERY_PERSON_20_SCHEMA_LOCATION); + + /** + * Simple test. + * + * @param args not used yet + * @throws Exception in case of an error + */ + public static void main(String[] args) throws Exception { + + InputStream is = SchemaValidationTest.class.getResourceAsStream("/zuse/msg.xml"); + + + Element result = DOMUtils.parseXmlValidating(is); + +// Document result = DOMUtils.parseDocument(is, +// true, ZUSE_SCHEMAS, null, new MOASPSSEntityResolver(), new MOAErrorHandler()); + + + System.out.print(DOMUtils.serializeNode(result)); + + } + +} diff --git a/moaSig/common/src/test/resources/zuse/msg.xml b/moaSig/common/src/test/resources/zuse/msg.xml new file mode 100644 index 0000000..200950a --- /dev/null +++ b/moaSig/common/src/test/resources/zuse/msg.xml @@ -0,0 +1,7 @@ + + + + urn:publicid:gv.at:ecdid+ZUSETNVZ+ZU + + + diff --git a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/api/Configurator.java b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/api/Configurator.java index 59db7b5..bc0acbe 100644 --- a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/api/Configurator.java +++ b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/api/Configurator.java @@ -26,6 +26,7 @@ package at.gv.egovernment.moa.spss.api; import at.gv.egovernment.moa.spss.MOAException; import at.gv.egovernment.moa.spss.server.init.ConfiguratorImpl; +import at.gv.egovernment.moa.spss.server.init.StartupConfigurationHolder; /** * Configures the SP/SS API. @@ -61,15 +62,24 @@ public abstract class Configurator { return instance; } + /** + * Get current configuration object. + * + * @return Configuration or null if it was not initialized yet + */ + public abstract StartupConfigurationHolder getCurrentConfiguration(); + /** * Initialize the SP/SS configuration. * * Only a single call to this method will have an effect. Use * update() for reflecting changes in the configuration instead. * + * @return Configuration holder + * * @throws MOAException An error occurred updating the SP/SS configuration. */ - public abstract void init() throws MOAException; + public abstract StartupConfigurationHolder init() throws MOAException; /** * Update the SP/SS configuration. @@ -77,8 +87,10 @@ public abstract class Configurator { * This will only have an effect after the system has been initialized once * using init(). * + * @return Updated Configuration holder, or null if it was not initialized + * * @throws MOAException An error occurred updating the SP/SS configuration. */ - public abstract void update() throws MOAException; + public abstract StartupConfigurationHolder update() throws MOAException; } diff --git a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/init/ConfiguratorImpl.java b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/init/ConfiguratorImpl.java index 8ab01d6..32654d4 100644 --- a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/init/ConfiguratorImpl.java +++ b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/init/ConfiguratorImpl.java @@ -29,6 +29,7 @@ import at.gv.egovernment.moa.spss.api.Configurator; import at.gv.egovernment.moa.spss.server.config.ConfigurationException; import at.gv.egovernment.moa.spss.server.config.ConfigurationProvider; import at.gv.egovernment.moa.spss.server.iaik.config.IaikConfigurator; +import iaik.server.ConfigurationData; /** * Default implementation of Configurator. @@ -40,26 +41,42 @@ public class ConfiguratorImpl extends Configurator { /** whether the configuration has been initialized */ private boolean initialized = false; - public void init() throws MOAException { + StartupConfigurationHolder result; + + public StartupConfigurationHolder getCurrentConfiguration() { + return result; + + } + + public StartupConfigurationHolder init() throws MOAException { if (!initialized) { - SystemInitializer.init(); + result = SystemInitializer.init(); initialized = true; + } + + return result; + } - public void update() throws MOAException { + public StartupConfigurationHolder update() throws MOAException { if (!initialized) { - return; + return null; } - try { + try { // reconfigure the system ConfigurationProvider config = ConfigurationProvider.reload(); - new IaikConfigurator().configure(config); + ConfigurationData iaikConfig = new IaikConfigurator().configure(config); + result = new StartupConfigurationHolder(config, iaikConfig); + return result; + } catch (MOAException e) { throw e; + } catch (Throwable t) { - throw new ConfigurationException("", null, t); + throw new ConfigurationException("MOA-SPSS initialization FAILED with a generic error", null, t); + } } diff --git a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/init/StartupConfigurationHolder.java b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/init/StartupConfigurationHolder.java new file mode 100644 index 0000000..229a8b2 --- /dev/null +++ b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/init/StartupConfigurationHolder.java @@ -0,0 +1,42 @@ +package at.gv.egovernment.moa.spss.server.init; + +import at.gv.egovernment.moa.spss.server.config.ConfigurationProvider; +import iaik.server.ConfigurationData; + +public class StartupConfigurationHolder { + + private final ConfigurationProvider moaSpssConfig; + private final ConfigurationData iaikConfiguration; + + /** + * Holder for IAIK and MOA-SPSS related configuration object. + * + * @param config MOA-SPSS specific configuration + * @param iaikConfig Internal IAIK module configuration + */ + public StartupConfigurationHolder(ConfigurationProvider config, ConfigurationData iaikConfig) { + this.moaSpssConfig = config; + this.iaikConfiguration = iaikConfig; + } + + /** + * Get MOA-SPSS configuration object from start-up process. + * + * @return MOA-SPSS configuration + */ + public ConfigurationProvider getMoaSpssConfig() { + return moaSpssConfig; + } + + /** + * Get configuration object for IAIK modules from start-up process. + * + * @return IAIK module configuration + */ + public ConfigurationData getIaikConfiguration() { + return iaikConfiguration; + } + + + +} diff --git a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/init/SystemInitializer.java b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/init/SystemInitializer.java index 6ef9c57..25bb6d9 100644 --- a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/init/SystemInitializer.java +++ b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/init/SystemInitializer.java @@ -51,6 +51,7 @@ import at.gv.egovernment.moaspss.logging.LoggingContextManager; import at.gv.egovernment.moaspss.util.Constants; import at.gv.egovernment.moaspss.util.DOMUtils; import iaik.asn1.ObjectID; +import iaik.server.ConfigurationData; import iaik.utils.RFC2253NameParser; /** @@ -71,6 +72,8 @@ public class SystemInitializer { private static ServiceLoader initializerServices = ServiceLoader.load(ExternalInitializer.class); + private static ConfigurationData iaikConfiguration; + private static ConfigurationProvider config; private static void runInitializer(ConfigurationProvider configurationProvider) { @@ -84,8 +87,9 @@ public class SystemInitializer { /** * Initialize the MOA SP/SS webservice. + * @return */ - public static void init() { + public static StartupConfigurationHolder init() { logger.info("##############################################################################"); logger.info("##############################################################################"); @@ -141,7 +145,7 @@ public class SystemInitializer { // initialize configuration try { Logger.info("Initialize MOA-SP/SS configuration ... "); - ConfigurationProvider config = ConfigurationProvider.getInstance(); + config = ConfigurationProvider.getInstance(); //initialize TSL module TSLConfiguration moaSPTslConfig = config.getTSLConfiguration(); @@ -168,25 +172,23 @@ public class SystemInitializer { Logger.info("Building IAIK-MOA configuration ... "); - new IaikConfigurator().configure(config); + iaikConfiguration = new IaikConfigurator().configure(config); runInitializer(config); Logger.info(new LogMsg(msg.getMessage("init.01", null))); + } catch (MOAException e) { Logger.fatal(new LogMsg(msg.getMessage("init.00", null)), e); + throw new RuntimeException(e); } catch (Throwable e) { Logger.fatal(new LogMsg(msg.getMessage("init.00", null)), e); throw new RuntimeException(e); - } finally { - logger.info("Configuration initialized"); - } - - - + } + // CHANGE IXSIL to XSECT // set IXSIL debug output //IXSILInit.setPrintDebugLog( @@ -207,6 +209,20 @@ public class SystemInitializer { logger.info("=============================================================================="); logger.info("=== CONFIGURATION DONE ==="); logger.info("=============================================================================="); + + + return new StartupConfigurationHolder(config, iaikConfiguration); + + } + + /** + * Get configuration object from IAIK modules. + * + * @return Configuration or null of it was not configurated yet + */ + public static ConfigurationData getIaikConfiguration() { + return iaikConfiguration; + } private static void initTSLUpdateTask(TSLConfiguration tslconfig) { diff --git a/moaSig/moa-sig/src/main/resources/log4j.properties b/moaSig/moa-sig/src/main/resources/log4j.properties index 8cd351c..d7522a7 100644 --- a/moaSig/moa-sig/src/main/resources/log4j.properties +++ b/moaSig/moa-sig/src/main/resources/log4j.properties @@ -6,15 +6,16 @@ org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.Log4jFactory # Configure root logger and loggers for moa-spss -log4j.rootLogger=warn, stdout -log4j.logger.moa.spss.server=info, stdout, moaspss -log4j.logger.iaik.server=info, stdout, moaspss -log4j.logger.at.gv.egovernment.moa.spss=TRACE, stdout, moaspss +log4j.rootLogger=warn,stdout +#log4j.logger.moa.spss.server=debug,moaspss +#log4j.logger.iaik.server=debug,moaspss +#log4j.logger.iaik.pki=debug,moaspss +#log4j.logger.at.gv.egovernment.moa.spss=debug, moaspss # Configure the 'stdout' appender to write logging output to the console log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%5p | %d{dd HH:mm:ss,SSS} | %C{1} | %20c | %10t | %m%n +log4j.appender.stdout.layout.ConversionPattern=log4j | %5p | %d{dd HH:mm:ss,SSS} | %C{1} | %20c | %10t | %m%n # Configure the 'moaspss' appender to write moa-spss related logging output # to the file '${catalina.base}/logs/moa-spss.log'. The file is rolled over every 1000KB, @@ -24,7 +25,7 @@ log4j.appender.moaspss.File=${catalina.base}/logs/moa-spss.log log4j.appender.moaspss.MaxFileSize=1000KB log4j.appender.moaspss.MaxBackupIndex=10 log4j.appender.moaspss.layout=org.apache.log4j.PatternLayout -log4j.appender.moaspss.layout.ConversionPattern=%5p | %d{dd HH:mm:ss,SSS} | %C{1} | %20c | %10t | %m%n +log4j.appender.moaspss.layout.ConversionPattern=log4j | %5p | %d{dd HH:mm:ss,SSS} | %C{1} | %20c | %10t | %m%n # Configure the jdbc appender 'JDBC' to write logging output # to the given PostgreSQL database diff --git a/moaSig/moa-sig/src/main/resources/logback.xml b/moaSig/moa-sig/src/main/resources/logback.xml new file mode 100644 index 0000000..501c1a6 --- /dev/null +++ b/moaSig/moa-sig/src/main/resources/logback.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + ${catalina.base}/logs/moa-spss.log + + logback | %5p | %d{dd HH:mm:ss,SSS} | %C{1} | %20c | %10t | %m%n + + + 10 + ${catalina.base}/logs/moa-spss.log.%i + + + 1000KB + + + + + logback | %5p | %d{dd HH:mm:ss,SSS} | %C{1} | %20c | %10t | %m%n + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- cgit v1.2.3