diff options
author | Endi Sukma Dewata <edewata@redhat.com> | 2012-02-28 00:05:53 -0600 |
---|---|---|
committer | Endi Sukma Dewata <edewata@redhat.com> | 2012-03-05 14:28:39 -0600 |
commit | 2956ea8a9003d637a3e161621eb97f7be779d94c (patch) | |
tree | e327fef6639edd513f6b9250d955d250ba1a74b5 /pki/base/common/src | |
parent | ea1bbcfb01ca2a1b4d6f0ac83ba7662c0a576a05 (diff) | |
download | pki-2956ea8a9003d637a3e161621eb97f7be779d94c.tar.gz pki-2956ea8a9003d637a3e161621eb97f7be779d94c.tar.xz pki-2956ea8a9003d637a3e161621eb97f7be779d94c.zip |
Fixed DRM REST interface to use BigInteger.
The DRM REST interface previously uses strings for key ID and request ID.
It has been modified to use KeyId and RequestId classes which can accept
decimal or hex numbers and internally store it as BigInteger.
Ticket #94
Diffstat (limited to 'pki/base/common/src')
21 files changed, 387 insertions, 104 deletions
diff --git a/pki/base/common/src/CMakeLists.txt b/pki/base/common/src/CMakeLists.txt index 62d30740d..ed83bb68e 100644 --- a/pki/base/common/src/CMakeLists.txt +++ b/pki/base/common/src/CMakeLists.txt @@ -200,6 +200,8 @@ set(pki-certsrv_java_SRCS com/netscape/certsrv/dbs/Modification.java com/netscape/certsrv/dbs/EDBNotAvailException.java com/netscape/certsrv/dbs/IDBVirtualList.java + com/netscape/certsrv/dbs/keydb/KeyId.java + com/netscape/certsrv/dbs/keydb/KeyIdAdapter.java com/netscape/certsrv/dbs/keydb/KeyState.java com/netscape/certsrv/dbs/keydb/IKeyRecord.java com/netscape/certsrv/dbs/keydb/IKeyRecordList.java @@ -301,6 +303,7 @@ set(pki-certsrv_java_SRCS com/netscape/certsrv/request/AgentApprovals.java com/netscape/certsrv/request/IRequestRecord.java com/netscape/certsrv/request/RequestId.java + com/netscape/certsrv/request/RequestIdAdapter.java com/netscape/certsrv/request/IService.java com/netscape/certsrv/request/IRequestListener.java com/netscape/certsrv/request/AgentApproval.java diff --git a/pki/base/common/src/com/netscape/certsrv/dbs/keydb/KeyId.java b/pki/base/common/src/com/netscape/certsrv/dbs/keydb/KeyId.java new file mode 100644 index 000000000..f998bf97a --- /dev/null +++ b/pki/base/common/src/com/netscape/certsrv/dbs/keydb/KeyId.java @@ -0,0 +1,122 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.dbs.keydb; + +import java.math.BigInteger; + +/** + * The KeyId class represents the identifier for a particular + * key record. This identifier may be used to retrieve the key record + * from the database. + * <p> + * + * @author Endi S. Dewata + * @version $Revision$ $Date$ + */ +public class KeyId { + + protected BigInteger value; + + /** + * Creates a new KeyId from its string representation. + * <p> + * + * @param id + * a string containing the decimal or hex value for the identifier. + */ + public KeyId(String id) { + if (id != null) { + id = id.trim(); + if (id.startsWith("0x")) { // hex + value = new BigInteger(id.substring(2), 16); + } else { // decimal + value = new BigInteger(id); + } + } + } + + /** + * Creates a new KeyId from its BigInteger representation. + * <p> + * + * @param id + * a BigInteger containing the identifier. + */ + public KeyId(BigInteger id) { + value = id; + } + + /** + * Creates a new KeyId from its integer representation. + * <p> + * + * @param id + * an integer containing the identifier. + */ + public KeyId(int id) { + value = BigInteger.valueOf(id); + } + + /** + * Converts the KeyId into its BigInteger representation. + * <p> + * + * @return + * a BigInteger containing the identifier. + */ + public BigInteger toBigInteger() { + return value; + } + + /** + * Converts the KeyId into its string representation. The string + * form can be stored in a database (such as the LDAP directory) + * <p> + * + * @return + * a string containing the decimal (base 10) value for the identifier. + */ + public String toString() { + return value.toString(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + KeyId other = (KeyId) obj; + if (value == null) { + if (other.value != null) + return false; + } else if (!value.equals(other.value)) + return false; + return true; + } +} diff --git a/pki/base/common/src/com/netscape/certsrv/dbs/keydb/KeyIdAdapter.java b/pki/base/common/src/com/netscape/certsrv/dbs/keydb/KeyIdAdapter.java new file mode 100644 index 000000000..3232999fd --- /dev/null +++ b/pki/base/common/src/com/netscape/certsrv/dbs/keydb/KeyIdAdapter.java @@ -0,0 +1,37 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.dbs.keydb; + +import javax.xml.bind.annotation.adapters.XmlAdapter; + +/** + * The KeyIdAdapter class provides custom marshaling for KeyId. + * + * @author Endi S. Dewata + * @version $Revision$ $Date$ + */ +public class KeyIdAdapter extends XmlAdapter<String, KeyId> { + + public KeyId unmarshal(String value) throws Exception { + return new KeyId(value); + } + + public String marshal(KeyId value) throws Exception { + return value.toString(); + } +} diff --git a/pki/base/common/src/com/netscape/certsrv/request/RequestId.java b/pki/base/common/src/com/netscape/certsrv/request/RequestId.java index 31681675b..da61f2bc0 100644 --- a/pki/base/common/src/com/netscape/certsrv/request/RequestId.java +++ b/pki/base/common/src/com/netscape/certsrv/request/RequestId.java @@ -17,6 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.certsrv.request; +import java.math.BigInteger; + /** * The RequestId class represents the identifier for a particular * request within a request queue. This identifier may be used to @@ -25,52 +27,95 @@ package com.netscape.certsrv.request; * * @version $Revision$ $Date$ */ -public final class RequestId { +public class RequestId { + + protected BigInteger value; /** * Creates a new RequestId from its string representation. * <p> * * @param id - * a string containing the decimal (base 10) value for the identifier. + * a string containing the decimal or hex value for the identifier. */ public RequestId(String id) { - mString = id; + if (id != null) { + id = id.trim(); + if (id.startsWith("0x")) { // hex + value = new BigInteger(id.substring(2), 16); + } else { // decimal + value = new BigInteger(id); + } + } } /** - * Converts the RequestId into its string representation. The string - * form can be stored in a database (such as the LDAP directory) + * Creates a new RequestId from its BigInteger representation. * <p> - * - * @return - * a string containing the decimal (base 10) value for the identifier. + * + * @param id + * a BigInteger containing the identifier. */ - public String toString() { - return mString; + public RequestId(BigInteger id) { + value = id; } /** - * Implements Object.hashCode. + * Creates a new RequestId from its integer representation. * <p> - * - * @return hash code of the object + * + * @param id + * an integer containing the identifier. */ - public int hashCode() { - return mString.hashCode(); + public RequestId(int id) { + value = BigInteger.valueOf(id); } /** - * Implements Object.equals. + * Converts the RequestId into its BigInteger representation. + * <p> + * + * @return + * a BigInteger containing the identifier. + */ + public BigInteger toBigInteger() { + return value; + } + + /** + * Converts the RequestId into its string representation. The string + * form can be stored in a database (such as the LDAP directory) * <p> * - * @param obj object to compare - * @return true if objects are equal + * @return + * a string containing the decimal (base 10) value for the identifier. */ - public boolean equals(Object obj) { - return mString.equals(obj); + public String toString() { + return value.toString(); } - // instance variables - private final String mString; + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + RequestId other = (RequestId) obj; + if (value == null) { + if (other.value != null) + return false; + } else if (!value.equals(other.value)) + return false; + return true; + } } diff --git a/pki/base/common/src/com/netscape/certsrv/request/RequestIdAdapter.java b/pki/base/common/src/com/netscape/certsrv/request/RequestIdAdapter.java new file mode 100644 index 000000000..1780bc337 --- /dev/null +++ b/pki/base/common/src/com/netscape/certsrv/request/RequestIdAdapter.java @@ -0,0 +1,37 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.request; + +import javax.xml.bind.annotation.adapters.XmlAdapter; + +/** + * The RequestIdAdapter class provides custom marshaling for RequestId. + * + * @author Endi S. Dewata + * @version $Revision$ $Date$ + */ +public class RequestIdAdapter extends XmlAdapter<String, RequestId> { + + public RequestId unmarshal(String value) throws Exception { + return new RequestId(value); + } + + public String marshal(RequestId value) throws Exception { + return value.toString(); + } +}
\ No newline at end of file diff --git a/pki/base/common/src/com/netscape/cms/servlet/key/KeyResourceService.java b/pki/base/common/src/com/netscape/cms/servlet/key/KeyResourceService.java index 4888d609f..79e6ccfdb 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/key/KeyResourceService.java +++ b/pki/base/common/src/com/netscape/cms/servlet/key/KeyResourceService.java @@ -32,8 +32,11 @@ import com.netscape.cms.servlet.request.model.KeyRequestDAO; import com.netscape.cms.servlet.request.model.KeyRequestInfo; import com.netscape.cms.servlet.request.model.RecoveryRequestData; import com.netscape.certsrv.request.IRequest; +import com.netscape.certsrv.request.RequestId; import com.netscape.certsrv.request.RequestStatus; import com.netscape.certsrv.base.EBaseException; +import com.netscape.certsrv.dbs.keydb.KeyId; + /** * @author alee * @@ -50,7 +53,7 @@ public class KeyResourceService extends CMSResourceService implements KeyResourc */ public KeyData retrieveKey(RecoveryRequestData data) { // auth and authz - String keyId = validateRequest(data); + KeyId keyId = validateRequest(data); KeyDAO dao = new KeyDAO(); KeyData keyData; try { @@ -73,10 +76,10 @@ public class KeyResourceService extends CMSResourceService implements KeyResourc return retrieveKey(data); } - private String validateRequest(RecoveryRequestData data) { + private KeyId validateRequest(RecoveryRequestData data) { // confirm request exists - String reqId = data.getRequestId(); + RequestId reqId = data.getRequestId(); if (reqId == null) { // log error throw new WebApplicationException(Response.Status.BAD_REQUEST); @@ -120,8 +123,7 @@ public class KeyResourceService extends CMSResourceService implements KeyResourc throw new WebApplicationException(Response.Status.UNAUTHORIZED); } - String keyURL = reqInfo.getKeyURL(); - return keyURL.substring(keyURL.lastIndexOf("/") + 1); + return reqInfo.getKeyId(); } } diff --git a/pki/base/common/src/com/netscape/cms/servlet/key/KeysResource.java b/pki/base/common/src/com/netscape/cms/servlet/key/KeysResource.java index 35cd5ccbe..c93ffa4c9 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/key/KeysResource.java +++ b/pki/base/common/src/com/netscape/cms/servlet/key/KeysResource.java @@ -10,14 +10,14 @@ import com.netscape.cms.servlet.key.model.KeyDataInfos; @Path("/keys") public interface KeysResource { - public static final String DEFAULT_MAXTIME = "10"; - public static final String DEFAULT_MAXRESULTS = "100"; + public static final int DEFAULT_MAXTIME = 10; + public static final int DEFAULT_MAXRESULTS = 100; @GET @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_XML }) public KeyDataInfos listKeys(@QueryParam("clientID") String clientID, @QueryParam("status") String status, - @DefaultValue(DEFAULT_MAXRESULTS) @QueryParam("maxResults") int maxResults, - @DefaultValue(DEFAULT_MAXTIME) @QueryParam("maxTime") int maxTime); + @DefaultValue(""+DEFAULT_MAXRESULTS) @QueryParam("maxResults") int maxResults, + @DefaultValue(""+DEFAULT_MAXTIME) @QueryParam("maxTime") int maxTime); } diff --git a/pki/base/common/src/com/netscape/cms/servlet/key/model/KeyDAO.java b/pki/base/common/src/com/netscape/cms/servlet/key/model/KeyDAO.java index f2ee46c66..f479c6f0d 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/key/model/KeyDAO.java +++ b/pki/base/common/src/com/netscape/cms/servlet/key/model/KeyDAO.java @@ -30,6 +30,7 @@ import com.netscape.certsrv.apps.CMS; import com.netscape.certsrv.base.EBaseException; import com.netscape.certsrv.dbs.keydb.IKeyRecord; import com.netscape.certsrv.dbs.keydb.IKeyRepository; +import com.netscape.certsrv.dbs.keydb.KeyId; import com.netscape.certsrv.kra.IKeyRecoveryAuthority; import com.netscape.certsrv.request.IRequest; import com.netscape.certsrv.request.IRequestQueue; @@ -87,23 +88,22 @@ public class KeyDAO { return ret; } - public KeyData getKey(String keyId, RecoveryRequestData data) throws EBaseException { + public KeyData getKey(KeyId keyId, RecoveryRequestData data) throws EBaseException { KeyData keyData; - BigInteger serial = new BigInteger(keyId); - - String rId = data.getRequestId(); + + RequestId rId = data.getRequestId(); String transWrappedSessionKey; String sessionWrappedPassphrase; - IRequest request = queue.findRequest(new RequestId(rId)); + IRequest request = queue.findRequest(rId); if (request == null) { return null; } // get wrapped key - IKeyRecord rec = repo.readKeyRecord(serial); + IKeyRecord rec = repo.readKeyRecord(keyId.toBigInteger()); if (rec == null) { return null; } @@ -133,7 +133,7 @@ public class KeyDAO { sessionWrappedPassphrase = data.getSessionWrappedPassphrase(); nonceData = data.getNonceData(); - if(transWrappedSessionKey == null) { + if (transWrappedSessionKey == null) { //There must be at least a transWrappedSessionKey input provided. //The command AND the request have provided insufficient data, end of the line. throw new EBaseException("Can't retrieve key, insufficient input data!"); diff --git a/pki/base/common/src/com/netscape/cms/servlet/key/model/KeyDataInfo.java b/pki/base/common/src/com/netscape/cms/servlet/key/model/KeyDataInfo.java index 46843ba90..88b31b4d1 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/key/model/KeyDataInfo.java +++ b/pki/base/common/src/com/netscape/cms/servlet/key/model/KeyDataInfo.java @@ -26,6 +26,8 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlAccessorType; +import com.netscape.certsrv.dbs.keydb.KeyId; + /** * @author alee * @@ -59,6 +61,14 @@ public class KeyDataInfo { } /** + * @return the key ID in the keyURL + */ + public KeyId getKeyId() { + String id = keyURL.substring(keyURL.lastIndexOf("/") + 1); + return new KeyId(id); + } + + /** * @return the clientID */ public String getClientID() { diff --git a/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestResource.java b/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestResource.java index 656768f02..cd08f46bb 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestResource.java +++ b/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestResource.java @@ -8,6 +8,8 @@ import javax.ws.rs.Produces; import javax.ws.rs.Consumes; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; + +import com.netscape.certsrv.request.RequestId; import com.netscape.cms.servlet.request.model.ArchivalRequestData; import com.netscape.cms.servlet.request.model.KeyRequestInfo; import com.netscape.cms.servlet.request.model.RecoveryRequestData; @@ -24,7 +26,7 @@ public interface KeyRequestResource { @GET @Path("{id}") @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_XML }) - public KeyRequestInfo getRequestInfo(@PathParam("id") String id); + public KeyRequestInfo getRequestInfo(@PathParam("id") RequestId id); // Archiving - used to test integration with a browser @POST @@ -54,14 +56,14 @@ public interface KeyRequestResource { @POST @Path("approve/{id}") - public void approveRequest(@PathParam("id") String id); + public void approveRequest(@PathParam("id") RequestId id); @POST @Path("reject/{id}") - public void rejectRequest(@PathParam("id") String id); + public void rejectRequest(@PathParam("id") RequestId id); @POST @Path("cancel/{id}") - public void cancelRequest(@PathParam("id") String id); + public void cancelRequest(@PathParam("id") RequestId id); } diff --git a/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestResourceService.java b/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestResourceService.java index e18407727..43e58bbdc 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestResourceService.java +++ b/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestResourceService.java @@ -18,13 +18,13 @@ package com.netscape.cms.servlet.request; -import javax.ws.rs.PathParam; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Context; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; import com.netscape.certsrv.base.EBaseException; +import com.netscape.certsrv.request.RequestId; import com.netscape.cms.servlet.base.CMSResourceService; import com.netscape.cms.servlet.request.model.ArchivalRequestData; import com.netscape.cms.servlet.request.model.KeyRequestDAO; @@ -43,7 +43,7 @@ public class KeyRequestResourceService extends CMSResourceService implements Key /** * Used to retrieve key request info for a specific request */ - public KeyRequestInfo getRequestInfo(String id) { + public KeyRequestInfo getRequestInfo(RequestId id) { // auth and authz KeyRequestDAO dao = new KeyRequestDAO(); KeyRequestInfo info; @@ -118,8 +118,8 @@ public class KeyRequestResourceService extends CMSResourceService implements Key return info; } - public void approveRequest(@PathParam("id") String id) { - if ( id == null) { + public void approveRequest(RequestId id) { + if (id == null) { throw new WebApplicationException(Response.Status.BAD_REQUEST); } // auth and authz @@ -133,8 +133,8 @@ public class KeyRequestResourceService extends CMSResourceService implements Key } } - public void rejectRequest(@PathParam("id") String id) { - if ( id == null) { + public void rejectRequest(RequestId id) { + if (id == null) { throw new WebApplicationException(Response.Status.BAD_REQUEST); } // auth and authz @@ -148,8 +148,8 @@ public class KeyRequestResourceService extends CMSResourceService implements Key } } - public void cancelRequest(@PathParam("id") String id) { - if ( id == null) { + public void cancelRequest(RequestId id) { + if (id == null) { throw new WebApplicationException(Response.Status.BAD_REQUEST); } // auth and authz diff --git a/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestsResource.java b/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestsResource.java index 0f8fbc78f..fd6bc4c27 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestsResource.java +++ b/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestsResource.java @@ -6,15 +6,17 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; + +import com.netscape.certsrv.request.RequestId; import com.netscape.cms.servlet.request.model.KeyRequestInfos; @Path("/keyrequests") public interface KeyRequestsResource { - public static final String DEFAULT_START = "0"; - public static final String DEFAULT_PAGESIZE = "20"; - public static final String DEFAULT_MAXRESULTS = "100"; - public static final String DEFAULT_MAXTIME = "10"; + public static final int DEFAULT_START = 0; + public static final int DEFAULT_PAGESIZE = 20; + public static final int DEFAULT_MAXRESULTS = 100; + public static final int DEFAULT_MAXTIME = 10; /** * Used to generate list of key requests based on the search parameters @@ -24,9 +26,9 @@ public interface KeyRequestsResource { public KeyRequestInfos listRequests(@QueryParam("requestState") String requestState, @QueryParam("requestType") String requestType, @QueryParam("clientID") String clientID, - @DefaultValue(DEFAULT_START) @QueryParam("start") String start_s, - @DefaultValue(DEFAULT_PAGESIZE) @QueryParam("pageSize") int pageSize, - @DefaultValue(DEFAULT_MAXRESULTS) @QueryParam("maxResults") int maxResults, - @DefaultValue(DEFAULT_MAXTIME) @QueryParam("maxTime") int maxTime); + @DefaultValue(""+DEFAULT_START) @QueryParam("start") RequestId start, + @DefaultValue(""+DEFAULT_PAGESIZE) @QueryParam("pageSize") int pageSize, + @DefaultValue(""+DEFAULT_MAXRESULTS) @QueryParam("maxResults") int maxResults, + @DefaultValue(""+DEFAULT_MAXTIME) @QueryParam("maxTime") int maxTime); } diff --git a/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestsResourceService.java b/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestsResourceService.java index 290868ab5..9b11a96d6 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestsResourceService.java +++ b/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestsResourceService.java @@ -25,10 +25,11 @@ import javax.ws.rs.core.UriInfo; import com.netscape.certsrv.apps.CMS; import com.netscape.certsrv.base.EBaseException; +import com.netscape.certsrv.request.RequestId; import com.netscape.cms.servlet.base.CMSResourceService; import com.netscape.cms.servlet.request.model.KeyRequestDAO; import com.netscape.cms.servlet.request.model.KeyRequestInfos; - + /** * @author alee * @@ -42,28 +43,16 @@ public class KeyRequestsResourceService extends CMSResourceService implements Ke * Used to generate list of key requests based on the search parameters */ public KeyRequestInfos listRequests(String requestState, String requestType, String clientID, - String start_s, int pageSize, int maxResults, - int maxTime) { + RequestId start, int pageSize, int maxResults, int maxTime) { // auth and authz // get ldap filter String filter = createSearchFilter(requestState, requestType, clientID); CMS.debug("listRequests: filter is " + filter); - // get start marker - int start = Integer.parseInt(KeyRequestsResource.DEFAULT_START); - if (start_s != null) { - try { - if (start_s.trim().startsWith("0x")) { - start = Integer.parseInt(start_s.trim().substring(2), 16); - } else { - start = Integer.parseInt(start_s.trim()); - } - } catch (NumberFormatException e) { - CMS.debug("listRequests: NumberformatException: Invalid value for start " + start_s); - throw new WebApplicationException(Response.Status.NOT_FOUND); - } + if (start == null) { + start = new RequestId(KeyRequestsResource.DEFAULT_START); } KeyRequestDAO reqDAO = new KeyRequestDAO(); diff --git a/pki/base/common/src/com/netscape/cms/servlet/request/ProcessCertReq.java b/pki/base/common/src/com/netscape/cms/servlet/request/ProcessCertReq.java index 68328a73c..ee5581a6d 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/request/ProcessCertReq.java +++ b/pki/base/common/src/com/netscape/cms/servlet/request/ProcessCertReq.java @@ -314,7 +314,7 @@ public class ProcessCertReq extends CMSServlet { IRequest r = null; if (seqNum.compareTo(BigInteger.ONE.negate()) > 0) { - r = mQueue.findRequest(new RequestId(seqNum.toString())); + r = mQueue.findRequest(new RequestId(seqNum)); } if (seqNum.compareTo(BigInteger.ONE.negate()) > 0 && r != null) { @@ -424,7 +424,7 @@ public class ProcessCertReq extends CMSServlet { } try { - IRequest r = mQueue.findRequest(new RequestId(seqNum.toString())); + IRequest r = mQueue.findRequest(new RequestId(seqNum)); if (r != null) { // overwrite "auditRequesterID" if and only if "id" != null diff --git a/pki/base/common/src/com/netscape/cms/servlet/request/ProcessReq.java b/pki/base/common/src/com/netscape/cms/servlet/request/ProcessReq.java index 93457a281..a4eb68b19 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/request/ProcessReq.java +++ b/pki/base/common/src/com/netscape/cms/servlet/request/ProcessReq.java @@ -245,7 +245,7 @@ public class ProcessReq extends CMSServlet { header.addBigIntegerValue("seqNum", seqNum, 10); - IRequest r = mQueue.findRequest(new RequestId(seqNum.toString())); + IRequest r = mQueue.findRequest(new RequestId(seqNum)); if (r != null) { if (doAssign != null) { diff --git a/pki/base/common/src/com/netscape/cms/servlet/request/QueryReq.java b/pki/base/common/src/com/netscape/cms/servlet/request/QueryReq.java index e580cc9a4..181f9f906 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/request/QueryReq.java +++ b/pki/base/common/src/com/netscape/cms/servlet/request/QueryReq.java @@ -414,7 +414,7 @@ public class QueryReq extends CMSServlet { jumptoend = true; // override to '99' during search } - RequestId id = new RequestId(marker.toString()); + RequestId id = new RequestId(marker); IRequestVirtualList list = mQueue.getPagedRequestsByFilter( id, jumptoend, diff --git a/pki/base/common/src/com/netscape/cms/servlet/request/model/KeyRequestDAO.java b/pki/base/common/src/com/netscape/cms/servlet/request/model/KeyRequestDAO.java index 4da4af6d5..d1f1a27bd 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/request/model/KeyRequestDAO.java +++ b/pki/base/common/src/com/netscape/cms/servlet/request/model/KeyRequestDAO.java @@ -29,6 +29,7 @@ import javax.ws.rs.core.UriInfo; import com.netscape.certsrv.apps.CMS; import com.netscape.certsrv.base.EBaseException; +import com.netscape.certsrv.dbs.keydb.KeyId; import com.netscape.certsrv.kra.IKeyRecoveryAuthority; import com.netscape.certsrv.request.IRequest; import com.netscape.certsrv.request.IRequestList; @@ -89,7 +90,7 @@ public class KeyRequestDAO { * @return collection of key request info * @throws EBaseException */ - public KeyRequestInfos listRequests(String filter, int start, int pageSize, int maxResults, int maxTime, + public KeyRequestInfos listRequests(String filter, RequestId start, int pageSize, int maxResults, int maxTime, UriInfo uriInfo) throws EBaseException { List <KeyRequestInfo> list = new ArrayList<KeyRequestInfo>(); List <Link> links = new ArrayList<Link>(); @@ -97,8 +98,7 @@ public class KeyRequestDAO { int current = 0; if (isVLVSearch(filter)) { - RequestId id = new RequestId(Integer.toString(start)); - IRequestVirtualList vlvlist = queue.getPagedRequestsByFilter(id, false, filter, + IRequestVirtualList vlvlist = queue.getPagedRequestsByFilter(start, false, filter, pageSize +1 , "requestId"); totalSize = vlvlist.getSize(); current = vlvlist.getCurrentIndex(); @@ -120,7 +120,7 @@ public class KeyRequestDAO { return null; } while (requests.hasMoreElements()) { - RequestId rid = (RequestId) requests.nextElement(); + RequestId rid = requests.nextElement(); IRequest request = queue.findRequest(rid); if (request != null) { list.add(createKeyRequestInfo(request, uriInfo)); @@ -168,8 +168,8 @@ public class KeyRequestDAO { * @return info for specific request * @throws EBaseException */ - public KeyRequestInfo getRequest(String id, UriInfo uriInfo) throws EBaseException { - IRequest request = queue.findRequest(new RequestId(id)); + public KeyRequestInfo getRequest(RequestId id, UriInfo uriInfo) throws EBaseException { + IRequest request = queue.findRequest(id); if (request == null) { return null; } @@ -189,7 +189,7 @@ public class KeyRequestDAO { boolean keyExists = doesKeyExist(clientId, "active", uriInfo); - if(keyExists == true) { + if (keyExists == true) { throw new EBaseException("Can not archive already active existing key!"); } @@ -221,7 +221,7 @@ public class KeyRequestDAO { IRequest request = queue.newRequest(IRequest.SECURITY_DATA_RECOVERY_REQUEST); - String keyId = data.getKeyId(); + KeyId keyId = data.getKeyId(); Hashtable<String, Object> requestParams; requestParams = kra.createVolatileRequest(request.getRequestId()); @@ -244,27 +244,27 @@ public class KeyRequestDAO { requestParams.put(IRequest.SECURITY_DATA_IV_STRING_IN, nonceDataStr); } - request.setExtData(ATTR_SERIALNO,keyId); + request.setExtData(ATTR_SERIALNO, keyId.toString()); queue.processRequest(request); return createKeyRequestInfo(request, uriInfo); } - public void approveRequest(String id) throws EBaseException { - IRequest request = queue.findRequest(new RequestId(id)); + public void approveRequest(RequestId id) throws EBaseException { + IRequest request = queue.findRequest(id); request.setRequestStatus(RequestStatus.APPROVED); queue.updateRequest(request); } - public void rejectRequest(String id) throws EBaseException { - IRequest request = queue.findRequest(new RequestId(id)); + public void rejectRequest(RequestId id) throws EBaseException { + IRequest request = queue.findRequest(id); request.setRequestStatus(RequestStatus.CANCELED); queue.updateRequest(request); } - public void cancelRequest(String id) throws EBaseException { - IRequest request = queue.findRequest(new RequestId(id)); + public void cancelRequest(RequestId id) throws EBaseException { + IRequest request = queue.findRequest(id); request.setRequestStatus(RequestStatus.REJECTED); queue.updateRequest(request); } @@ -276,7 +276,7 @@ public class KeyRequestDAO { ret.setRequestStatus(request.getRequestStatus().toString()); Path keyRequestPath = KeyRequestResource.class.getAnnotation(Path.class); - String rid = request.getRequestId().toString(); + RequestId rid = request.getRequestId(); UriBuilder reqBuilder = uriInfo.getBaseUriBuilder(); reqBuilder.path(keyRequestPath.value() + "/" + rid); diff --git a/pki/base/common/src/com/netscape/cms/servlet/request/model/KeyRequestInfo.java b/pki/base/common/src/com/netscape/cms/servlet/request/model/KeyRequestInfo.java index d768e2ba9..f07c302dd 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/request/model/KeyRequestInfo.java +++ b/pki/base/common/src/com/netscape/cms/servlet/request/model/KeyRequestInfo.java @@ -23,6 +23,9 @@ import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; +import com.netscape.certsrv.dbs.keydb.KeyId; +import com.netscape.certsrv.request.RequestId; + @XmlRootElement(name="SecurityDataRequestInfo") @XmlAccessorType(XmlAccessType.FIELD) public class KeyRequestInfo { @@ -79,6 +82,14 @@ public class KeyRequestInfo { } /** + * @return the request ID in the requestURL + */ + public RequestId getRequestId() { + String id = requestURL.substring(requestURL.lastIndexOf("/") + 1); + return new RequestId(id); + } + + /** * @param requestURL the requestURL to set */ public void setRequestURL(String requestURL) { @@ -93,6 +104,14 @@ public class KeyRequestInfo { } /** + * @return the key ID in the keyURL + */ + public KeyId getKeyId() { + String id = keyURL.substring(keyURL.lastIndexOf("/") + 1); + return new KeyId(id); + } + + /** * @param keyURL the keyURL to set */ public void setKeyURL(String keyURL) { diff --git a/pki/base/common/src/com/netscape/cms/servlet/request/model/RecoveryRequestData.java b/pki/base/common/src/com/netscape/cms/servlet/request/model/RecoveryRequestData.java index ae8417542..80ec6d127 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/request/model/RecoveryRequestData.java +++ b/pki/base/common/src/com/netscape/cms/servlet/request/model/RecoveryRequestData.java @@ -26,6 +26,12 @@ import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; + +import com.netscape.certsrv.dbs.keydb.KeyId; +import com.netscape.certsrv.dbs.keydb.KeyIdAdapter; +import com.netscape.certsrv.request.RequestId; +import com.netscape.certsrv.request.RequestIdAdapter; /** * @author alee @@ -42,10 +48,12 @@ public class RecoveryRequestData { private static final String NONCE_DATA = "nonceData"; @XmlElement - protected String keyId; + @XmlJavaTypeAdapter(KeyIdAdapter.class) + protected KeyId keyId; @XmlElement - protected String requestId; + @XmlJavaTypeAdapter(RequestIdAdapter.class) + protected RequestId requestId; @XmlElement protected String transWrappedSessionKey; @@ -61,8 +69,12 @@ public class RecoveryRequestData { } public RecoveryRequestData(MultivaluedMap<String, String> form) { - keyId = form.getFirst(KEY_ID); - requestId = form.getFirst(REQUEST_ID); + if (form.containsKey(KEY_ID)) { + keyId = new KeyId(form.getFirst(KEY_ID)); + } + if (form.containsKey(REQUEST_ID)) { + requestId = new RequestId(form.getFirst(REQUEST_ID)); + } transWrappedSessionKey = form.getFirst(TRANS_WRAPPED_SESSION_KEY); sessionWrappedPassphrase = form.getFirst(SESSION_WRAPPED_PASSPHRASE); nonceData = form.getFirst(NONCE_DATA); @@ -71,28 +83,28 @@ public class RecoveryRequestData { /** * @return the keyId */ - public String getKeyId() { + public KeyId getKeyId() { return keyId; } /** * @param keyId the keyId to set */ - public void setKeyId(String keyId) { + public void setKeyId(KeyId keyId) { this.keyId = keyId; } /** * @return the requestId */ - public String getRequestId() { + public RequestId getRequestId() { return requestId; } /** * @param requestId the requestId to set */ - public void setRequestId(String requestId) { + public void setRequestId(RequestId requestId) { this.requestId = requestId; } diff --git a/pki/base/common/src/com/netscape/cmscore/cert/PrettyPrintFormat.java b/pki/base/common/src/com/netscape/cmscore/cert/PrettyPrintFormat.java index fb97a5ccb..669200575 100644 --- a/pki/base/common/src/com/netscape/cmscore/cert/PrettyPrintFormat.java +++ b/pki/base/common/src/com/netscape/cmscore/cert/PrettyPrintFormat.java @@ -104,6 +104,9 @@ public class PrettyPrintFormat implements IPrettyPrintFormat { public String toHexString(byte[] in, int indentSize, int lineLen, String separator) { + + if (in == null) return ""; + StringBuffer sb = new StringBuffer(); int hexCount = 0; char c[]; diff --git a/pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java b/pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java index b23e6fff4..ef13d3c29 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java +++ b/pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java @@ -52,7 +52,7 @@ public class RequestQueue // get the next request Id BigInteger next = mRepository.getNextSerialNumber(); - RequestId rid = new RequestId(next.toString()); + RequestId rid = new RequestId(next); return rid; } @@ -241,7 +241,7 @@ public class RequestQueue String filter = "(" + "requeststate" + "=*" + ")"; - RequestId fromId = new RequestId(reqId_upper_bound.toString(10)); + RequestId fromId = new RequestId(reqId_upper_bound); CMS.debug("RequestQueue: getLastRequestId: filter " + filter + " fromId " + fromId); ListEnumeration recList = (ListEnumeration) getPagedRequestsByFilter(fromId, filter, 5 * -1, "requestId"); |