Skip to content

Commit

Permalink
Add LDAPPublishingConfig
Browse files Browse the repository at this point in the history
The LDAPPublishingConfig has been modified to encapsulate
ca.publish.ldappublish.* params.
  • Loading branch information
edewata committed Sep 18, 2023
1 parent 08ad580 commit bf1d20f
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import com.netscape.cmscore.apps.CMS;
import com.netscape.cmscore.base.ConfigStore;
import com.netscape.cmscore.ldap.CAPublisherProcessor;
import com.netscape.cmscore.ldap.LDAPPublishingConfig;
import com.netscape.cmscore.ldap.LdapRule;
import com.netscape.cmscore.ldap.PublisherProcessor;
import com.netscape.cmscore.ldap.PublishingConfig;
Expand Down Expand Up @@ -449,8 +450,8 @@ private void getLDAPDest(HttpServletRequest req,
CAEngine engine = CAEngine.getInstance();
CAConfig config = engine.getConfig().getCAConfig();
PublishingConfig publishcfg = config.getPublishingConfig();
ConfigStore ldapcfg = publishcfg.getSubStore(PublisherProcessor.PROP_LDAP_PUBLISH_SUBSTORE, ConfigStore.class);
ConfigStore ldap = ldapcfg.getSubStore(PublisherProcessor.PROP_LDAP, ConfigStore.class);
LDAPPublishingConfig ldapcfg = publishcfg.getLDAPPublishingConfig();
LDAPConfig ldap = ldapcfg.getLDAPConfig();

Enumeration<String> e = req.getParameterNames();

Expand Down Expand Up @@ -507,8 +508,7 @@ private void getLDAPDest(HttpServletRequest req,
publishcfg.getString(Constants.PR_PUBLISHING_QUEUE_PRIORITY, "0"));
params.put(Constants.PR_PUBLISHING_QUEUE_STATUS,
publishcfg.getString(Constants.PR_PUBLISHING_QUEUE_STATUS, "200"));
params.put(Constants.PR_ENABLE,
ldapcfg.getString(PublisherProcessor.PROP_ENABLE, Constants.FALSE));
params.put(Constants.PR_ENABLE, ldapcfg.getEnable());
sendResponse(SUCCESS, null, params, resp);
}

Expand All @@ -520,14 +520,14 @@ private void setLDAPDest(HttpServletRequest req, HttpServletResponse resp)

//Save New Settings to the config file
PublishingConfig publishcfg = config.getPublishingConfig();
ConfigStore ldapcfg = publishcfg.getSubStore(PublisherProcessor.PROP_LDAP_PUBLISH_SUBSTORE, ConfigStore.class);
ConfigStore ldap = ldapcfg.getSubStore(PublisherProcessor.PROP_LDAP, ConfigStore.class);
LDAPPublishingConfig ldapcfg = publishcfg.getLDAPPublishingConfig();
LDAPConfig ldap = ldapcfg.getLDAPConfig();

//set enable flag
publishcfg.putString(PublisherProcessor.PROP_ENABLE, req.getParameter(Constants.PR_PUBLISHING_ENABLE));
String enable = req.getParameter(Constants.PR_ENABLE);

