>From 5c9ddc197269e3ef89a199a8e45039838261fb4f Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Tue, 22 Jul 2014 00:03:47 -0400 Subject: [PATCH 07/10] 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. 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 | 64 ++++++++++++++++------ .../netscape/cmscore/app/CMSEngineDefaultStub.java | 3 + 4 files changed, 82 insertions(+), 16 deletions(-) diff --git a/base/common/src/com/netscape/certsrv/apps/CMS.java b/base/common/src/com/netscape/certsrv/apps/CMS.java index 63c1a2cbde2ffdb0ce116c664ab373aeba91f5a3..38a69945be2100cf3538c3924f00fa9e7c409cc7 100644 --- a/base/common/src/com/netscape/certsrv/apps/CMS.java +++ b/base/common/src/com/netscape/certsrv/apps/CMS.java @@ -511,6 +511,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 68c64824e37bcad282a5bbeabf6b943fabf39481..2641057d9ad6d4de751f7215d52374b08eceb1f8 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,6 +950,10 @@ public class CMSEngine implements ICMSEngine { IConfigStore ssConfig = mConfig.getSubStore(id); CMS.debug("CMSEngine: initSubsystem id=" + id); + if (!ssinfo.enabled) { + CMS.debug("CMSEngine: subsystem disabled id=" + id); + return; + } if (doSetId) ss.setId(id); CMS.debug("CMSEngine: ready to init id=" + id); @@ -2000,10 +2026,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; } -- 1.9.3