From 3358adfa62a1e021f158f726a640e0ee3d2217aa Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Mon, 17 Mar 2014 11:40:42 -0400
Subject: [PATCH] Added search filter for TPS resources.

The TPS resources have been modified to accept a basic search filter
for find operation. For resources based on LDAP database, the filtering
is done using LDAP filter. For other resources, the filtering is done
using string comparison. For now the filter is will only be matched
against entry IDs. In the future the filter may be expanded to support
other entry attributes. The CLI has been updated accordingly.

The total attribute in DataCollection was changed from Integer into int
because the total size of the collection cannot be null.

The PKIException constructors have been consolidated into a single
actual constructor. The other constructors have been modified to
call the actual constructor with some default values.

Ticket #847
---
 .../com/netscape/certsrv/base/DataCollection.java  |  6 ++--
 .../com/netscape/certsrv/base/PKIException.java    | 39 ++++++++++------------
 .../netscape/certsrv/logging/ActivityClient.java   |  8 ++---
 .../netscape/certsrv/logging/ActivityResource.java |  1 +
 .../netscape/certsrv/selftests/SelfTestClient.java |  4 +--
 .../certsrv/selftests/SelfTestResource.java        |  1 +
 .../tps/authenticator/AuthenticatorClient.java     |  4 +--
 .../tps/authenticator/AuthenticatorResource.java   |  1 +
 .../netscape/certsrv/tps/cert/TPSCertClient.java   |  4 +--
 .../netscape/certsrv/tps/cert/TPSCertResource.java |  1 +
 .../certsrv/tps/connection/ConnectionClient.java   |  4 +--
 .../certsrv/tps/connection/ConnectionResource.java |  1 +
 .../certsrv/tps/profile/ProfileClient.java         |  4 +--
 .../certsrv/tps/profile/ProfileMappingClient.java  |  4 +--
 .../tps/profile/ProfileMappingResource.java        |  1 +
 .../certsrv/tps/profile/ProfileResource.java       |  1 +
 .../netscape/certsrv/tps/token/TokenClient.java    |  4 +--
 .../netscape/certsrv/tps/token/TokenResource.java  |  1 +
 .../netscape/cmstools/logging/ActivityFindCLI.java |  7 ++--
 .../cmstools/selftests/SelfTestFindCLI.java        |  7 ++--
 .../tps/authenticator/AuthenticatorFindCLI.java    |  7 ++--
 .../netscape/cmstools/tps/cert/TPSCertFindCLI.java |  7 ++--
 .../cmstools/tps/connection/ConnectionFindCLI.java |  7 ++--
 .../cmstools/tps/profile/ProfileFindCLI.java       |  7 ++--
 .../tps/profile/ProfileMappingFindCLI.java         |  7 ++--
 .../netscape/cmstools/tps/token/TokenFindCLI.java  |  7 ++--
 .../org/dogtagpki/server/rest/GroupService.java    |  3 +-
 .../org/dogtagpki/server/rest/SelfTestService.java | 14 ++++++--
 .../src/org/dogtagpki/server/rest/UserService.java | 16 +++++++--
 .../src/com/netscape/cmscore/dbs/Database.java     | 15 +++++++--
 .../src/com/netscape/cmscore/dbs/LDAPDatabase.java | 11 +++---
 .../server/tps/config/ConfigDatabase.java          |  5 +--
 .../server/tps/config/ConnectionDatabase.java      |  3 +-
 .../server/tps/config/ProfileDatabase.java         |  3 +-
 .../server/tps/config/ProfileMappingDatabase.java  |  3 +-
 .../dogtagpki/server/tps/dbs/ActivityDatabase.java |  5 ++-
 .../server/tps/dbs/AuthenticatorDatabase.java      |  3 +-
 .../dogtagpki/server/tps/dbs/TPSCertDatabase.java  |  5 ++-
 .../dogtagpki/server/tps/dbs/TokenDatabase.java    |  5 ++-
 .../dogtagpki/server/tps/rest/ActivityService.java |  4 +--
 .../server/tps/rest/AuthenticatorService.java      |  4 +--
 .../server/tps/rest/ConnectionService.java         |  4 +--
 .../server/tps/rest/ProfileMappingService.java     |  4 +--
 .../dogtagpki/server/tps/rest/ProfileService.java  |  4 +--
 .../dogtagpki/server/tps/rest/TPSCertService.java  |  4 +--
 .../dogtagpki/server/tps/rest/TokenService.java    |  4 +--
 46 files changed, 169 insertions(+), 95 deletions(-)

