package at.gv.egovernment.moa.spss.server.init; import java.io.IOException; import java.security.Security; import javax.net.ssl.SSLSocketFactory; import iaik.ixsil.init.IXSILInit; 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.util.Constants; import at.gv.egovernment.moa.util.DOMUtils; import at.gv.egovernment.moa.spss.MOAException; 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.logging.IaikLog; import at.gv.egovernment.moa.spss.server.service.RevocationArchiveCleaner; import at.gv.egovernment.moa.spss.util.MessageProvider; /** * 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; /** * Initialize the MOA SP/SS webservice. */ public static void init() { MessageProvider msg = MessageProvider.getInstance(); ClassLoader cl = SystemInitializer.class.getClassLoader(); 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")); // load some jsse classes so that the integrity of the jars can be verified // before the iaik jce is installed as the security provider // this workaround is only needed when sun jsse is used in conjunction with // iaik-jce (on jdk1.3) try { cl.loadClass("javax.security.cert.Certificate"); // from jcert.jar } catch (ClassNotFoundException e) { Logger.warn(msg.getMessage("init.03", null), e); } // set up SUN JSSE SSL Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); System.setProperty( "java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol"); SSLSocketFactory.getDefault(); // 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(); new IaikConfigurator().configure(config); Logger.info(new LogMsg(msg.getMessage("init.01", null))); } catch (MOAException e) { Logger.fatal(new LogMsg(msg.getMessage("init.00", null)), e); } // set IXSIL debug output IXSILInit.setPrintDebugLog( Logger.isDebugEnabled(IaikLog.IAIK_LOG_HIERARCHY)); // 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); } }