summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFraser Tweedale <ftweedal@redhat.com>2014-07-22 00:03:47 -0400
committerFraser Tweedale <frase@frase.id.au>2015-04-07 22:38:11 -0400
commit2af78cedd82a08046324ea13eb4973d65c80010f (patch)
tree343fab43ad95a4aca9b2988f5299644e2d2af0a0
parent4785f08b9fa14e2abd60533542d763bdea8082a0 (diff)
downloadpki-2af78cedd82a08046324ea13eb4973d65c80010f.tar.gz
pki-2af78cedd82a08046324ea13eb4973d65c80010f.tar.xz
pki-2af78cedd82a08046324ea13eb4973d65c80010f.zip
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`.
-rw-r--r--base/common/src/com/netscape/certsrv/apps/CMS.java22
-rw-r--r--base/common/src/com/netscape/certsrv/apps/ICMSEngine.java9
-rw-r--r--base/server/cmscore/src/com/netscape/cmscore/apps/CMSEngine.java66
-rw-r--r--base/server/test/com/netscape/cmscore/app/CMSEngineDefaultStub.java3
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 8b4bac2c0..85c8e58ca 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 74fa09003..5c78a7c0f 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<ISubsystem> 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 04ff5ec46..b682130dd 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<String> getDynSubsystemNames() throws EBaseException {
+ IConfigStore ssconfig = mConfig.getSubStore(PROP_SUBSYSTEM);
+ Enumeration<String> ssNames = ssconfig.getSubStoreNames();
+ ArrayList<String> ssNamesList = new ArrayList<String>();
+ 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<String> ssnames = ssconfig.getSubStoreNames();
- int nsubsystems = 0;
-
- for (nsubsystems = 0; ssnames.hasMoreElements(); nsubsystems++)
- ssnames.nextElement();
+ ArrayList<String> 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 db39964f2..0b7518d81 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;
}