diff options
Diffstat (limited to 'moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/init')
3 files changed, 326 insertions, 0 deletions
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 new file mode 100644 index 0000000..8ab01d6 --- /dev/null +++ b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/init/ConfiguratorImpl.java @@ -0,0 +1,66 @@ +/* + * Copyright 2003 Federal Chancellery Austria + * MOA-SPSS has been developed in a cooperation between BRZ, the Federal + * Chancellery Austria - ICT staff unit, and Graz University of Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + */ + + +package at.gv.egovernment.moa.spss.server.init; + +import at.gv.egovernment.moa.spss.MOAException; +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; + +/** + * Default implementation of <code>Configurator</code>. + * + * @author Patrick Peck + * @version $Id$ + */ +public class ConfiguratorImpl extends Configurator { + /** whether the configuration has been initialized */ + private boolean initialized = false; + + public void init() throws MOAException { + if (!initialized) { + SystemInitializer.init(); + initialized = true; + } + } + + public void update() throws MOAException { + if (!initialized) { + return; + } + + try { + // reconfigure the system + ConfigurationProvider config = ConfigurationProvider.reload(); + new IaikConfigurator().configure(config); + } catch (MOAException e) { + throw e; + } catch (Throwable t) { + throw new ConfigurationException("", null, t); + } + } + +} diff --git a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/init/ExternalInitializer.java b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/init/ExternalInitializer.java new file mode 100644 index 0000000..692ee53 --- /dev/null +++ b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/init/ExternalInitializer.java @@ -0,0 +1,7 @@ +package at.gv.egovernment.moa.spss.server.init; + +import at.gv.egovernment.moa.spss.server.config.ConfigurationProvider; + +public interface ExternalInitializer { + public void initialize(ConfigurationProvider configurationProvider); +} 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 new file mode 100644 index 0000000..f2663cf --- /dev/null +++ b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/init/SystemInitializer.java @@ -0,0 +1,253 @@ +/* + * Copyright 2003 Federal Chancellery Austria + * MOA-SPSS has been developed in a cooperation between BRZ, the Federal + * Chancellery Austria - ICT staff unit, and Graz University of Technology. + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://www.osor.eu/eupl/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + */ + + +package at.gv.egovernment.moa.spss.server.init; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.security.cert.CertificateException; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.Iterator; +import java.util.ServiceLoader; +import java.util.Timer; + +import org.slf4j.LoggerFactory; + +import at.gv.egovernment.moa.logging.LogMsg; +import at.gv.egovernment.moa.logging.Logger; +import at.gv.egovernment.moa.logging.LoggingContext; +import at.gv.egovernment.moa.logging.LoggingContextManager; +import at.gv.egovernment.moa.spss.MOAException; +import at.gv.egovernment.moa.spss.api.common.TSLConfiguration; +import at.gv.egovernment.moa.spss.server.config.ConfigurationProvider; +import at.gv.egovernment.moa.spss.server.iaik.config.IaikConfigurator; +import at.gv.egovernment.moa.spss.server.service.RevocationArchiveCleaner; +import at.gv.egovernment.moa.spss.tsl.connector.TSLConnector; +import at.gv.egovernment.moa.spss.tsl.timer.TSLUpdaterTimerTask; +import at.gv.egovernment.moa.spss.util.MessageProvider; +import at.gv.egovernment.moa.util.Constants; +import at.gv.egovernment.moa.util.DOMUtils; +import iaik.pki.store.certstore.CertStoreException; +import iaik.pki.store.truststore.TrustStoreException; +import iaik.server.ConfigurationData; +import iaik.xml.crypto.tsl.ex.TSLEngineDiedException; +import iaik.xml.crypto.tsl.ex.TSLSearchException; + +/** + * MOA SP/SS web service initialization. + * + * @author Patrick Peck + * @version $Id$ + */ +public class SystemInitializer { + /** Interval between archive cleanups in seconds */ + private static final long ARCHIVE_CLEANUP_INTERVAL = 60 * 60; // 1h + /** The MOA SP/SS logging hierarchy. */ + private static final String LOGGING_HIERARCHY = "moa.spss.server"; + /** Whether XML schema grammars have been initialized. */ + private static boolean grammarsInitialized = false; + + private static final org.slf4j.Logger logger = LoggerFactory.getLogger(SystemInitializer.class); + + private static ServiceLoader<ExternalInitializer> initializerServices = + ServiceLoader.load(ExternalInitializer.class); + + + private static void runInitializer(ConfigurationProvider configurationProvider) { + Iterator<ExternalInitializer> initializerIterator = initializerServices.iterator(); + + while(initializerIterator.hasNext()) { + ExternalInitializer externalInitializer = initializerIterator.next(); + externalInitializer.initialize(configurationProvider); + } + } + + /** + * Initialize the MOA SP/SS webservice. + */ + public static void init() { + + logger.info("##############################################################################"); + logger.info("##############################################################################"); + logger.info("### ###"); + logger.info("### LOADING MOA-SIG ###"); + logger.info("### =============== ###"); + logger.info("### ###"); + logger.info("##############################################################################"); + logger.info("##############################################################################"); + + MessageProvider msg = MessageProvider.getInstance(); + + Thread archiveCleaner; + + // set up the MOA SPSS logging hierarchy + Logger.setHierarchy(LOGGING_HIERARCHY); + + // set up a logging context for logging the startup + LoggingContextManager.getInstance().setLoggingContext( + new LoggingContext("startup")); + +// AxisProperties.setProperty("enableNamespacePrefixOptimization","false"); +// AxisProperties.setProperty("disablePrettyXML", "true"); +// AxisProperties.setProperty("axis.doAutoTypes", "true"); + + // initialize preparsed Xerces grammar pool for faster XML + // parsing/validating + try { + if (!grammarsInitialized) { + Class clazz = SystemInitializer.class; + // preparse XML schema + DOMUtils.addSchemaToPool( + clazz.getResourceAsStream(Constants.XML_SCHEMA_LOCATION), + Constants.XML_NS_URI); + // preparse XMLDsig Filter2 schema + DOMUtils.addSchemaToPool( + clazz.getResourceAsStream(Constants.DSIG_FILTER2_SCHEMA_LOCATION), + Constants.DSIG_FILTER2_NS_URI); + // preparse XMLDsig schema + DOMUtils.addSchemaToPool( + clazz.getResourceAsStream(Constants.DSIG_SCHEMA_LOCATION), + Constants.DSIG_NS_URI); + // preparse MOA schema + DOMUtils.addSchemaToPool( + clazz.getResourceAsStream(Constants.MOA_SCHEMA_LOCATION), + Constants.MOA_NS_URI); + grammarsInitialized = true; + } + } catch (IOException e) { + Logger.warn(new LogMsg(msg.getMessage("init.04", null)), e); + } + + // initialize configuration + try { + ConfigurationProvider config = ConfigurationProvider.getInstance(); + Logger.info("Building ConfigurationData"); + ConfigurationData configData = new IaikConfigurator().configure(config); + + //initialize TSL module + TSLConfiguration tslconfig = config.getTSLConfiguration(); + + TSLConnector tslconnector = new TSLConnector(); + if (tslconfig != null) { + //Logger.info(new LogMsg(msg.getMessage("init.01", null))); + Logger.info(new LogMsg(msg.getMessage("config.41", null))); + tslconnector.initialize(tslconfig.getEuTSLUrl(), tslconfig.getWorkingDirectory(), null, null); + + } + + //start TSL Update + TSLUpdaterTimerTask.tslconnector_ = tslconnector; + TSLUpdaterTimerTask.configData_ = configData; + TSLUpdaterTimerTask.update(); + + //initialize TSL Update Task + initTSLUpdateTask(tslconfig); + + runInitializer(config); + + Logger.info(new LogMsg(msg.getMessage("init.01", null))); + } catch (MOAException e) { + Logger.fatal(new LogMsg(msg.getMessage("init.00", null)), e); + } + catch (TSLEngineDiedException e) { + Logger.fatal(new LogMsg(msg.getMessage("init.00", null)), e); + } + catch (TSLSearchException e) { + Logger.fatal(new LogMsg(msg.getMessage("init.00", null)), e); + } + catch (CertStoreException e) { + Logger.fatal(new LogMsg(msg.getMessage("init.00", null)), e); + } catch (TrustStoreException e) { + Logger.fatal(new LogMsg(msg.getMessage("init.00", null)), e); + } catch (FileNotFoundException e) { + Logger.fatal(new LogMsg(msg.getMessage("init.00", null)), e); + } catch (IOException e) { + Logger.fatal(new LogMsg(msg.getMessage("init.00", null)), e); + } catch (CertificateException e) { + Logger.fatal(new LogMsg(msg.getMessage("init.00", null)), e); + } + + + + // CHANGE IXSIL to XSECT + // set IXSIL debug output + //IXSILInit.setPrintDebugLog( + // Logger.isDebugEnabled(IaikLog.IAIK_LOG_HIERARCHY)); + //Logger.info("Registering XSECT"); + //XSecProvider.addAsProvider(true); + + // start the archive cleanup thread + archiveCleaner = + new Thread(new RevocationArchiveCleaner(ARCHIVE_CLEANUP_INTERVAL)); + archiveCleaner.setName("RevocationArchiveCleaner"); + archiveCleaner.setDaemon(true); + archiveCleaner.setPriority(Thread.MIN_PRIORITY); + archiveCleaner.start(); + + // unset the startup logging context + LoggingContextManager.getInstance().setLoggingContext(null); + logger.info("=============================================================================="); + logger.info("=== CONFIGURATION DONE ==="); + logger.info("=============================================================================="); + } + + private static void initTSLUpdateTask(TSLConfiguration tslconfig) { + MessageProvider msg = MessageProvider.getInstance(); + if (tslconfig != null) { + // get start time and period from config + long period = tslconfig.getUpdateSchedulePeriod(); + Date startConfig = tslconfig.getUpdateScheduleStartTime(); + + // get hh:mm:ss from config date + Calendar calendar = GregorianCalendar.getInstance(); // creates a new calendar instance + calendar.setTime(startConfig); // assigns calendar to given date + int hour = calendar.get(Calendar.HOUR_OF_DAY); + int min = calendar.get(Calendar.MINUTE); + int sec = calendar.get(Calendar.SECOND); + + // create date with today and time from config + Calendar cal = Calendar.getInstance(); + Date now = cal.getTime(); + cal.set(Calendar.HOUR_OF_DAY, hour); + cal.set(Calendar.MINUTE, min); + cal.set(Calendar.SECOND, sec); + + // proposed start time + Date start = cal.getTime(); + + // if start time has already passed today - add one day (86400000 milliseconds = 1 day) + if (start.before(now)) + start = new Date(start.getTime() + 86400000); + + Logger.debug(new LogMsg(msg.getMessage("config.46", new String[]{start.toString(), "" + period}))); + + // start TSL updater task + Timer timer = new Timer(); + timer.schedule(new TSLUpdaterTimerTask(), start, period); + } + } + +} |