>From daab6b8af0014929690edd7146de9ce779179fa6 Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Tue, 22 Jul 2014 00:03:47 -0400 Subject: [PATCH 7/9] Add ability to enable/disable dynamic subsystems The CA installation process requires starting with the profile subsystem disabled, then enabling it once profiles have been loaded into the database. Accordingly, to avoid hacks with hardcoded offsets, add the "enabled" CS.cfg configuration parameter along with methods to enable or disable a subsystem based on the subsystem ID. A disabled subsystem does not have its `init` method called, but it is still instantiated and added to the registry so that other code can look up a subsystem by name and find out its class. Subsystems are enabled by default. This commit also removes an assumption that the subsystem config sub-store names are sequential numbers beginning at `0`. --- base/common/src/com/netscape/certsrv/apps/CMS.java | 22 ++++++++ .../src/com/netscape/certsrv/apps/ICMSEngine.java | 9 +++ .../src/com/netscape/cmscore/apps/CMSEngine.java | 66 ++++++++++++++++------ .../netscape/cmscore/app/CMSEngineDefaultStub.java | 3 + 4 files changed, 83 insertions(+), 17 deletions(-) diff --git a/base/common/src/com/netscape/certsrv/apps/CMS.java b/base/common/src/com/netscape/certsrv/apps/CMS.java index 8b4bac2c0985637ceab6d55bf3d2b9a00b848412..85c8e58ca81c5bc3afc0b13fe3f391a047ba5a8e 100644 --- a/base/common/src/com/netscape/certsrv/apps/CMS.java +++ b/base/common/src/com/netscape/certsrv/apps/CMS.java @@ -509,6 +509,28 @@ public final class CMS { } /** + * Enable the subsystem with the given ID. + * + * Does not start the subsystem. + * + * @param id Subsystem ID. + */ + public static void enableSubsystem(String id) throws EBaseException { + _engine.setSubsystemEnabled(id, true); + } + + /** + * Disable the subsystem with the given ID. + * + * Does not stop the subsystem. + * + * @param id Subsystem ID. + */ + public static void disableSubsystem(String id) throws EBaseException { + _engine.setSubsystemEnabled(id, false); + } + + /** * Retrieves the localized user message from UserMessages.properties. * * @param msgID message id defined in UserMessages.properties diff --git a/base/common/src/com/netscape/certsrv/apps/ICMSEngine.java b/base/common/src/com/netscape/certsrv/apps/ICMSEngine.java index 74fa090038b892713c872025470e4c4d9cb87760..5c78a7c0f9c4144df8369a6017876f900e57605d 100644 --- a/base/common/src/com/netscape/certsrv/apps/ICMSEngine.java +++ b/base/common/src/com/netscape/certsrv/apps/ICMSEngine.java @@ -171,6 +171,15 @@ public interface ICMSEngine extends ISubsystem { public Enumeration getSubsystems(); /** + * Set whether the given subsystem is enabled. + * + * @param id The subsystem ID. + * @param enabled Whether the subsystem is enabled + */ + public void setSubsystemEnabled(String id, boolean enabled) + throws EBaseException; + + /** * Retrieves the registered subsytem with the given name. * * @param name subsystem name diff --git a/base/server/cmscore/src/com/netscape/cmscore/apps/CMSEngine.java b/base/server/cmscore/src/com/netscape/cmscore/apps/CMSEngine.java index 04ff5ec46cab59eaf8e32e709677fcae66a33420..b682130dd43810d7cd2122e5390a2a08889c372d 100644 --- a/base/server/cmscore/src/com/netscape/cmscore/apps/CMSEngine.java +++ b/base/server/cmscore/src/com/netscape/cmscore/apps/CMSEngine.java @@ -29,6 +29,7 @@ import java.security.cert.CertificateEncodingException; import java.security.cert.X509CRL; import java.security.cert.X509Certificate; import java.text.MessageFormat; +import java.util.ArrayList; import java.util.Date; import java.util.Enumeration; import java.util.Hashtable; @@ -181,6 +182,7 @@ public class CMSEngine implements ICMSEngine { private static final String PROP_SUBSYSTEM = "subsystem"; private static final String PROP_ID = "id"; private static final String PROP_CLASS = "class"; + private static final String PROP_ENABLED = "enabled"; private static final String SERVER_XML = "server.xml"; public static final SubsystemRegistry mSSReg = SubsystemRegistry.getInstance(); @@ -866,32 +868,34 @@ public class CMSEngine implements ICMSEngine { } } + private ArrayList getDynSubsystemNames() throws EBaseException { + IConfigStore ssconfig = mConfig.getSubStore(PROP_SUBSYSTEM); + Enumeration ssNames = ssconfig.getSubStoreNames(); + ArrayList ssNamesList = new ArrayList(); + while (ssNames.hasMoreElements()) + ssNamesList.add(ssNames.nextElement()); + return ssNamesList; + } + /** * load dynamic subsystems */ private void loadDynSubsystems() throws EBaseException { - IConfigStore ssconfig = mConfig.getSubStore(PROP_SUBSYSTEM); - - // count number of dyn loaded subsystems. - Enumeration ssnames = ssconfig.getSubStoreNames(); - int nsubsystems = 0; - - for (nsubsystems = 0; ssnames.hasMoreElements(); nsubsystems++) - ssnames.nextElement(); + ArrayList ssNames = getDynSubsystemNames(); if (Debug.ON) { - Debug.trace(nsubsystems + " dyn subsystems loading.."); + Debug.trace(ssNames.size() + " dyn subsystems loading.."); } - if (nsubsystems == 0) - return; // load dyn subsystems. - mDynSubsystems = new SubsystemInfo[nsubsystems]; - for (int i = 0; i < mDynSubsystems.length; i++) { - IConfigStore config = - ssconfig.getSubStore(String.valueOf(i)); + IConfigStore ssconfig = mConfig.getSubStore(PROP_SUBSYSTEM); + mDynSubsystems = new SubsystemInfo[ssNames.size()]; + int i = 0; + for (String ssName : ssNames) { + IConfigStore config = ssconfig.getSubStore(ssName); String id = config.getString(PROP_ID); String classname = config.getString(PROP_CLASS); + boolean enabled = config.getBoolean(PROP_ENABLED, true); ISubsystem ss = null; try { @@ -906,11 +910,29 @@ public class CMSEngine implements ICMSEngine { throw new EBaseException( CMS.getUserMessage("CMS_BASE_LOAD_FAILED_1", id, e.toString())); } - mDynSubsystems[i] = new SubsystemInfo(id, ss); + mDynSubsystems[i++] = new SubsystemInfo(id, ss, enabled); Debug.trace("loaded dyn subsystem " + id); } } + /** + * Set whether the given subsystem is enabled. + * + * @param id The subsystem ID. + * @param enabled Whether the subsystem is enabled + */ + public void setSubsystemEnabled(String id, boolean enabled) + throws EBaseException { + IConfigStore ssconfig = mConfig.getSubStore(PROP_SUBSYSTEM); + for (String ssName : getDynSubsystemNames()) { + IConfigStore config = ssconfig.getSubStore(ssName); + if (id.equalsIgnoreCase(config.getString(PROP_ID))) { + config.putBoolean(PROP_ENABLED, enabled); + break; + } + } + } + public LDAPConnection getBoundConnection(String host, int port, int version, LDAPSSLSocketFactoryExt fac, String bindDN, String bindPW) throws LDAPException { @@ -928,13 +950,17 @@ public class CMSEngine implements ICMSEngine { IConfigStore ssConfig = mConfig.getSubStore(id); CMS.debug("CMSEngine: initSubsystem id=" + id); + mSSReg.put(id, ss); if (doSetId) ss.setId(id); + if (!ssinfo.enabled) { + CMS.debug("CMSEngine: subsystem disabled id=" + id); + return; + } CMS.debug("CMSEngine: ready to init id=" + id); ss.init(this, ssConfig); // add to id - subsystem hash table. CMS.debug("CMSEngine: done init id=" + id); - mSSReg.put(id, ss); CMS.debug("CMSEngine: initialized " + id); if (id.equals("ca") || id.equals("ocsp") || @@ -2001,10 +2027,16 @@ class WarningListener implements ILogEventListener { class SubsystemInfo { public final String mId; public final ISubsystem mInstance; + public final boolean enabled; public SubsystemInfo(String id, ISubsystem ssInstance) { + this(id, ssInstance, true); + } + + public SubsystemInfo(String id, ISubsystem ssInstance, boolean enabled) { mId = id; mInstance = ssInstance; + this.enabled = enabled; } } diff --git a/base/server/test/com/netscape/cmscore/app/CMSEngineDefaultStub.java b/base/server/test/com/netscape/cmscore/app/CMSEngineDefaultStub.java index db39964f2411d169492cad8dc817a0fe4163b765..0b7518d81c516b2073cc54ae69a9b9fb0262c669 100644 --- a/base/server/test/com/netscape/cmscore/app/CMSEngineDefaultStub.java +++ b/base/server/test/com/netscape/cmscore/app/CMSEngineDefaultStub.java @@ -135,6 +135,9 @@ public class CMSEngineDefaultStub implements ICMSEngine { return null; } + public void setSubsystemEnabled(String id, boolean enabled) { + }; + public ISubsystem getSubsystem(String name) { return null; } -- 2.1.0