[Pki-devel] [PATCH] 0031..0033 minor LDAPProfileSubsystem fixes
Fraser Tweedale
ftweedal at redhat.com
Mon Apr 13 06:12:20 UTC 2015
These patches address the issues outlined in
https://www.redhat.com/archives/pki-devel/2015-April/msg00028.html.
-------------- next part --------------
>From 0e708eb63173588a10c866d6a910a53b2f9d5efd Mon Sep 17 00:00:00 2001
From: Fraser Tweedale <frase at frase.id.au>
Date: Mon, 13 Apr 2015 00:29:09 -0400
Subject: [PATCH 31/33] Remove unneeded collection from profile subsystems
Caveat: This changes the order in which profiles are listed, but the
previous order doesn't seem very logical and there doesn't appear to
be any contract for a particular order.
---
.../src/com/netscape/cmscore/profile/AbstractProfileSubsystem.java | 3 +--
.../src/com/netscape/cmscore/profile/LDAPProfileSubsystem.java | 5 -----
.../cmscore/src/com/netscape/cmscore/profile/ProfileSubsystem.java | 4 ----
3 files changed, 1 insertion(+), 11 deletions(-)
diff --git a/base/server/cmscore/src/com/netscape/cmscore/profile/AbstractProfileSubsystem.java b/base/server/cmscore/src/com/netscape/cmscore/profile/AbstractProfileSubsystem.java
index b7cd503a142fc0c3065c7d19de5229c7490613f4..642f60232806eaadc68398bd21d2912dc920cda9 100644
--- a/base/server/cmscore/src/com/netscape/cmscore/profile/AbstractProfileSubsystem.java
+++ b/base/server/cmscore/src/com/netscape/cmscore/profile/AbstractProfileSubsystem.java
@@ -36,7 +36,6 @@ public abstract class AbstractProfileSubsystem implements IProfileSubsystem {
protected IConfigStore mConfig = null;
@SuppressWarnings("unused")
protected ISubsystem mOwner;
- protected Vector<String> mProfileIds;
protected Hashtable<String, IProfile> mProfiles;
protected Hashtable<String, String> mProfileClassIds;
@@ -133,7 +132,7 @@ public abstract class AbstractProfileSubsystem implements IProfileSubsystem {
* list is of type String.
*/
public Enumeration<String> getProfileIds() {
- return mProfileIds.elements();
+ return mProfiles.keys();
}
/**
diff --git a/base/server/cmscore/src/com/netscape/cmscore/profile/LDAPProfileSubsystem.java b/base/server/cmscore/src/com/netscape/cmscore/profile/LDAPProfileSubsystem.java
index 92aa827b1bcb348ed0b5a5df355c8ef98f265a6c..c7963498dfffe90ec6b9cd83d351385a8686f913 100644
--- a/base/server/cmscore/src/com/netscape/cmscore/profile/LDAPProfileSubsystem.java
+++ b/base/server/cmscore/src/com/netscape/cmscore/profile/LDAPProfileSubsystem.java
@@ -73,7 +73,6 @@ public class LDAPProfileSubsystem
CMS.debug("LDAPProfileSubsystem: start init");
// (re)init member collections
- mProfileIds = new Vector<String>();
mProfiles = new Hashtable<String, IProfile>();
mProfileClassIds = new Hashtable<String, String>();
@@ -163,8 +162,6 @@ public class LDAPProfileSubsystem
IProfile profile = (IProfile) Class.forName(className).newInstance();
profile.setId(id);
profile.init(this, subStoreConfig);
- if (!mProfiles.containsKey(id))
- mProfileIds.addElement(id);
mProfiles.put(id, profile);
mProfileClassIds.put(id, classid);
return profile;
@@ -216,7 +213,6 @@ public class LDAPProfileSubsystem
* notification that a profile was deleted.
*/
private void forgetProfile(String id) {
- mProfileIds.removeElement(id);
mProfiles.remove(id);
mProfileClassIds.remove(id);
}
@@ -250,7 +246,6 @@ public class LDAPProfileSubsystem
}
private void forgetAllProfiles() {
- mProfileIds.clear();
mProfiles.clear();
mProfileClassIds.clear();
}
diff --git a/base/server/cmscore/src/com/netscape/cmscore/profile/ProfileSubsystem.java b/base/server/cmscore/src/com/netscape/cmscore/profile/ProfileSubsystem.java
index 9a7292f2cbe03d2a9cc06d47e8bd52552dec94d7..b2b4b30f22926c0e4e00b106115e1818402e59e6 100644
--- a/base/server/cmscore/src/com/netscape/cmscore/profile/ProfileSubsystem.java
+++ b/base/server/cmscore/src/com/netscape/cmscore/profile/ProfileSubsystem.java
@@ -55,7 +55,6 @@ public class ProfileSubsystem
IPluginRegistry registry = (IPluginRegistry)
CMS.getSubsystem(CMS.SUBSYSTEM_REGISTRY);
- mProfileIds = new Vector<String>();
mProfiles = new Hashtable<String, IProfile>();
mProfileClassIds = new Hashtable<String, String>();
@@ -126,7 +125,6 @@ public class ProfileSubsystem
CMS.debug("ProfileSubsystem: initing " + className);
profile.setId(id);
profile.init(this, subStoreConfig);
- mProfileIds.addElement(id);
mProfiles.put(id, profile);
mProfileClassIds.put(id, classid);
if (isNew)
@@ -179,7 +177,6 @@ public class ProfileSubsystem
if (!file1.delete()) {
CMS.debug("ProfileSubsystem: deleteProfile: Cannot delete the configuration file : " + configPath);
}
- mProfileIds.removeElement(id);
mProfiles.remove(id);
mProfileClassIds.remove(id);
try {
@@ -226,7 +223,6 @@ public class ProfileSubsystem
* <P>
*/
public void shutdown() {
- mProfileIds.clear();
mProfiles.clear();
mProfileClassIds.clear();
}
--
2.1.0
-------------- next part --------------
>From 785e4bc2298677c8a322b00b7d42a7c7e67fe4c5 Mon Sep 17 00:00:00 2001
From: Fraser Tweedale <frase at frase.id.au>
Date: Mon, 13 Apr 2015 01:19:58 -0400
Subject: [PATCH 32/33] Get profile ID from DN instead of CN attribute
---
.../cmscore/profile/LDAPProfileSubsystem.java | 23 +++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/base/server/cmscore/src/com/netscape/cmscore/profile/LDAPProfileSubsystem.java b/base/server/cmscore/src/com/netscape/cmscore/profile/LDAPProfileSubsystem.java
index c7963498dfffe90ec6b9cd83d351385a8686f913..cdb5a36a95e9cf25429b80b27686416d28a05632 100644
--- a/base/server/cmscore/src/com/netscape/cmscore/profile/LDAPProfileSubsystem.java
+++ b/base/server/cmscore/src/com/netscape/cmscore/profile/LDAPProfileSubsystem.java
@@ -35,6 +35,7 @@ import netscape.ldap.LDAPSearchResults;
import netscape.ldap.controls.LDAPEntryChangeControl;
import netscape.ldap.controls.LDAPPersistSearchControl;
import netscape.ldap.util.DN;
+import netscape.security.x509.X500Name;
import com.netscape.certsrv.apps.CMS;
import com.netscape.certsrv.base.EBaseException;
@@ -106,8 +107,14 @@ public class LDAPProfileSubsystem
IPluginRegistry registry = (IPluginRegistry)
CMS.getSubsystem(CMS.SUBSYSTEM_REGISTRY);
- String profileId = (String)
- ldapProfile.getAttribute("cn").getStringValues().nextElement();
+ String profileId = null;
+ String dn = ldapProfile.getDN();
+ try {
+ profileId = new X500Name(dn).getCommonName();
+ } catch (IOException e) {
+ CMS.debug("Error reading profile entry: DN " + dn + "has no common name");
+ return;
+ }
String classId = (String)
ldapProfile.getAttribute("classId").getStringValues().nextElement();
@@ -218,13 +225,15 @@ public class LDAPProfileSubsystem
}
private void forgetProfile(LDAPEntry entry) {
- String profileId = (String)
- entry.getAttribute("cn").getStringValues().nextElement();
- if (profileId == null) {
+ String profileId = null;
+ String dn = entry.getDN();
+ try {
+ profileId = new X500Name(dn).getCommonName();
+ } catch (IOException e) {
CMS.debug("forgetProfile: error retrieving cn (profileId) from LDAPEntry");
- } else {
- forgetProfile(profileId);
+ return;
}
+ forgetProfile(profileId);
}
/**
--
2.1.0
-------------- next part --------------
>From f30a0339cdd12dd49af5b9e2e12a5c96a5968d4f Mon Sep 17 00:00:00 2001
From: Fraser Tweedale <frase at frase.id.au>
Date: Mon, 13 Apr 2015 02:00:10 -0400
Subject: [PATCH 33/33] Consolidate profile persistent search try/catch blocks
---
.../cmscore/profile/LDAPProfileSubsystem.java | 30 +++++++++++-----------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/base/server/cmscore/src/com/netscape/cmscore/profile/LDAPProfileSubsystem.java b/base/server/cmscore/src/com/netscape/cmscore/profile/LDAPProfileSubsystem.java
index cdb5a36a95e9cf25429b80b27686416d28a05632..1bf08dc8fffb3f5a6276a1b96ddc4503d10cf11a 100644
--- a/base/server/cmscore/src/com/netscape/cmscore/profile/LDAPProfileSubsystem.java
+++ b/base/server/cmscore/src/com/netscape/cmscore/profile/LDAPProfileSubsystem.java
@@ -277,7 +277,7 @@ public class LDAPProfileSubsystem
LDAPPersistSearchControl persistCtrl =
new LDAPPersistSearchControl(op, false, true, true);
- LDAPConnection conn;
+ LDAPConnection conn = null;
CMS.debug("Profile change monitor: starting.");
@@ -285,16 +285,6 @@ public class LDAPProfileSubsystem
forgetAllProfiles();
try {
conn = dbFactory.getConn();
- } catch (ELdapException e) {
- CMS.debug("Profile change monitor: failed to get LDAPConnection. Retrying in 1 second.");
- try {
- Thread.sleep(1000);
- } catch (InterruptedException ex) {
- Thread.currentThread().interrupt();
- }
- continue;
- }
- try {
LDAPSearchConstraints cons = conn.getSearchConstraints();
cons.setServerControls(persistCtrl);
cons.setBatchSize(1);
@@ -343,13 +333,23 @@ public class LDAPProfileSubsystem
readProfile(entry);
}
}
+ } catch (ELdapException e) {
+ CMS.debug("Profile change monitor: failed to get LDAPConnection. Retrying in 1 second.");
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException ex) {
+ Thread.currentThread().interrupt();
+ }
} catch (LDAPException e) {
CMS.debug("Profile change monitor: Caught exception: " + e.toString());
} finally {
- try {
- dbFactory.returnConn(conn);
- } catch (Exception e) {
- CMS.debug("Profile change monitor: Error releasing the LDAPConnection" + e.toString());
+ if (conn != null) {
+ try {
+ dbFactory.returnConn(conn);
+ conn = null;
+ } catch (Exception e) {
+ CMS.debug("Profile change monitor: Error releasing the LDAPConnection" + e.toString());
+ }
}
}
}
--
2.1.0
More information about the Pki-devel
mailing list