summaryrefslogtreecommitdiffstats
path: root/base/server
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2015-02-11 13:57:44 -0500
committerEndi S. Dewata <edewata@redhat.com>2015-02-11 14:50:01 -0500
commitcdad249ce00305a165d272d86f100d05edf97db2 (patch)
tree80c9a5d565e1f1ce804ea44971569ee08d55e268 /base/server
parent91c77390474d67cfd0c15b8b3377997b3f0cd38a (diff)
downloadpki-cdad249ce00305a165d272d86f100d05edf97db2.tar.gz
pki-cdad249ce00305a165d272d86f100d05edf97db2.tar.xz
pki-cdad249ce00305a165d272d86f100d05edf97db2.zip
Refactored LDAPDatabase.createFilter().
The createFilter() method in LDAPDatabase has been changed to construct an LDAP filter based on a keyword and a set of attributes with their values. This will allow searching the database based on specific attribute values. The subclasses of LDAPDatabase have been updated accordingly. https://fedorahosted.org/pki/ticket/1164
Diffstat (limited to 'base/server')
-rw-r--r--base/server/cmscore/src/com/netscape/cmscore/dbs/LDAPDatabase.java26
1 files changed, 23 insertions, 3 deletions
diff --git a/base/server/cmscore/src/com/netscape/cmscore/dbs/LDAPDatabase.java b/base/server/cmscore/src/com/netscape/cmscore/dbs/LDAPDatabase.java
index 0e3ffc13b..3e9f25e95 100644
--- a/base/server/cmscore/src/com/netscape/cmscore/dbs/LDAPDatabase.java
+++ b/base/server/cmscore/src/com/netscape/cmscore/dbs/LDAPDatabase.java
@@ -6,6 +6,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Enumeration;
+import java.util.Map;
import com.netscape.certsrv.apps.CMS;
import com.netscape.certsrv.base.EBaseException;
@@ -17,6 +18,7 @@ import com.netscape.certsrv.dbs.IDBSearchResults;
import com.netscape.certsrv.dbs.IDBSubsystem;
import com.netscape.certsrv.dbs.Modification;
import com.netscape.certsrv.dbs.ModificationSet;
+import com.netscape.cmsutil.ldap.LDAPUtil;
/**
* This class implements LDAP database.
@@ -98,15 +100,33 @@ public abstract class LDAPDatabase<E extends IDBObj> extends Database<E> {
}
public abstract String createDN(String id);
- public abstract String createFilter(String filter);
+ public abstract String createFilter(String keyword, Map<String, String> attributes);
+
+ public void createFilter(StringBuilder sb, Map<String, String> attributes) {
+
+ // if no attributes specified, don't change filter
+ if (attributes == null || attributes.isEmpty()) return;
+
+ // wrap current filter with attribute matching filter
+ sb.insert(0, "(&");
+ for (Map.Entry<String, String> entry : attributes.entrySet()) {
+ sb.append("(" + entry.getKey() + "=" + LDAPUtil.escapeFilter(entry.getValue()) + ")");
+ }
+ sb.append(")");
+ }
@Override
- public Collection<E> findRecords(String filter) throws Exception {
+ public Collection<E> findRecords(String keyword) throws Exception {
+ return findRecords(keyword, null);
+ }
+
+ public Collection<E> findRecords(String keyword, Map<String, String> attributes) throws Exception {
+
CMS.debug("LDAPDatabase: findRecords()");
try (IDBSSession session = dbSubsystem.createSession()) {
Collection<E> list = new ArrayList<E>();
- String ldapFilter = createFilter(filter);
+ String ldapFilter = createFilter(keyword, attributes);
CMS.debug("LDAPDatabase: searching " + baseDN + " with filter " + ldapFilter);
IDBSearchResults results = session.search(baseDN, ldapFilter);