summaryrefslogtreecommitdiffstats
path: root/base/server/cms/src/com
diff options
context:
space:
mode:
Diffstat (limited to 'base/server/cms/src/com')
-rw-r--r--base/server/cms/src/com/netscape/cms/servlet/cert/CertRequestDAO.java10
-rw-r--r--base/server/cms/src/com/netscape/cms/servlet/cert/CertService.java102
-rw-r--r--base/server/cms/src/com/netscape/cms/servlet/key/KeyRequestDAO.java6
-rw-r--r--base/server/cms/src/com/netscape/cms/servlet/key/KeyService.java51
-rw-r--r--base/server/cms/src/com/netscape/cms/servlet/profile/ProfileService.java54
-rw-r--r--base/server/cms/src/com/netscape/cms/servlet/request/CMSRequestDAO.java9
-rw-r--r--base/server/cms/src/com/netscape/cms/servlet/request/CertRequestService.java66
7 files changed, 194 insertions, 104 deletions
diff --git a/base/server/cms/src/com/netscape/cms/servlet/cert/CertRequestDAO.java b/base/server/cms/src/com/netscape/cms/servlet/cert/CertRequestDAO.java
index 70433339f..c94ee1496 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/cert/CertRequestDAO.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/cert/CertRequestDAO.java
@@ -93,14 +93,16 @@ public class CertRequestDAO extends CMSRequestDAO {
CMSRequestInfos cmsInfos = listCMSRequests(filter, start, pageSize, maxResults, maxTime, uriInfo);
- Collection<? extends CMSRequestInfo> cmsList = cmsInfos.getRequests();
+ ret.setTotal(cmsInfos.getTotal());
+
+ Collection<? extends CMSRequestInfo> cmsList = cmsInfos.getEntries();
// We absolutely know 100% that this list is a list
// of CertRequestInfo objects. This is because the method
// createCMSRequestInfo. Is the only one adding to it
List<CertRequestInfo> list = (List<CertRequestInfo>) cmsList;
- ret.setRequests(list);
+ ret.setEntries(list);
ret.setLinks(cmsInfos.getLinks());
@@ -179,9 +181,11 @@ public class CertRequestDAO extends CMSRequestDAO {
IRequest reqs[] = (IRequest[]) results.get(CAProcessor.ARG_REQUESTS);
for (IRequest req : reqs) {
CertRequestInfo info = CertRequestInfoFactory.create(req, uriInfo);
- ret.addRequest(info);
+ ret.addEntry(info);
}
+ ret.setTotal(ret.getEntries().size());
+
// TODO - what happens if the errorCode is internal error ?
return ret;
diff --git a/base/server/cms/src/com/netscape/cms/servlet/cert/CertService.java b/base/server/cms/src/com/netscape/cms/servlet/cert/CertService.java
index 483ae139c..1b4954822 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/cert/CertService.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/cert/CertService.java
@@ -103,6 +103,8 @@ public class CertService extends PKIService implements CertResource {
ICertificateRepository repo;
Random random;
+ public static final int DEFAULT_MAXTIME = 0;
+ public static final int DEFAULT_MAXRESULTS = 20;
public final static int DEFAULT_SIZE = 20;
public CertService() {
@@ -387,36 +389,74 @@ public class CertService extends PKIService implements CertResource {
}
@Override
- public CertDataInfos listCerts(String status, int maxResults, int maxTime) {
- // get ldap filter
+ public CertDataInfos listCerts(String status, Integer maxResults, Integer maxTime, Integer start, Integer size) {
+
+ maxResults = maxResults == null ? DEFAULT_MAXRESULTS : maxResults;
+ maxTime = maxTime == null ? DEFAULT_MAXTIME : maxTime;
+ start = start == null ? 0 : start;
+ size = size == null ? DEFAULT_SIZE : size;
+
String filter = createSearchFilter(status);
- CMS.debug("listKeys: filter is " + filter);
+ CMS.debug("listCerts: filter is " + filter);
- CertDataInfos infos;
+ CertDataInfos infos = new CertDataInfos();
try {
- infos = getCertList(filter, maxResults, maxTime);
+ Enumeration<ICertRecord> e = repo.searchCertificates(filter, maxResults, maxTime);
+ if (e == null) {
+ throw new EBaseException("search results are null");
+ }
+
+ // store non-null results in a list
+ List<CertDataInfo> results = new ArrayList<CertDataInfo>();
+ while (e.hasMoreElements()) {
+ ICertRecord rec = e.nextElement();
+ if (rec == null) continue;
+ results.add(createCertDataInfo(rec));
+ }
+
+ int total = results.size();
+ infos.setTotal(total);
+
+ // return entries in the requested page
+ for (int i = start; i < start + size && i < total ; i++) {
+ infos.addEntry(results.get(i));
+ }
+
+ if (start > 0) {
+ URI uri = uriInfo.getRequestUriBuilder().replaceQueryParam("start", Math.max(start - size, 0)).build();
+ infos.addLink(new Link("prev", uri));
+ }
+
+ if (start + size < total) {
+ URI uri = uriInfo.getRequestUriBuilder().replaceQueryParam("start", start + size).build();
+ infos.addLink(new Link("next", uri));
+ }
+
} catch (Exception e) {
e.printStackTrace();
- throw new PKIException("Error listing certs in CertsResourceService.listCerts!", e);
+ throw new PKIException("Error listing certs in CertService.listCerts!", e);
}
+
return infos;
}
@Override
public CertDataInfos searchCerts(CertSearchRequest data, Integer start, Integer size) {
+
if (data == null) {
throw new BadRequestException("Search request is null.");
}
+
start = start == null ? 0 : start;
size = size == null ? DEFAULT_SIZE : size;
String filter = createSearchFilter(data);
CertDataInfos infos = new CertDataInfos();
-
- Enumeration<ICertRecord> e = null;
try {
-
- e = repo.findCertRecords(filter);
+ Enumeration<ICertRecord> e = repo.findCertRecords(filter);
+ if (e == null) {
+ throw new EBaseException("search results are null");
+ }
int i = 0;
@@ -427,13 +467,15 @@ public class CertService extends PKIService implements CertResource {
// return entries up to the page size
for (; i < start + size && e.hasMoreElements(); i++) {
ICertRecord user = e.nextElement();
- infos.addCertData(createCertDataInfo(user));
+ infos.addEntry(createCertDataInfo(user));
}
// count the total entries
for (; e.hasMoreElements(); i++)
e.nextElement();
+ infos.setTotal(i);
+
if (start > 0) {
URI uri = uriInfo.getRequestUriBuilder().replaceQueryParam("start", Math.max(start - size, 0)).build();
infos.addLink(new Link("prev", uri));
@@ -443,48 +485,14 @@ public class CertService extends PKIService implements CertResource {
URI uri = uriInfo.getRequestUriBuilder().replaceQueryParam("start", start + size).build();
infos.addLink(new Link("next", uri));
}
+
} catch (Exception e1) {
- throw new PKIException("Error listing certs in CertsResourceService.listCerts!", e1);
+ throw new PKIException("Error searching certs in CertService.searchCerts!", e1);
}
return infos;
}
- /**
- * Returns list of certs meeting specified search filter.
- * Currently, vlv searches are not used for certs.
- *
- * @param filter
- * @param maxResults
- * @param maxTime
- * @param uriInfo
- * @return
- * @throws EBaseException
- * @throws InvalidKeyException
- */
- private CertDataInfos getCertList(String filter, int maxResults, int maxTime)
- throws EBaseException, InvalidKeyException {
- List<CertDataInfo> list = new ArrayList<CertDataInfo>();
- Enumeration<ICertRecord> e = null;
-
- e = repo.searchCertificates(filter, maxResults, maxTime);
- if (e == null) {
- throw new EBaseException("search results are null");
- }
-
- while (e.hasMoreElements()) {
- ICertRecord rec = e.nextElement();
- if (rec != null) {
- list.add(createCertDataInfo(rec));
- }
- }
-
- CertDataInfos ret = new CertDataInfos();
- ret.setCertInfos(list);
-
- return ret;
- }
-
public CertData getCert(CertRetrievalRequest data, boolean generateNonce) throws EBaseException, CertificateEncodingException {
CertId certId = data.getCertId();
diff --git a/base/server/cms/src/com/netscape/cms/servlet/key/KeyRequestDAO.java b/base/server/cms/src/com/netscape/cms/servlet/key/KeyRequestDAO.java
index bef0455a9..49cd4515d 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/key/KeyRequestDAO.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/key/KeyRequestDAO.java
@@ -88,14 +88,16 @@ public class KeyRequestDAO extends CMSRequestDAO {
CMSRequestInfos cmsInfos = listCMSRequests(filter, start, pageSize, maxResults, maxTime, uriInfo);
- Collection<? extends CMSRequestInfo> cmsList = cmsInfos.getRequests();
+ ret.setTotal(cmsInfos.getTotal());
+
+ Collection<? extends CMSRequestInfo> cmsList = cmsInfos.getEntries();
// We absolutely know 100% that this list is a list
// of KeyRequestInfo objects. This is because the method
// createCMSRequestInfo. Is the only one adding to it
List<KeyRequestInfo> list = (List<KeyRequestInfo>) cmsList;
- ret.setRequests(list);
+ ret.setEntries(list);
ret.setLinks(cmsInfos.getLinks());
diff --git a/base/server/cms/src/com/netscape/cms/servlet/key/KeyService.java b/base/server/cms/src/com/netscape/cms/servlet/key/KeyService.java
index 90bc61d2d..27cc909e5 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/key/KeyService.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/key/KeyService.java
@@ -20,8 +20,11 @@ package com.netscape.cms.servlet.key;
import java.math.BigInteger;
+import java.net.URI;
+import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Path;
@@ -32,6 +35,8 @@ import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
+import org.jboss.resteasy.plugins.providers.atom.Link;
+
import com.netscape.certsrv.apps.CMS;
import com.netscape.certsrv.base.BadRequestException;
import com.netscape.certsrv.base.EBaseException;
@@ -74,15 +79,16 @@ public class KeyService extends PKIService implements KeyResource {
@Context
private HttpServletRequest servletRequest;
- private IKeyRepository repo;
- private IKeyRecoveryAuthority kra;
- private IRequestQueue queue;
-
private final static String LOGGING_SIGNED_AUDIT_SECURITY_DATA_RETRIEVE_KEY =
"LOGGING_SIGNED_AUDIT_SECURITY_DATA_RETRIEVE_KEY_5";
public static final int DEFAULT_MAXRESULTS = 100;
public static final int DEFAULT_MAXTIME = 10;
+ public final static int DEFAULT_SIZE = 20;
+
+ private IKeyRepository repo;
+ private IKeyRecoveryAuthority kra;
+ private IRequestQueue queue;
public KeyService() {
kra = ( IKeyRecoveryAuthority ) CMS.getSubsystem( "kra" );
@@ -288,8 +294,11 @@ public class KeyService extends PKIService implements KeyResource {
* Used to generate list of key infos based on the search parameters
*/
@Override
- public KeyDataInfos listKeys(String clientID, String status, Integer maxResults, Integer maxTime) {
- // auth and authz
+ public KeyDataInfos listKeys(String clientID, String status, Integer maxResults, Integer maxTime,
+ Integer start, Integer size) {
+
+ start = start == null ? 0 : start;
+ size = size == null ? DEFAULT_SIZE : size;
// get ldap filter
String filter = createSearchFilter(status, clientID);
@@ -300,24 +309,42 @@ public class KeyService extends PKIService implements KeyResource {
KeyDataInfos infos = new KeyDataInfos();
try {
- Enumeration<IKeyRecord> e = null;
-
- e = repo.searchKeys(filter, maxResults, maxTime);
+ Enumeration<IKeyRecord> e = repo.searchKeys(filter, maxResults, maxTime);
if (e == null) {
return infos;
}
+ // store non-null results in a list
+ List<KeyDataInfo> results = new ArrayList<KeyDataInfo>();
while (e.hasMoreElements()) {
IKeyRecord rec = e.nextElement();
- if (rec != null) {
- infos.addKeyInfo(createKeyDataInfo(rec));
- }
+ if (rec == null) continue;
+ results.add(createKeyDataInfo(rec));
+ }
+
+ int total = results.size();
+ infos.setTotal(total);
+
+ // return entries in the requested page
+ for (int i = start; i < start + size && i < total; i++) {
+ infos.addEntry(results.get(i));
+ }
+
+ if (start > 0) {
+ URI uri = uriInfo.getRequestUriBuilder().replaceQueryParam("start", Math.max(start-size, 0)).build();
+ infos.addLink(new Link("prev", uri));
+ }
+
+ if (start + size < total) {
+ URI uri = uriInfo.getRequestUriBuilder().replaceQueryParam("start", start+size).build();
+ infos.addLink(new Link("next", uri));
}
} catch (EBaseException e) {
e.printStackTrace();
throw new PKIException(e.getMessage());
}
+
return infos;
}
diff --git a/base/server/cms/src/com/netscape/cms/servlet/profile/ProfileService.java b/base/server/cms/src/com/netscape/cms/servlet/profile/ProfileService.java
index 1ee810769..02840451c 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/profile/ProfileService.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/profile/ProfileService.java
@@ -96,6 +96,8 @@ public class ProfileService extends PKIService implements ProfileResource {
@Context
private HttpServletRequest servletRequest;
+ public final static int DEFAULT_SIZE = 20;
+
private IProfileSubsystem ps = (IProfileSubsystem) CMS.getSubsystem(IProfileSubsystem.ID);
private IPluginRegistry registry = (IPluginRegistry) CMS.getSubsystem(CMS.SUBSYSTEM_REGISTRY);
private IConfigStore cs = CMS.getConfigStore().getSubStore("profile");
@@ -106,8 +108,11 @@ public class ProfileService extends PKIService implements ProfileResource {
"LOGGING_SIGNED_AUDIT_CONFIG_CERT_PROFILE_3";
@Override
- public ProfileDataInfos listProfiles() {
- List<ProfileDataInfo> list = new ArrayList<ProfileDataInfo>();
+ public ProfileDataInfos listProfiles(Integer start, Integer size) {
+
+ start = start == null ? 0 : start;
+ size = size == null ? DEFAULT_SIZE : size;
+
ProfileDataInfos infos = new ProfileDataInfos();
boolean visibleOnly = true;
@@ -122,24 +127,41 @@ public class ProfileService extends PKIService implements ProfileResource {
principal.hasRole("Certificate Manager Administrators"))) {
visibleOnly = false;
}
- Enumeration<String> profileIds = ps.getProfileIds();
- if (profileIds != null) {
- while (profileIds.hasMoreElements()) {
- String id = profileIds.nextElement();
- ProfileDataInfo info = null;
- try {
- info = createProfileDataInfo(id, visibleOnly, uriInfo, getLocale(headers));
- } catch (EBaseException e) {
- continue;
- }
- if (info != null) {
- list.add(info);
- }
+ Enumeration<String> e = ps.getProfileIds();
+ if (e == null) return infos;
+
+ // store non-null results in a list
+ List<ProfileDataInfo> results = new ArrayList<ProfileDataInfo>();
+ while (e.hasMoreElements()) {
+ try {
+ String id = e.nextElement();
+ ProfileDataInfo info = createProfileDataInfo(id, visibleOnly, uriInfo, getLocale(headers));
+ if (info == null) continue;
+ results.add(info);
+ } catch (EBaseException ex) {
+ continue;
}
}
- infos.setProfileInfos(list);
+ int total = results.size();
+ infos.setTotal(total);
+
+ // return entries in the requested page
+ for (int i = start; i < start + size && i < total; i++) {
+ infos.addEntry(results.get(i));
+ }
+
+ if (start > 0) {
+ URI uri = uriInfo.getRequestUriBuilder().replaceQueryParam("start", Math.max(start-size, 0)).build();
+ infos.addLink(new Link("prev", uri));
+ }
+
+ if (start + size < total) {
+ URI uri = uriInfo.getRequestUriBuilder().replaceQueryParam("start", start+size).build();
+ infos.addLink(new Link("next", uri));
+ }
+
return infos;
}
diff --git a/base/server/cms/src/com/netscape/cms/servlet/request/CMSRequestDAO.java b/base/server/cms/src/com/netscape/cms/servlet/request/CMSRequestDAO.java
index e54f8a4c6..931ade159 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/request/CMSRequestDAO.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/request/CMSRequestDAO.java
@@ -23,10 +23,11 @@ import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
+import org.jboss.resteasy.plugins.providers.atom.Link;
+
import com.netscape.certsrv.apps.CMS;
import com.netscape.certsrv.authority.IAuthority;
import com.netscape.certsrv.base.EBaseException;
-import com.netscape.certsrv.base.Link;
import com.netscape.certsrv.request.CMSRequestInfo;
import com.netscape.certsrv.request.CMSRequestInfos;
import com.netscape.certsrv.request.IRequest;
@@ -91,6 +92,7 @@ public abstract class CMSRequestDAO {
IRequestVirtualList vlvlist = queue.getPagedRequestsByFilter(start, false, filter,
pageSize + 1, "requestId");
totalSize = vlvlist.getSize();
+ ret.setTotal(totalSize);
current = vlvlist.getCurrentIndex();
int numRecords = (totalSize > (current + pageSize)) ? pageSize :
@@ -98,7 +100,7 @@ public abstract class CMSRequestDAO {
for (int i = 0; i < numRecords; i++) {
IRequest request = vlvlist.getElementAt(i);
- ret.addRequest(createCMSRequestInfo(request, uriInfo));
+ ret.addEntry(createCMSRequestInfo(request, uriInfo));
}
} else {
// The non-vlv requests are indexed, but are not paginated.
@@ -113,9 +115,10 @@ public abstract class CMSRequestDAO {
RequestId rid = requests.nextElement();
IRequest request = queue.findRequest(rid);
if (request != null) {
- ret.addRequest(createCMSRequestInfo(request, uriInfo));
+ ret.addEntry(createCMSRequestInfo(request, uriInfo));
}
}
+ ret.setTotal(ret.getEntries().size());
}
// builder for vlv links
diff --git a/base/server/cms/src/com/netscape/cms/servlet/request/CertRequestService.java b/base/server/cms/src/com/netscape/cms/servlet/request/CertRequestService.java
index 56da823d2..cd3ffee5a 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/request/CertRequestService.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/request/CertRequestService.java
@@ -18,6 +18,7 @@
package com.netscape.cms.servlet.request;
+import java.net.URI;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
@@ -30,6 +31,8 @@ import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;
+import org.jboss.resteasy.plugins.providers.atom.Link;
+
import com.netscape.certsrv.apps.CMS;
import com.netscape.certsrv.authentication.EAuthException;
import com.netscape.certsrv.authorization.EAuthzException;
@@ -119,13 +122,15 @@ public class CertRequestService extends PKIService implements CertRequestResourc
@Override
public CertRequestInfos enrollCert(CertEnrollmentRequest data) {
- CertRequestInfos infos;
+
if (data == null) {
CMS.debug("enrollCert: data is null");
throw new BadRequestException("Unable to create enrollment reequest: Invalid input data");
}
+
CertRequestDAO dao = new CertRequestDAO();
+ CertRequestInfos infos;
try {
infos = dao.submitRequest(data, servletRequest, uriInfo, getLocale(headers));
} catch (EAuthException e) {
@@ -354,35 +359,54 @@ public class CertRequestService extends PKIService implements CertRequestResourc
}
@Override
- public ProfileDataInfos listEnrollmentTemplates() {
+ public ProfileDataInfos listEnrollmentTemplates(Integer start, Integer size) {
+
+ start = start == null ? DEFAULT_START : start;
+ size = size == null ? DEFAULT_PAGESIZE : size;
+
IProfileSubsystem ps = (IProfileSubsystem) CMS.getSubsystem(IProfileSubsystem.ID);
- List<ProfileDataInfo> list = new ArrayList<ProfileDataInfo>();
- ProfileDataInfos infos = new ProfileDataInfos();
- boolean visibleOnly = true;
if (ps == null) {
- return null;
+ throw new PKIException("Profile subsystem unavailable.");
}
- Enumeration<String> profileIds = ps.getProfileIds();
- if (profileIds != null) {
- while (profileIds.hasMoreElements()) {
- String id = profileIds.nextElement();
- ProfileDataInfo info = null;
- try {
- info = ProfileService.createProfileDataInfo(id, visibleOnly, uriInfo, getLocale(headers));
- } catch (EBaseException e) {
- continue;
- }
+ ProfileDataInfos infos = new ProfileDataInfos();
+ boolean visibleOnly = true;
- if (info != null) {
- list.add(info);
- }
+ Enumeration<String> e = ps.getProfileIds();
+ if (e == null) return infos;
+
+ // store non-null results in a list
+ List<ProfileDataInfo> results = new ArrayList<ProfileDataInfo>();
+ while (e.hasMoreElements()) {
+ try {
+ String id = e.nextElement();
+ ProfileDataInfo info = ProfileService.createProfileDataInfo(id, visibleOnly, uriInfo, getLocale(headers));
+ if (info == null) continue;
+ results.add(info);
+ } catch (EBaseException ex) {
+ continue;
}
}
- infos.setProfileInfos(list);
+ int total = results.size();
+ infos.setTotal(total);
+
+ // return entries in the requested page
+ for (int i = start; i < start + size && i < total; i++) {
+ infos.addEntry(results.get(i));
+ }
+
+ if (start > 0) {
+ URI uri = uriInfo.getRequestUriBuilder().replaceQueryParam("start", Math.max(start-size, 0)).build();
+ infos.addLink(new Link("prev", uri));
+ }
+
+ if (start + size < total) {
+ URI uri = uriInfo.getRequestUriBuilder().replaceQueryParam("start", start+size).build();
+ infos.addLink(new Link("next", uri));
+ }
+
return infos;
}
-
}