ldapcfg.putString(PublisherProcessor.PROP_ENABLE, enable);
ldapcfg.setEnable(enable);
if (enable.equals("false")) {
// need to disable the ldap module here
mProcessor.setLdapConnModule(null);
Expand Down Expand Up @@ -645,16 +645,16 @@ private void testSetLDAPDest(HttpServletRequest req, HttpServletResponse resp)

//Save New Settings to the config file
PublishingConfig publishcfg = config.getPublishingConfig();
ConfigStore ldapcfg = publishcfg.getSubStore(PublisherProcessor.PROP_LDAP_PUBLISH_SUBSTORE, ConfigStore.class);
LDAPConfig ldap = ldapcfg.getSubStore(PublisherProcessor.PROP_LDAP, LDAPConfig.class);
LDAPPublishingConfig ldapcfg = publishcfg.getLDAPPublishingConfig();
LDAPConfig ldap = ldapcfg.getLDAPConfig();
LDAPAuthenticationConfig authConfig = ldap.getAuthenticationConfig();

//set enable flag
publishcfg.putString(PublisherProcessor.PROP_ENABLE,
req.getParameter(Constants.PR_PUBLISHING_ENABLE));
String ldapPublish = req.getParameter(Constants.PR_ENABLE);

ldapcfg.putString(PublisherProcessor.PROP_ENABLE, ldapPublish);
ldapcfg.setEnable(ldapPublish);
if (ldapPublish.equals("false")) {
// need to disable the ldap module here
mProcessor.setLdapConnModule(null);
Expand Down Expand Up @@ -711,7 +711,7 @@ private void testSetLDAPDest(HttpServletRequest req, HttpServletResponse resp)

// test before commit
if (publishcfg.getBoolean(PublisherProcessor.PROP_ENABLE) &&
ldapcfg.getBoolean(PublisherProcessor.PROP_ENABLE)) {
ldapcfg.isEnabled()) {
params.put("title",
"You've attempted to configure CMS to connect" +
" to a LDAP directory. The connection status is" +
Expand Down Expand Up @@ -908,8 +908,7 @@ private void testSetLDAPDest(HttpServletRequest req, HttpServletResponse resp)
}

//commit(true);
if (ldapcfg.getBoolean(PublisherProcessor.PROP_ENABLE) &&
pwd != null) {
if (ldapcfg.isEnabled() && pwd != null) {

/* Do a "PUT" of the new pw to the watchdog"
** do not remove - cfu
Expand Down Expand Up @@ -952,7 +951,7 @@ private void testSetLDAPDest(HttpServletRequest req, HttpServletResponse resp)
mProcessor.startup();
//params.add("restarted", "Publishing is restarted.");

if (ldapcfg.getBoolean(PublisherProcessor.PROP_ENABLE)) {
if (ldapcfg.isEnabled()) {
CertificateAuthority ca = mProcessor.getAuthority();

// publish ca cert
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// Copyright Red Hat, Inc.
//
// SPDX-License-Identifier: GPL-2.0-or-later
//
package com.netscape.cmscore.ldap;

import com.netscape.certsrv.base.EBaseException;
import com.netscape.certsrv.common.Constants;
import com.netscape.cmscore.base.ConfigStorage;
import com.netscape.cmscore.base.ConfigStore;
import com.netscape.cmscore.base.SimpleProperties;
import com.netscape.cmscore.ldapconn.LDAPConfig;

/**
* Provides ca.publish.ldappublish.* parameters.
*/
public class LDAPPublishingConfig extends ConfigStore {

public LDAPPublishingConfig() {
}

public LDAPPublishingConfig(ConfigStorage storage) {
super(storage);
}

public LDAPPublishingConfig(String name, SimpleProperties source) {
super(name, source);
}

/**
* Returns ca.publish.ldappublish.enable parameter.
*/
public boolean isEnabled() throws EBaseException {
return getBoolean("enable", false);
}

public String getEnable() throws EBaseException {
return getString("enable", Constants.FALSE);
}

public void setEnable(String enable) throws EBaseException {
putString("enable", enable);
}

/**
* Returns ca.publish.ldappublish.ldap.* parameters.
*/
public LDAPConfig getLDAPConfig() throws EBaseException {
return getSubStore("ldap", LDAPConfig.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ public abstract class PublisherProcessor {

public static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(PublisherProcessor.class);

public final static String PROP_LDAP_PUBLISH_SUBSTORE = "ldappublish";

public final static String PROP_CLASS = "class";
public final static String PROP_IMPL = "impl";
public final static String PROP_PLUGIN = "pluginName";
Expand All @@ -66,7 +64,7 @@ public abstract class PublisherProcessor {
protected LdapConnModule mLdapConnModule;

protected PublishingConfig mConfig;
protected ConfigStore mLdapConfig;
protected LDAPPublishingConfig mLdapConfig;
protected String mId;

protected RequestListener requestListener;
Expand Down Expand Up @@ -355,8 +353,8 @@ private void initLdapConn(ConfigStore ldapConfig)

public void startup() throws EBaseException {
logger.debug("PublisherProcessor: startup()");
mLdapConfig = mConfig.getSubStore(PROP_LDAP_PUBLISH_SUBSTORE, ConfigStore.class);
if (mLdapConfig.getBoolean(PROP_ENABLE, false)) {
mLdapConfig = mConfig.getLDAPPublishingConfig();
if (mLdapConfig.isEnabled()) {
logger.debug("PublisherProcessor: about to initLdapConn");
initLdapConn(mLdapConfig);
} else {
Expand Down Expand Up @@ -813,7 +811,7 @@ public Vector<String> getRuleInstanceParams(String implName) throws
*/
public boolean ldapEnabled() {
try {
return mInited && mLdapConfig.getBoolean(PROP_ENABLE, false);
return mInited && mLdapConfig.isEnabled();
} catch (EBaseException e) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,11 @@ public PublishingRuleConfig getRuleConfig() {
public PublishingQueueConfig getQueueConfig() {
return getSubStore("queue", PublishingQueueConfig.class);
}

/**
* Returns ca.publish.ldappublish.* parameters.
*/
public LDAPPublishingConfig getLDAPPublishingConfig() {
return getSubStore("ldappublish", LDAPPublishingConfig.class);
}
}

0 comments on commit bf1d20f

Please sign in to comment.