diff --git a/base/common/src/com/netscape/certsrv/base/DataCollection.java b/base/common/src/com/netscape/certsrv/base/DataCollection.java
index f5f46bcb8fb6c4ac1244f54e29600fdf7aca20a8..ecbef0a6bed96f9f29f52c9b617dd0047e12ece7 100644
--- a/base/common/src/com/netscape/certsrv/base/DataCollection.java
+++ b/base/common/src/com/netscape/certsrv/base/DataCollection.java
@@ -30,15 +30,15 @@ import org.jboss.resteasy.plugins.providers.atom.Link;
  */
 public class DataCollection<E> {
 
-    Integer total;
+    int total;
     Collection<E> entries = new ArrayList<E>();
     Collection<Link> links = new ArrayList<Link>();
 
-    public Integer getTotal() {
+    public int getTotal() {
         return total;
     }
 
-    public void setTotal(Integer total) {
+    public void setTotal(int total) {
         this.total = total;
     }
 
diff --git a/base/common/src/com/netscape/certsrv/base/PKIException.java b/base/common/src/com/netscape/certsrv/base/PKIException.java
index f89c1b18ce192226fa137d82ae107dbf074f1b32..9c89e9028894096da55acb4d7be042d06bdd615e 100644
--- a/base/common/src/com/netscape/certsrv/base/PKIException.java
+++ b/base/common/src/com/netscape/certsrv/base/PKIException.java
@@ -31,44 +31,41 @@ public class PKIException extends RuntimeException {
 
     public int code;
 
-    public PKIException(Response.Status status) {
-        super(status.getReasonPhrase());
-        code = status.getStatusCode();
+    public PKIException(int code, String message, Throwable cause) {
+        super(message, cause);
+        this.code = code;
     }
 
     public PKIException(String message) {
-        super(message);
-        code = Response.Status.INTERNAL_SERVER_ERROR.getStatusCode();
+        this(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), message);
     }
 
-    public PKIException(int code, String message) {
-        super(message);
-        this.code = code;
+    public PKIException(Response.Status status) {
+        this(status, status.getReasonPhrase());
     }
 
     public PKIException(Response.Status status, String message) {
-        super(message);
-        code = status.getStatusCode();
+        this(status.getStatusCode(), message);
+    }
+
+    public PKIException(int code, String message) {
+        this(message, null);
+    }
+
+    public PKIException(Throwable cause) {
+        this(cause.getMessage(), cause);
     }
 
     public PKIException(String message, Throwable cause) {
-        super(message, cause);
-        code = Response.Status.INTERNAL_SERVER_ERROR.getStatusCode();
-    }
-
-    public PKIException(int code, String message, Throwable cause) {
-        super(message, cause);
-        this.code = code;
+        this(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), message, cause);
     }
 
     public PKIException(Response.Status status, String message, Throwable cause) {
-        super(message, cause);
-        code = status.getStatusCode();
+        this(status.getStatusCode(), message, cause);
     }
 
     public PKIException(Data data) {
-        super(data.message);
-        code = data.code;
+        this(data.code, data.message);
     }
 
     public int getCode() {
diff --git a/base/common/src/com/netscape/certsrv/logging/ActivityClient.java b/base/common/src/com/netscape/certsrv/logging/ActivityClient.java
index eae2f6f4829c82ca5d1c89cfbf2d389f13e43cae..1fc3bcc2132874a8d8beb423c707b8153072b8ba 100644
--- a/base/common/src/com/netscape/certsrv/logging/ActivityClient.java
+++ b/base/common/src/com/netscape/certsrv/logging/ActivityClient.java
@@ -40,13 +40,13 @@ public class ActivityClient extends Client {
         resource = createProxy(ActivityResource.class);
     }
 
-    public ActivityCollection findActivities(Integer start, Integer size) {
-        Response response = resource.findActivities(start, size);
+    public ActivityCollection findActivities(String filter, Integer start, Integer size) {
+        Response response = resource.findActivities(filter, start, size);
         return client.getEntity(response, ActivityCollection.class);
     }
 
-    public ActivityData getActivity(String tokenID) {
-        Response response = resource.getActivity(tokenID);
+    public ActivityData getActivity(String activityID) {
+        Response response = resource.getActivity(activityID);
         return client.getEntity(response, ActivityData.class);
     }
 }
diff --git a/base/common/src/com/netscape/certsrv/logging/ActivityResource.java b/base/common/src/com/netscape/certsrv/logging/ActivityResource.java
index bc6d375caacae5bffda6b10dca0189188cde551f..3e0a0502e2e14614d44230f8e935441c7410d790 100644
--- a/base/common/src/com/netscape/certsrv/logging/ActivityResource.java
+++ b/base/common/src/com/netscape/certsrv/logging/ActivityResource.java
@@ -35,6 +35,7 @@ public interface ActivityResource {
     @GET
     @ClientResponseType(entityType=ActivityCollection.class)
     public Response findActivities(
+            @QueryParam("filter") String filter,
             @QueryParam("start") Integer start,
             @QueryParam("size") Integer size);
 
diff --git a/base/common/src/com/netscape/certsrv/selftests/SelfTestClient.java b/base/common/src/com/netscape/certsrv/selftests/SelfTestClient.java
index a48698bfa26a5d0e392ece7d8e238791b0d3d29b..108cc1f8f01689d846f0a45dc51b1b2c5f59d56a 100644
--- a/base/common/src/com/netscape/certsrv/selftests/SelfTestClient.java
+++ b/base/common/src/com/netscape/certsrv/selftests/SelfTestClient.java
@@ -40,8 +40,8 @@ public class SelfTestClient extends Client {
         resource = createProxy(SelfTestResource.class);
     }
 
-    public SelfTestCollection findSelfTests(Integer start, Integer size) {
-        Response response = resource.findSelfTests(start, size);
+    public SelfTestCollection findSelfTests(String filter, Integer start, Integer size) {
+        Response response = resource.findSelfTests(filter, start, size);
         return client.getEntity(response, SelfTestCollection.class);
     }
 
diff --git a/base/common/src/com/netscape/certsrv/selftests/SelfTestResource.java b/base/common/src/com/netscape/certsrv/selftests/SelfTestResource.java
index 90dfcb4b163b7798879892203e8a7305e8269200..04f41999d6b830e5ec6782c24ad0464c5cc80146 100644
--- a/base/common/src/com/netscape/certsrv/selftests/SelfTestResource.java
+++ b/base/common/src/com/netscape/certsrv/selftests/SelfTestResource.java
@@ -41,6 +41,7 @@ public interface SelfTestResource {
     @GET
     @ClientResponseType(entityType=SelfTestCollection.class)
     public Response findSelfTests(
+            @QueryParam("filter") String filter,
             @QueryParam("start") Integer start,
             @QueryParam("size") Integer size);
 
diff --git a/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorClient.java b/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorClient.java
index c9c7b83f3573033fb06913b1fa0430ed9a9e434d..293c470b7e76272fcda252857e8738ecd4d53c59 100644
--- a/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorClient.java
+++ b/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorClient.java
@@ -40,8 +40,8 @@ public class AuthenticatorClient extends Client {
         resource = createProxy(AuthenticatorResource.class);
     }
 
-    public AuthenticatorCollection findAuthenticators(Integer start, Integer size) {
-        Response response = resource.findAuthenticators(start, size);
+    public AuthenticatorCollection findAuthenticators(String filter, Integer start, Integer size) {
+        Response response = resource.findAuthenticators(filter, start, size);
         return client.getEntity(response, AuthenticatorCollection.class);
     }
 
diff --git a/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorResource.java b/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorResource.java
index ce570edf134ad29040f51529e25001fb53938a16..457549ecace2bdb9beabbb3b524c9271a80b66b5 100644
--- a/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorResource.java
+++ b/base/common/src/com/netscape/certsrv/tps/authenticator/AuthenticatorResource.java
@@ -43,6 +43,7 @@ public interface AuthenticatorResource {
     @GET
     @ClientResponseType(entityType=AuthenticatorCollection.class)
     public Response findAuthenticators(
+            @QueryParam("filter") String filter,
             @QueryParam("start") Integer start,
             @QueryParam("size") Integer size);
 
diff --git a/base/common/src/com/netscape/certsrv/tps/cert/TPSCertClient.java b/base/common/src/com/netscape/certsrv/tps/cert/TPSCertClient.java
index e1e192557eb092c6a509dead33292f30d46ce5f6..fc11c9a27c79e96f2aac1ad13f9d25a99a559092 100644
--- a/base/common/src/com/netscape/certsrv/tps/cert/TPSCertClient.java
+++ b/base/common/src/com/netscape/certsrv/tps/cert/TPSCertClient.java
@@ -40,8 +40,8 @@ public class TPSCertClient extends Client {
         resource = createProxy(TPSCertResource.class);
     }
 
-    public TPSCertCollection findCerts(Integer start, Integer size) {
-        Response response = resource.findCerts(start, size);
+    public TPSCertCollection findCerts(String filter, Integer start, Integer size) {
+        Response response = resource.findCerts(filter, start, size);
         return client.getEntity(response, TPSCertCollection.class);
     }
 
diff --git a/base/common/src/com/netscape/certsrv/tps/cert/TPSCertResource.java b/base/common/src/com/netscape/certsrv/tps/cert/TPSCertResource.java
index cf95dad893214812846a3d95ce56a3a4a65add21..7b87570066798b69b91317e32e3e0ee6be4eb6f6 100644
--- a/base/common/src/com/netscape/certsrv/tps/cert/TPSCertResource.java
+++ b/base/common/src/com/netscape/certsrv/tps/cert/TPSCertResource.java
@@ -35,6 +35,7 @@ public interface TPSCertResource {
     @GET
     @ClientResponseType(entityType=TPSCertCollection.class)
     public Response findCerts(
+            @QueryParam("filter") String filter,
             @QueryParam("start") Integer start,
             @QueryParam("size") Integer size);
 
diff --git a/base/common/src/com/netscape/certsrv/tps/connection/ConnectionClient.java b/base/common/src/com/netscape/certsrv/tps/connection/ConnectionClient.java
index 4ef59366c6114f03a4124971d7f38cc661a2c613..aaf9e639992b966b28eb310ae75f160d31726dfc 100644
--- a/base/common/src/com/netscape/certsrv/tps/connection/ConnectionClient.java
+++ b/base/common/src/com/netscape/certsrv/tps/connection/ConnectionClient.java
@@ -40,8 +40,8 @@ public class ConnectionClient extends Client {
         resource = createProxy(ConnectionResource.class);
     }
 
-    public ConnectionCollection findConnections(Integer start, Integer size) {
-        Response response = resource.findConnections(start, size);
+    public ConnectionCollection findConnections(String filter, Integer start, Integer size) {
+        Response response = resource.findConnections(filter, start, size);
         return client.getEntity(response, ConnectionCollection.class);
     }
 
diff --git a/base/common/src/com/netscape/certsrv/tps/connection/ConnectionResource.java b/base/common/src/com/netscape/certsrv/tps/connection/ConnectionResource.java
index 136cc8784059b566f8bcc2e0c0d14e6dad83c6b2..e161350633f997d478f360055f49c2a1fd637073 100644
--- a/base/common/src/com/netscape/certsrv/tps/connection/ConnectionResource.java
+++ b/base/common/src/com/netscape/certsrv/tps/connection/ConnectionResource.java
@@ -43,6 +43,7 @@ public interface ConnectionResource {
     @GET
     @ClientResponseType(entityType=ConnectionCollection.class)
     public Response findConnections(
+            @QueryParam("filter") String filter,
             @QueryParam("start") Integer start,
             @QueryParam("size") Integer size);
 
diff --git a/base/common/src/com/netscape/certsrv/tps/profile/ProfileClient.java b/base/common/src/com/netscape/certsrv/tps/profile/ProfileClient.java
index 9ca571d19d091ad907b735c00099bec348be20b8..3a659291e8d380124e413123e134d5d6117c495f 100644
--- a/base/common/src/com/netscape/certsrv/tps/profile/ProfileClient.java
+++ b/base/common/src/com/netscape/certsrv/tps/profile/ProfileClient.java
@@ -44,8 +44,8 @@ public class ProfileClient extends Client {
         resource = createProxy(ProfileResource.class);
     }
 
-    public ProfileCollection findProfiles(Integer start, Integer size) {
-        Response response = resource.findProfiles(start, size);
+    public ProfileCollection findProfiles(String filter, Integer start, Integer size) {
+        Response response = resource.findProfiles(filter, start, size);
         return client.getEntity(response, ProfileCollection.class);
     }
 
diff --git a/base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingClient.java b/base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingClient.java
index 409d8d7182c16c720222fd2b6e1fbc697de7c582..dafc25f4113b5a6b8e7d1f9f5a66c821b79a893d 100644
--- a/base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingClient.java
+++ b/base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingClient.java
@@ -40,8 +40,8 @@ public class ProfileMappingClient extends Client {
         resource = createProxy(ProfileMappingResource.class);
     }
 
-    public ProfileMappingCollection findProfileMappings(Integer start, Integer size) {
-        Response response = resource.findProfileMappings(start, size);
+    public ProfileMappingCollection findProfileMappings(String filter, Integer start, Integer size) {
+        Response response = resource.findProfileMappings(filter, start, size);
         return client.getEntity(response, ProfileMappingCollection.class);
     }
 
diff --git a/base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingResource.java b/base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingResource.java
index 694a1810e4642c7b699a5e538cecfc32901bceb3..5828a3317046475b9c605614d815138ca262aa3c 100644
--- a/base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingResource.java
+++ b/base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingResource.java
@@ -43,6 +43,7 @@ public interface ProfileMappingResource {
     @GET
     @ClientResponseType(entityType=ProfileMappingCollection.class)
     public Response findProfileMappings(
+            @QueryParam("filter") String filter,
             @QueryParam("start") Integer start,
             @QueryParam("size") Integer size);
 
diff --git a/base/common/src/com/netscape/certsrv/tps/profile/ProfileResource.java b/base/common/src/com/netscape/certsrv/tps/profile/ProfileResource.java
index 4cb466f2f20d8f402f53704ed8853cfe91329d16..50a205cd7eb9331627856d52241c2902713ce4b7 100644
--- a/base/common/src/com/netscape/certsrv/tps/profile/ProfileResource.java
+++ b/base/common/src/com/netscape/certsrv/tps/profile/ProfileResource.java
@@ -43,6 +43,7 @@ public interface ProfileResource {
     @GET
     @ClientResponseType(entityType=ProfileCollection.class)
     public Response findProfiles(
+            @QueryParam("filter") String filter,
             @QueryParam("start") Integer start,
             @QueryParam("size") Integer size);
 
diff --git a/base/common/src/com/netscape/certsrv/tps/token/TokenClient.java b/base/common/src/com/netscape/certsrv/tps/token/TokenClient.java
index 98690cb99a8c5fcf4fc7f07f2e16dcd146ddd9a1..ba2ae3c0f605d1355b93c8891241fa5753a2454f 100644
--- a/base/common/src/com/netscape/certsrv/tps/token/TokenClient.java
+++ b/base/common/src/com/netscape/certsrv/tps/token/TokenClient.java
@@ -40,8 +40,8 @@ public class TokenClient extends Client {
         resource = createProxy(TokenResource.class);
     }
 
-    public TokenCollection findTokens(Integer start, Integer size) {
-        Response response = resource.findTokens(start, size);
+    public TokenCollection findTokens(String filter, Integer start, Integer size) {
+        Response response = resource.findTokens(filter, start, size);
         return client.getEntity(response, TokenCollection.class);
     }
 
diff --git a/base/common/src/com/netscape/certsrv/tps/token/TokenResource.java b/base/common/src/com/netscape/certsrv/tps/token/TokenResource.java
index f88ce399c9c4626b8677d20014ed8d94021a42ae..3f5f305ef9ee22284e4edbbc265a5e9f185bf404 100644
--- a/base/common/src/com/netscape/certsrv/tps/token/TokenResource.java
+++ b/base/common/src/com/netscape/certsrv/tps/token/TokenResource.java
@@ -44,6 +44,7 @@ public interface TokenResource {
     @GET
     @ClientResponseType(entityType=TokenCollection.class)
     public Response findTokens(
+            @QueryParam("filter") String filter,
             @QueryParam("start") Integer start,
             @QueryParam("size") Integer size);
 
diff --git a/base/java-tools/src/com/netscape/cmstools/logging/ActivityFindCLI.java b/base/java-tools/src/com/netscape/cmstools/logging/ActivityFindCLI.java
index 88b8177985111c0b4b4c22a410a4abaef047493e..d9daf921ca5da841e57542adc30b6bc235098bcc 100644
--- a/base/java-tools/src/com/netscape/cmstools/logging/ActivityFindCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/logging/ActivityFindCLI.java
@@ -41,7 +41,7 @@ public class ActivityFindCLI extends CLI {
     }
 
     public void printHelp() {
-        formatter.printHelp(getFullName() + " [OPTIONS...]", options);
+        formatter.printHelp(getFullName() + " [FILTER] [OPTIONS...]", options);
     }
 
     public void execute(String[] args) throws Exception {
@@ -65,13 +65,16 @@ public class ActivityFindCLI extends CLI {
             System.exit(1);
         }
 
+        String[] cmdArgs = cmd.getArgs();
+        String filter = cmdArgs.length > 0 ? cmdArgs[0] : null;
+
         String s = cmd.getOptionValue("start");
         Integer start = s == null ? null : Integer.valueOf(s);
 
         s = cmd.getOptionValue("size");
         Integer size = s == null ? null : Integer.valueOf(s);
 
-        ActivityCollection result = activityCLI.activityClient.findActivities(start, size);
+        ActivityCollection result = activityCLI.activityClient.findActivities(filter, start, size);
 
         MainCLI.printMessage(result.getTotal() + " entries matched");
         if (result.getTotal() == 0) return;
diff --git a/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestFindCLI.java b/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestFindCLI.java
index 241f6c300163bcdff469880aad805bf40c9123f1..82909f67ff0400939b9ebc4cbb5d9c7eed662e4d 100644
--- a/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestFindCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestFindCLI.java
@@ -41,7 +41,7 @@ public class SelfTestFindCLI extends CLI {
     }
 
     public void printHelp() {
-        formatter.printHelp(getFullName() + " [OPTIONS...]", options);
+        formatter.printHelp(getFullName() + " [FILTER] [OPTIONS...]", options);
     }
 
     public void execute(String[] args) throws Exception {
@@ -65,13 +65,16 @@ public class SelfTestFindCLI extends CLI {
             System.exit(1);
         }
 
+        String[] cmdArgs = cmd.getArgs();
+        String filter = cmdArgs.length > 0 ? cmdArgs[0] : null;
+
         String s = cmd.getOptionValue("start");
         Integer start = s == null ? null : Integer.valueOf(s);
 
         s = cmd.getOptionValue("size");
         Integer size = s == null ? null : Integer.valueOf(s);
 
-        SelfTestCollection result = selfTestCLI.selfTestClient.findSelfTests(start, size);
+        SelfTestCollection result = selfTestCLI.selfTestClient.findSelfTests(filter, start, size);
 
         MainCLI.printMessage(result.getTotal() + " entries matched");
         if (result.getTotal() == 0) return;
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorFindCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorFindCLI.java
index 683d2891cd8ac69b5519c3970ba788393f0405b3..552fc30403ea29759b4add617494a6d4d734be5c 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorFindCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorFindCLI.java
@@ -41,7 +41,7 @@ public class AuthenticatorFindCLI extends CLI {
     }
 
     public void printHelp() {
-        formatter.printHelp(getFullName() + " [OPTIONS...]", options);
+        formatter.printHelp(getFullName() + " [FILTER] [OPTIONS...]", options);
     }
 
     public void execute(String[] args) throws Exception {
@@ -65,13 +65,16 @@ public class AuthenticatorFindCLI extends CLI {
             System.exit(1);
         }
 
+        String[] cmdArgs = cmd.getArgs();
+        String filter = cmdArgs.length > 0 ? cmdArgs[0] : null;
+
         String s = cmd.getOptionValue("start");
         Integer start = s == null ? null : Integer.valueOf(s);
 
         s = cmd.getOptionValue("size");
         Integer size = s == null ? null : Integer.valueOf(s);
 
-        AuthenticatorCollection result = authenticatorCLI.authenticatorClient.findAuthenticators(start, size);
+        AuthenticatorCollection result = authenticatorCLI.authenticatorClient.findAuthenticators(filter, start, size);
 
         MainCLI.printMessage(result.getTotal() + " entries matched");
         if (result.getTotal() == 0) return;
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/cert/TPSCertFindCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/cert/TPSCertFindCLI.java
index 12ec1b9da45517674c1e71ff283d863a985b82e5..91c460bf6aa94ce01aa3d5ac2f98a025793f5e75 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/cert/TPSCertFindCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/cert/TPSCertFindCLI.java
@@ -41,7 +41,7 @@ public class TPSCertFindCLI extends CLI {
     }
 
     public void printHelp() {
-        formatter.printHelp(getFullName() + " [OPTIONS...]", options);
+        formatter.printHelp(getFullName() + " [FILTER] [OPTIONS...]", options);
     }
 
     public void execute(String[] args) throws Exception {
@@ -65,13 +65,16 @@ public class TPSCertFindCLI extends CLI {
             System.exit(1);
         }
 
+        String[] cmdArgs = cmd.getArgs();
+        String filter = cmdArgs.length > 0 ? cmdArgs[0] : null;
+
         String s = cmd.getOptionValue("start");
         Integer start = s == null ? null : Integer.valueOf(s);
 
         s = cmd.getOptionValue("size");
         Integer size = s == null ? null : Integer.valueOf(s);
 
-        TPSCertCollection result = certCLI.certClient.findCerts(start, size);
+        TPSCertCollection result = certCLI.certClient.findCerts(filter, start, size);
 
         MainCLI.printMessage(result.getTotal() + " entries matched");
         if (result.getTotal() == 0) return;
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/connection/ConnectionFindCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/connection/ConnectionFindCLI.java
index d78727d7b9cbfadf768d3980955cafae430d9294..9d2165ef032634f5b2f5f9728b5c98abdd4ae89c 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/connection/ConnectionFindCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/connection/ConnectionFindCLI.java
@@ -41,7 +41,7 @@ public class ConnectionFindCLI extends CLI {
     }
 
     public void printHelp() {
-        formatter.printHelp(getFullName() + " [OPTIONS...]", options);
+        formatter.printHelp(getFullName() + " [FILTER] [OPTIONS...]", options);
     }
 
     public void execute(String[] args) throws Exception {
@@ -65,13 +65,16 @@ public class ConnectionFindCLI extends CLI {
             System.exit(1);
         }
 
+        String[] cmdArgs = cmd.getArgs();
+        String filter = cmdArgs.length > 0 ? cmdArgs[0] : null;
+
         String s = cmd.getOptionValue("start");
         Integer start = s == null ? null : Integer.valueOf(s);
 
         s = cmd.getOptionValue("size");
         Integer size = s == null ? null : Integer.valueOf(s);
 
-        ConnectionCollection result = connectionCLI.connectionClient.findConnections(start, size);
+        ConnectionCollection result = connectionCLI.connectionClient.findConnections(filter, start, size);
 
         MainCLI.printMessage(result.getTotal() + " entries matched");
         if (result.getTotal() == 0) return;
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileFindCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileFindCLI.java
index cabacaacdc8410f57bd6f4d9fa65917cba3c055d..251d14d23253e459198f2a06c911c3fad30ba8da 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileFindCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileFindCLI.java
@@ -41,7 +41,7 @@ public class ProfileFindCLI extends CLI {
     }
 
     public void printHelp() {
-        formatter.printHelp(getFullName() + " [OPTIONS...]", options);
+        formatter.printHelp(getFullName() + " [FILTER] [OPTIONS...]", options);
     }
 
     public void execute(String[] args) throws Exception {
@@ -65,13 +65,16 @@ public class ProfileFindCLI extends CLI {
             System.exit(1);
         }
 
+        String[] cmdArgs = cmd.getArgs();
+        String filter = cmdArgs.length > 0 ? cmdArgs[0] : null;
+
         String s = cmd.getOptionValue("start");
         Integer start = s == null ? null : Integer.valueOf(s);
 
         s = cmd.getOptionValue("size");
         Integer size = s == null ? null : Integer.valueOf(s);
 
-        ProfileCollection result = profileCLI.profileClient.findProfiles(start, size);
+        ProfileCollection result = profileCLI.profileClient.findProfiles(filter, start, size);
 
         MainCLI.printMessage(result.getTotal() + " entries matched");
         if (result.getTotal() == 0) return;
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingFindCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingFindCLI.java
index 9d87cc43cda050a2d56da387e74803e0e9ea263e..e125629e67869bf173af5afaf73a7804cbbcac07 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingFindCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/profile/ProfileMappingFindCLI.java
@@ -41,7 +41,7 @@ public class ProfileMappingFindCLI extends CLI {
     }
 
     public void printHelp() {
-        formatter.printHelp(getFullName() + " [OPTIONS...]", options);
+        formatter.printHelp(getFullName() + " [FILTER] [OPTIONS...]", options);
     }
 
     public void execute(String[] args) throws Exception {
@@ -65,13 +65,16 @@ public class ProfileMappingFindCLI extends CLI {
             System.exit(1);
         }
 
+        String[] cmdArgs = cmd.getArgs();
+        String filter = cmdArgs.length > 0 ? cmdArgs[0] : null;
+
         String s = cmd.getOptionValue("start");
         Integer start = s == null ? null : Integer.valueOf(s);
 
         s = cmd.getOptionValue("size");
         Integer size = s == null ? null : Integer.valueOf(s);
 
-        ProfileMappingCollection result = profileMappingCLI.profileMappingClient.findProfileMappings(start, size);
+        ProfileMappingCollection result = profileMappingCLI.profileMappingClient.findProfileMappings(filter, start, size);
 
         MainCLI.printMessage(result.getTotal() + " entries matched");
         if (result.getTotal() == 0) return;
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenFindCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenFindCLI.java
index 6cfb1fb00ea7287751fc08115679ea1f16c27769..22fbad94478f657be66eb94950d273b2e3b760b0 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenFindCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenFindCLI.java
@@ -41,7 +41,7 @@ public class TokenFindCLI extends CLI {
     }
 
     public void printHelp() {
-        formatter.printHelp(getFullName() + " [OPTIONS...]", options);
+        formatter.printHelp(getFullName() + " [FILTER] [OPTIONS...]", options);
     }
 
     public void execute(String[] args) throws Exception {
@@ -65,13 +65,16 @@ public class TokenFindCLI extends CLI {
             System.exit(1);
         }
 
+        String[] cmdArgs = cmd.getArgs();
+        String filter = cmdArgs.length > 0 ? cmdArgs[0] : null;
+
         String s = cmd.getOptionValue("start");
         Integer start = s == null ? null : Integer.valueOf(s);
 
         s = cmd.getOptionValue("size");
         Integer size = s == null ? null : Integer.valueOf(s);
 
-        TokenCollection result = tokenCLI.tokenClient.findTokens(start, size);
+        TokenCollection result = tokenCLI.tokenClient.findTokens(filter, start, size);
 
         MainCLI.printMessage(result.getTotal() + " entries matched");
         if (result.getTotal() == 0) return;
diff --git a/base/server/cms/src/org/dogtagpki/server/rest/GroupService.java b/base/server/cms/src/org/dogtagpki/server/rest/GroupService.java
index 2c3c0011aca6b8e6b69c859ccd35dfc4a215a807..0f3d9b0db25dcdd313468f5dc90b8eac5fd5f78b 100644
--- a/base/server/cms/src/org/dogtagpki/server/rest/GroupService.java
+++ b/base/server/cms/src/org/dogtagpki/server/rest/GroupService.java
@@ -139,7 +139,8 @@ public class GroupService extends PKIService implements GroupResource {
             return createOKResponse(response);
 
         } catch (Exception e) {
-            throw new PKIException(getUserMessage("CMS_INTERNAL_ERROR", headers));
+            CMS.debug(e);
+            throw new PKIException(e);
         }
     }
 
diff --git a/base/server/cms/src/org/dogtagpki/server/rest/SelfTestService.java b/base/server/cms/src/org/dogtagpki/server/rest/SelfTestService.java
index 652875fe80f9949137a6e1a47cbd6d52ea113d4a..62993f68e7bcd40744bf526ce335454e4b7de085 100644
--- a/base/server/cms/src/org/dogtagpki/server/rest/SelfTestService.java
+++ b/base/server/cms/src/org/dogtagpki/server/rest/SelfTestService.java
@@ -21,7 +21,8 @@ package org.dogtagpki.server.rest;
 import java.io.UnsupportedEncodingException;
 import java.net.URI;
 import java.net.URLEncoder;
-import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Iterator;
 
 import javax.servlet.http.HttpServletRequest;
@@ -94,7 +95,7 @@ public class SelfTestService extends PKIService implements SelfTestResource {
     }
 
     @Override
-    public Response findSelfTests(Integer start, Integer size) {
+    public Response findSelfTests(String filter, Integer start, Integer size) {
 
         CMS.debug("SelfTestService.findSelfTests()");
 
@@ -103,9 +104,16 @@ public class SelfTestService extends PKIService implements SelfTestResource {
             size = size == null ? DEFAULT_SIZE : size;
 
             ISelfTestSubsystem subsystem = (ISelfTestSubsystem)CMS.getSubsystem(ISelfTestSubsystem.ID);
-            Iterator<String> entries = Arrays.asList(subsystem.listSelfTestsEnabledOnDemand()).iterator();
+
+            // filter self tests
+            Collection<String> results = new ArrayList<String>();
+            for (String name : subsystem.listSelfTestsEnabledOnDemand()) {
+                if (filter != null && !name.contains(filter)) continue;
+                results.add(name);
+            }
 
             SelfTestCollection response = new SelfTestCollection();
+            Iterator<String> entries = results.iterator();
             int i = 0;
 
             // skip to the start of the page
diff --git a/base/server/cms/src/org/dogtagpki/server/rest/UserService.java b/base/server/cms/src/org/dogtagpki/server/rest/UserService.java
index ac1f0617fc24f2d995865d034aad269d2fbb3bd4..839b29291373c0ff34b8d8263ced7d77e322d0b6 100644
--- a/base/server/cms/src/org/dogtagpki/server/rest/UserService.java
+++ b/base/server/cms/src/org/dogtagpki/server/rest/UserService.java
@@ -133,6 +133,7 @@ public class UserService extends PKIService implements UserResource {
      */
     @Override
     public Response findUsers(String filter, Integer start, Integer size) {
+        UserCollection response = new UserCollection();
         try {
             filter = StringUtils.isEmpty(filter) ? "*" : "*"+LDAPUtil.escapeFilter(filter)+"*";
             start = start == null ? 0 : start;
@@ -140,7 +141,6 @@ public class UserService extends PKIService implements UserResource {
 
             Enumeration<IUser> users = userGroupManager.findUsers(filter);
 
-            UserCollection response = new UserCollection();
             int i = 0;
 
             // skip to the start of the page
@@ -168,8 +168,20 @@ public class UserService extends PKIService implements UserResource {
 
             return createOKResponse(response);
 
+        } catch (EUsrGrpException e) {
+            // Workaround for ticket #914.
+            // If no users found, return empty result.
+            if (CMS.getUserMessage("CMS_USRGRP_USER_NOT_FOUND").equals(e.getMessage())) {
+                CMS.debug("UserService.findUsers(): " + e.getMessage());
+                return createOKResponse(response);
+            }
+
+            CMS.debug(e);
+            throw new PKIException(e);
+
         } catch (Exception e) {
-            throw new PKIException(getUserMessage("CMS_INTERNAL_ERROR", headers));
+            CMS.debug(e);
+            throw new PKIException(e);
         }
     }
 
diff --git a/base/server/cmscore/src/com/netscape/cmscore/dbs/Database.java b/base/server/cmscore/src/com/netscape/cmscore/dbs/Database.java
index 3df2d59193975b171f36d9e3d26d1f69cb247f52..f8c55204b9208845646c034e6ac6548d34c99381 100644
--- a/base/server/cmscore/src/com/netscape/cmscore/dbs/Database.java
+++ b/base/server/cmscore/src/com/netscape/cmscore/dbs/Database.java
@@ -18,6 +18,7 @@
 
 package com.netscape.cmscore.dbs;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.LinkedHashMap;
 import java.util.Map;
@@ -43,8 +44,18 @@ public class Database<E> {
         CMS.debug("Initializing " + name + " database");
     }
 
-    public Collection<E> getRecords() throws Exception {
-        return records.values();
+    /**
+     * Find records matching filter
+     */
+    public Collection<E> findRecords(String filter) throws Exception {
+
+        Collection<E> results = new ArrayList<E>();
+        for (String id : records.keySet()) {
+            if (filter != null && !id.contains(filter)) continue;
+            results.add(records.get(id));
+        }
+
+        return results;
     }
 
     public E getRecord(String id) throws Exception {
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 f6ded787bfc1c27551f1a3157f0849f0c0956e22..4c3ac8dfb4f15bb57fbf63856886f46936f1ed83 100644
--- a/base/server/cmscore/src/com/netscape/cmscore/dbs/LDAPDatabase.java
+++ b/base/server/cmscore/src/com/netscape/cmscore/dbs/LDAPDatabase.java
@@ -98,14 +98,14 @@ public abstract class LDAPDatabase<E extends IDBObj> extends Database<E> {
     public abstract String createFilter(String filter);
 
     @Override
-    public Collection<E> getRecords() throws Exception {
-        CMS.debug("LDAPDatabase: getRecords()");
+    public Collection<E> findRecords(String filter) throws Exception {
+        CMS.debug("LDAPDatabase: findRecords()");
 
         try (IDBSSession session = dbSubsystem.createSession()) {
             Collection<E> list = new ArrayList<E>();
-
-            CMS.debug("LDAPDatabase: searching " + baseDN);
-            IDBSearchResults results = session.search(baseDN, createFilter(null));
+            filter = createFilter(filter);
+            CMS.debug("LDAPDatabase: searching " + baseDN + " with filter " + filter);
+            IDBSearchResults results = session.search(baseDN, filter);
 
             while (results.hasMoreElements()) {
                 @SuppressWarnings("unchecked")
@@ -167,5 +167,4 @@ public abstract class LDAPDatabase<E extends IDBObj> extends Database<E> {
             session.delete(dn);
         }
     }
-
 }
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/config/ConfigDatabase.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/config/ConfigDatabase.java
index f1b0d7178a31711015e0fb7ea677fe036df4c219..cded13af57959829ba8c4382802a207e63e01954 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/config/ConfigDatabase.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/config/ConfigDatabase.java
@@ -55,9 +55,9 @@ public class ConfigDatabase extends Database<ConfigRecord> {
     }
 
     @Override
-    public Collection<ConfigRecord> getRecords() throws Exception {
+    public Collection<ConfigRecord> findRecords(String filter) throws Exception {
 
-        CMS.debug("ConfigDatabase.getRecords()");
+        CMS.debug("ConfigDatabase.findRecords()");
 
         Collection<ConfigRecord> result = new ArrayList<ConfigRecord>();
 
@@ -75,6 +75,7 @@ public class ConfigDatabase extends Database<ConfigRecord> {
         }
 
         for (String configID : configIDs) {
+            if (filter != null && !configID.contains(filter)) continue;
             ConfigRecord configData = getRecord(configID);
             result.add(configData);
         }
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/config/ConnectionDatabase.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/config/ConnectionDatabase.java
index 35eb382ea90f918b740b02de10f0360578d113d1..9755db85b773ccd86fa256fb36a1dff4cc4aab2a 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/config/ConnectionDatabase.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/config/ConnectionDatabase.java
@@ -53,13 +53,14 @@ public class ConnectionDatabase extends CSCfgDatabase<ConnectionRecord> {
     }
 
     @Override
-    public Collection<ConnectionRecord> getRecords() throws Exception {
+    public Collection<ConnectionRecord> findRecords(String filter) throws Exception {
 
         Collection<ConnectionRecord> result = new ArrayList<ConnectionRecord>();
         ConfigDatabase configDatabase = new ConfigDatabase();
         ConfigRecord configRecord = configDatabase.getRecord("Subsystem_Connections");
 
         for (String connectionID : configRecord.getKeys()) {
+            if (filter != null && !connectionID.contains(filter)) continue;
             ConnectionRecord connectionRecord = createConnectionRecord(configDatabase, configRecord, connectionID);
             result.add(connectionRecord);
         }
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/config/ProfileDatabase.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/config/ProfileDatabase.java
index 6054bf38da2661881c82abe593b3af611fdf6ad2..195580ff9376d99df89f3bdb92863459e60bc4d8 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/config/ProfileDatabase.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/config/ProfileDatabase.java
@@ -51,13 +51,14 @@ public class ProfileDatabase extends CSCfgDatabase<ProfileRecord> {
     }
 
     @Override
-    public Collection<ProfileRecord> getRecords() throws Exception {
+    public Collection<ProfileRecord> findRecords(String filter) throws Exception {
 
         Collection<ProfileRecord> result = new ArrayList<ProfileRecord>();
         ConfigDatabase configDatabase = new ConfigDatabase();
         ConfigRecord configRecord = configDatabase.getRecord(substoreName);
 
         for (String profileID : configRecord.getKeys()) {
+            if (filter != null && !profileID.contains(filter)) continue;
             ProfileRecord profileRecord = createProfileRecord(configDatabase, configRecord, profileID);
             result.add(profileRecord);
         }
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/config/ProfileMappingDatabase.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/config/ProfileMappingDatabase.java
index dca0beb02f8ad4ecfaad02596bdab6560ef7dde0..8310abe825535a59a2fdd547956b05b9053f587c 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/config/ProfileMappingDatabase.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/config/ProfileMappingDatabase.java
@@ -50,13 +50,14 @@ public class ProfileMappingDatabase extends CSCfgDatabase<ProfileMappingRecord>
     }
 
     @Override
-    public Collection<ProfileMappingRecord> getRecords() throws Exception {
+    public Collection<ProfileMappingRecord> findRecords(String filter) throws Exception {
 
         Collection<ProfileMappingRecord> result = new ArrayList<ProfileMappingRecord>();
         ConfigDatabase configDatabase = new ConfigDatabase();
         ConfigRecord configRecord = configDatabase.getRecord(substoreName);
 
         for (String profileMappingID : configRecord.getKeys()) {
+            if (filter != null && !profileMappingID.contains(filter)) continue;
             ProfileMappingRecord profileMappingRecord = createProfileMappingRecord(configDatabase, configRecord, profileMappingID);
             result.add(profileMappingRecord);
         }
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/dbs/ActivityDatabase.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/dbs/ActivityDatabase.java
index d48d31489b2554b4c8c71e8f84520766b9aa2d9e..0222f3f00843719771c4aad1b2cc065e873d7d65 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/dbs/ActivityDatabase.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/dbs/ActivityDatabase.java
@@ -20,9 +20,12 @@ package org.dogtagpki.server.tps.dbs;
 
 import java.util.Date;
 
+import org.apache.commons.lang.StringUtils;
+
 import com.netscape.certsrv.base.EBaseException;
 import com.netscape.certsrv.dbs.IDBSubsystem;
 import com.netscape.cmscore.dbs.LDAPDatabase;
+import com.netscape.cmsutil.ldap.LDAPUtil;
 
 /**
  * This class implements in-memory activity database. In the future this
@@ -50,6 +53,6 @@ public class ActivityDatabase extends LDAPDatabase<ActivityRecord> {
 
     @Override
     public String createFilter(String filter) {
-        return "(id=*)";
+        return StringUtils.isEmpty(filter) ? "(id=*)" : "(id=*"+LDAPUtil.escapeFilter(filter)+"*)";
     }
 }
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/dbs/AuthenticatorDatabase.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/dbs/AuthenticatorDatabase.java
index f6425bc8defec3ac6b6d18c529a89f6cec37071e..912207501fa0132b61f03d00f7b02089ab580fb6 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/dbs/AuthenticatorDatabase.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/dbs/AuthenticatorDatabase.java
@@ -53,13 +53,14 @@ public class AuthenticatorDatabase extends CSCfgDatabase<AuthenticatorRecord> {
     }
 
     @Override
-    public Collection<AuthenticatorRecord> getRecords() throws Exception {
+    public Collection<AuthenticatorRecord> findRecords(String filter) throws Exception {
 
         Collection<AuthenticatorRecord> result = new ArrayList<AuthenticatorRecord>();
         ConfigDatabase configDatabase = new ConfigDatabase();
         ConfigRecord configRecord = configDatabase.getRecord(substoreName);
 
         for (String authenticatorID : configRecord.getKeys()) {
+            if (filter != null && !authenticatorID.contains(filter)) continue;
             AuthenticatorRecord authenticatorRecord = createAuthenticatorRecord(configDatabase, configRecord, authenticatorID);
             result.add(authenticatorRecord);
         }
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/dbs/TPSCertDatabase.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/dbs/TPSCertDatabase.java
index 9922c4d50d094a7005f0957ded866fc5b163b31d..e12a41b69bbe24a521a279922a47ef5e08896309 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/dbs/TPSCertDatabase.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/dbs/TPSCertDatabase.java
@@ -20,9 +20,12 @@ package org.dogtagpki.server.tps.dbs;
 
 import java.util.Date;
 
+import org.apache.commons.lang.StringUtils;
+
 import com.netscape.certsrv.base.EBaseException;
 import com.netscape.certsrv.dbs.IDBSubsystem;
 import com.netscape.cmscore.dbs.LDAPDatabase;
+import com.netscape.cmsutil.ldap.LDAPUtil;
 
 /**
  * This class implements in-memory activity database. In the future this
@@ -57,6 +60,6 @@ public class TPSCertDatabase extends LDAPDatabase<TPSCertRecord> {
 
     @Override
     public String createFilter(String filter) {
-        return "(id=*)";
+        return StringUtils.isEmpty(filter) ? "(id=*)" : "(id=*"+LDAPUtil.escapeFilter(filter)+"*)";
     }
 }
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/dbs/TokenDatabase.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/dbs/TokenDatabase.java
index 517d3151e8a5983ed060645372024c318afcc418..6f5a790942b9c471cecfbd8793b0b4effa84f795 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/dbs/TokenDatabase.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/dbs/TokenDatabase.java
@@ -20,9 +20,12 @@ package org.dogtagpki.server.tps.dbs;
 
 import java.util.Date;
 
+import org.apache.commons.lang.StringUtils;
+
 import com.netscape.certsrv.base.EBaseException;
 import com.netscape.certsrv.dbs.IDBSubsystem;
 import com.netscape.cmscore.dbs.LDAPDatabase;
+import com.netscape.cmsutil.ldap.LDAPUtil;
 
 /**
  * @author Endi S. Dewata
@@ -55,6 +58,6 @@ public class TokenDatabase extends LDAPDatabase<TokenRecord> {
 
     @Override
     public String createFilter(String filter) {
-        return "(id=*)";
+        return StringUtils.isEmpty(filter) ? "(id=*)" : "(id=*"+LDAPUtil.escapeFilter(filter)+"*)";
     }
 }
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/ActivityService.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/ActivityService.java
index 1c331f150619559ec7c4555f84c5a838c0799b92..1fb1e4c8260df592b0cccc561708d185def71cad 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/ActivityService.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/ActivityService.java
@@ -100,7 +100,7 @@ public class ActivityService extends PKIService implements ActivityResource {
     }
 
     @Override
-    public Response findActivities(Integer start, Integer size) {
+    public Response findActivities(String filter, Integer start, Integer size) {
 
         CMS.debug("ActivityService.findActivities()");
 
@@ -111,7 +111,7 @@ public class ActivityService extends PKIService implements ActivityResource {
             TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             ActivityDatabase database = subsystem.getActivityDatabase();
 
-            Iterator<ActivityRecord> activities = database.getRecords().iterator();
+            Iterator<ActivityRecord> activities = database.findRecords(filter).iterator();
 
             ActivityCollection response = new ActivityCollection();
             int i = 0;
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/AuthenticatorService.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/AuthenticatorService.java
index 21d15cc1084c31df1b314b0835193fbc0e65bb2f..2daffd55107044ca17d54ca0daf33e7fe927e29a 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/AuthenticatorService.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/AuthenticatorService.java
@@ -95,7 +95,7 @@ public class AuthenticatorService extends PKIService implements AuthenticatorRes
     }
 
     @Override
-    public Response findAuthenticators(Integer start, Integer size) {
+    public Response findAuthenticators(String filter, Integer start, Integer size) {
 
         CMS.debug("AuthenticatorService.findAuthenticators()");
 
@@ -106,7 +106,7 @@ public class AuthenticatorService extends PKIService implements AuthenticatorRes
             TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             AuthenticatorDatabase database = subsystem.getAuthenticatorDatabase();
 
-            Iterator<AuthenticatorRecord> authenticators = database.getRecords().iterator();
+            Iterator<AuthenticatorRecord> authenticators = database.findRecords(filter).iterator();
 
             AuthenticatorCollection response = new AuthenticatorCollection();
             int i = 0;
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/ConnectionService.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/ConnectionService.java
index 2cd6f2bfd84359dbc16158590924d1219f9a81db..8e0b69dcf85f332850b269ba561bc89688078d0a 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/ConnectionService.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/ConnectionService.java
@@ -95,7 +95,7 @@ public class ConnectionService extends PKIService implements ConnectionResource
     }
 
     @Override
-    public Response findConnections(Integer start, Integer size) {
+    public Response findConnections(String filter, Integer start, Integer size) {
 
         CMS.debug("ConnectionService.findConnections()");
 
@@ -106,7 +106,7 @@ public class ConnectionService extends PKIService implements ConnectionResource
             TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             ConnectionDatabase database = subsystem.getConnectionDatabase();
 
-            Iterator<ConnectionRecord> connections = database.getRecords().iterator();
+            Iterator<ConnectionRecord> connections = database.findRecords(filter).iterator();
 
             ConnectionCollection response = new ConnectionCollection();
             int i = 0;
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/ProfileMappingService.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/ProfileMappingService.java
index 8336bff7f7c0ed07fdf60aaeb71b6c58b246f3fb..75087cd6119e51658ad881940e235612ecbfbb38 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/ProfileMappingService.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/ProfileMappingService.java
@@ -95,7 +95,7 @@ public class ProfileMappingService extends PKIService implements ProfileMappingR
     }
 
     @Override
-    public Response findProfileMappings(Integer start, Integer size) {
+    public Response findProfileMappings(String filter, Integer start, Integer size) {
 
         CMS.debug("ProfileMappingService.findProfileMappings()");
 
@@ -106,7 +106,7 @@ public class ProfileMappingService extends PKIService implements ProfileMappingR
             TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             ProfileMappingDatabase database = subsystem.getProfileMappingDatabase();
 
-            Iterator<ProfileMappingRecord> profileMappings = database.getRecords().iterator();
+            Iterator<ProfileMappingRecord> profileMappings = database.findRecords(filter).iterator();
 
             ProfileMappingCollection response = new ProfileMappingCollection();
             int i = 0;
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/ProfileService.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/ProfileService.java
index 866a1dc7f8942fa4f745eec25f8b314baafef3e0..723075a407473e0a78dd2d8d5f94e12dad0b8a01 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/ProfileService.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/ProfileService.java
@@ -95,7 +95,7 @@ public class ProfileService extends PKIService implements ProfileResource {
     }
 
     @Override
-    public Response findProfiles(Integer start, Integer size) {
+    public Response findProfiles(String filter, Integer start, Integer size) {
 
         CMS.debug("ProfileService.findProfiles()");
 
@@ -106,7 +106,7 @@ public class ProfileService extends PKIService implements ProfileResource {
             TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             ProfileDatabase database = subsystem.getProfileDatabase();
 
-            Iterator<ProfileRecord> profiles = database.getRecords().iterator();
+            Iterator<ProfileRecord> profiles = database.findRecords(filter).iterator();
 
             ProfileCollection response = new ProfileCollection();
             int i = 0;
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/TPSCertService.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/TPSCertService.java
index 45e5db6b83c684dcad0ae070fdda4f3f70a73c7c..275631ba4988f75b33fc4bab79debb3d32c45c88 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/TPSCertService.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/TPSCertService.java
@@ -110,7 +110,7 @@ public class TPSCertService extends PKIService implements TPSCertResource {
     }
 
     @Override
-    public Response findCerts(Integer start, Integer size) {
+    public Response findCerts(String filter, Integer start, Integer size) {
 
         System.out.println("TPSCertService.findCerts()");
 
@@ -121,7 +121,7 @@ public class TPSCertService extends PKIService implements TPSCertResource {
             TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             TPSCertDatabase database = subsystem.getCertDatabase();
 
-            Iterator<TPSCertRecord> activities = database.getRecords().iterator();
+            Iterator<TPSCertRecord> activities = database.findRecords(filter).iterator();
 
             TPSCertCollection response = new TPSCertCollection();
             int i = 0;
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/TokenService.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/TokenService.java
index 3f30e973b3eabd1130b2d738cd04d99d4e68f6de..110abe7db70f06798fdfc95e84b12389df2722d2 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/TokenService.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/TokenService.java
@@ -109,7 +109,7 @@ public class TokenService extends PKIService implements TokenResource {
     }
 
     @Override
-    public Response findTokens(Integer start, Integer size) {
+    public Response findTokens(String filter, Integer start, Integer size) {
 
         CMS.debug("TokenService.findTokens()");
 
@@ -120,7 +120,7 @@ public class TokenService extends PKIService implements TokenResource {
             TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             TokenDatabase database = subsystem.getTokenDatabase();
 
-            Iterator<TokenRecord> tokens = database.getRecords().iterator();
+            Iterator<TokenRecord> tokens = database.findRecords(filter).iterator();
 
             TokenCollection response = new TokenCollection();
             int i = 0;
-- 
1.8.4.2

