summaryrefslogtreecommitdiffstats
path: root/base/common/src/com/netscape/certsrv/key
diff options
context:
space:
mode:
authorEndi Sukma Dewata <edewata@redhat.com>2012-10-25 11:52:15 -0500
committerEndi Sukma Dewata <edewata@redhat.com>2012-10-29 10:38:38 -0500
commitc1aa8b2d05cb1873990d1a3e9cf007cca240f135 (patch)
treef12c76eaa1c385a79e40e7b38123360279c05fc0 /base/common/src/com/netscape/certsrv/key
parent748605a324266bb515a3d1124bc55deb3be4df71 (diff)
downloadpki-c1aa8b2d05cb1873990d1a3e9cf007cca240f135.tar.gz
pki-c1aa8b2d05cb1873990d1a3e9cf007cca240f135.tar.xz
pki-c1aa8b2d05cb1873990d1a3e9cf007cca240f135.zip
Enabled authentication for key services.
The web.xml in KRA has been modified to enable the authentication for key and key request services. Some tools have been added to access the services via command-line. Ticket #376
Diffstat (limited to 'base/common/src/com/netscape/certsrv/key')
-rw-r--r--base/common/src/com/netscape/certsrv/key/KeyClient.java75
-rw-r--r--base/common/src/com/netscape/certsrv/key/KeyDataInfo.java43
-rw-r--r--base/common/src/com/netscape/certsrv/key/KeyDataInfos.java15
-rw-r--r--base/common/src/com/netscape/certsrv/key/KeyRequestInfo.java69
-rw-r--r--base/common/src/com/netscape/certsrv/key/KeyRequestInfos.java120
-rw-r--r--base/common/src/com/netscape/certsrv/key/KeyRequestResource.java14
-rw-r--r--base/common/src/com/netscape/certsrv/key/KeyResource.java8
7 files changed, 314 insertions, 30 deletions
diff --git a/base/common/src/com/netscape/certsrv/key/KeyClient.java b/base/common/src/com/netscape/certsrv/key/KeyClient.java
new file mode 100644
index 000000000..ce2946c1e
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/key/KeyClient.java
@@ -0,0 +1,75 @@
+//--- 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) 2012 Red Hat, Inc.
+//All rights reserved.
+//--- END COPYRIGHT BLOCK ---
+package com.netscape.certsrv.key;
+
+import java.net.URISyntaxException;
+
+import com.netscape.certsrv.client.ClientConfig;
+import com.netscape.certsrv.client.PKIClient;
+import com.netscape.certsrv.client.PKIConnection;
+import com.netscape.certsrv.request.RequestId;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class KeyClient extends PKIClient {
+
+ public KeyResource keyClient;
+ public KeyRequestResource keyRequestClient;
+
+ public KeyClient(PKIConnection connection) throws URISyntaxException {
+ super(connection);
+ init();
+ }
+
+ public KeyClient(ClientConfig config) throws URISyntaxException {
+ super(config);
+ init();
+ }
+
+ public void init() throws URISyntaxException {
+ keyClient = createProxy(KeyResource.class);
+ keyRequestClient = createProxy(KeyRequestResource.class);
+ }
+
+ public KeyDataInfos findKeys(String clientID, String status, Integer maxSize, Integer maxTime) {
+ return keyClient.listKeys(clientID, status, maxSize, maxTime);
+ }
+
+ public KeyData retrieveKey(KeyRecoveryRequest data) {
+ return keyClient.retrieveKey(data);
+ }
+
+ public KeyRequestInfos findKeyRequests(
+ String requestState,
+ String requestType,
+ String clientID,
+ RequestId start,
+ Integer pageSize,
+ Integer maxResults,
+ Integer maxTime) {
+ return keyRequestClient.listRequests(
+ requestState,
+ requestType,
+ clientID,
+ start,
+ pageSize,
+ maxResults,
+ maxTime);
+ }
+}
diff --git a/base/common/src/com/netscape/certsrv/key/KeyDataInfo.java b/base/common/src/com/netscape/certsrv/key/KeyDataInfo.java
index 3af348ef3..09d228718 100644
--- a/base/common/src/com/netscape/certsrv/key/KeyDataInfo.java
+++ b/base/common/src/com/netscape/certsrv/key/KeyDataInfo.java
@@ -42,6 +42,18 @@ public class KeyDataInfo {
@XmlElement
protected String clientID;
+ @XmlElement
+ protected String status;
+
+ @XmlElement
+ protected String algorithm;
+
+ @XmlElement
+ protected Integer size;
+
+ @XmlElement
+ protected String ownerName;
+
public KeyDataInfo() {
// required for JAXB (defaults)
}
@@ -82,4 +94,35 @@ public class KeyDataInfo {
this.clientID = clientID;
}
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public String getAlgorithm() {
+ return algorithm;
+ }
+
+ public void setAlgorithm(String algorithm) {
+ this.algorithm = algorithm;
+ }
+
+ public Integer getSize() {
+ return size;
+ }
+
+ public void setSize(Integer size) {
+ this.size = size;
+ }
+
+ public String getOwnerName() {
+ return ownerName;
+ }
+
+ public void setOwnerName(String ownerName) {
+ this.ownerName = ownerName;
+ }
}
diff --git a/base/common/src/com/netscape/certsrv/key/KeyDataInfos.java b/base/common/src/com/netscape/certsrv/key/KeyDataInfos.java
index 4e82f27b5..d9fc885b4 100644
--- a/base/common/src/com/netscape/certsrv/key/KeyDataInfos.java
+++ b/base/common/src/com/netscape/certsrv/key/KeyDataInfos.java
@@ -17,6 +17,7 @@
// --- END COPYRIGHT BLOCK ---
package com.netscape.certsrv.key;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -29,8 +30,8 @@ import com.netscape.certsrv.base.Link;
@XmlRootElement(name = "KeyDataInfos")
public class KeyDataInfos {
- protected Collection<KeyDataInfo> keyInfos;
- protected List<Link> links;
+ protected Collection<KeyDataInfo> keyInfos = new ArrayList<KeyDataInfo>();
+ protected List<Link> links = new ArrayList<Link>();
/**
* @return the keyInfos
@@ -39,12 +40,21 @@ public class KeyDataInfos {
public Collection<KeyDataInfo> getKeyInfos() {
return keyInfos;
}
+
/**
* @param keyInfos the keyInfos to set
*/
public void setKeyInfos(Collection<KeyDataInfo> keyInfos) {
this.keyInfos = keyInfos;
}
+
+ /**
+ * @param keyInfo the keyInfo to add
+ */
+ public void addKeyInfo(KeyDataInfo keyInfo) {
+ keyInfos.add(keyInfo);
+ }
+
/**
* @return the links
*/
@@ -52,6 +62,7 @@ public class KeyDataInfos {
public List<Link> getLinks() {
return links;
}
+
/**
* @param links the links to set
*/
diff --git a/base/common/src/com/netscape/certsrv/key/KeyRequestInfo.java b/base/common/src/com/netscape/certsrv/key/KeyRequestInfo.java
index f18e60e64..d9e5fbf1c 100644
--- a/base/common/src/com/netscape/certsrv/key/KeyRequestInfo.java
+++ b/base/common/src/com/netscape/certsrv/key/KeyRequestInfo.java
@@ -18,6 +18,12 @@
package com.netscape.certsrv.key;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
@@ -25,6 +31,7 @@ import javax.xml.bind.annotation.XmlRootElement;
import com.netscape.certsrv.dbs.keydb.KeyId;
import com.netscape.certsrv.request.CMSRequestInfo;
+import com.netscape.certsrv.request.RequestStatus;
@XmlRootElement(name = "KeyRequestInfo")
@XmlAccessorType(XmlAccessType.FIELD)
@@ -58,4 +65,66 @@ public class KeyRequestInfo extends CMSRequestInfo {
public void setKeyURL(String keyURL) {
this.keyURL = keyURL;
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ((keyURL == null) ? 0 : keyURL.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ KeyRequestInfo other = (KeyRequestInfo) obj;
+ if (keyURL == null) {
+ if (other.keyURL != null)
+ return false;
+ } else if (!keyURL.equals(other.keyURL))
+ return false;
+ return true;
+ }
+
+ public String toString() {
+ try {
+ StringWriter sw = new StringWriter();
+ Marshaller marshaller = JAXBContext.newInstance(KeyRequestInfo.class).createMarshaller();
+ marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+ marshaller.marshal(this, sw);
+ return sw.toString();
+
+ } catch (Exception e) {
+ return super.toString();
+ }
+ }
+
+ public static KeyRequestInfo valueOf(String string) throws Exception {
+ try {
+ Unmarshaller unmarshaller = JAXBContext.newInstance(KeyRequestInfo.class).createUnmarshaller();
+ return (KeyRequestInfo)unmarshaller.unmarshal(new StringReader(string));
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ public static void main(String args[]) throws Exception {
+
+ KeyRequestInfo before = new KeyRequestInfo();
+ before.setRequestType("securityDataEnrollment");
+ before.setRequestStatus(RequestStatus.COMPLETE);
+
+ String string = before.toString();
+ System.out.println(string);
+
+ KeyRequestInfo after = KeyRequestInfo.valueOf(string);
+ System.out.println(after);
+
+ System.out.println(before.equals(after));
+ }
}
diff --git a/base/common/src/com/netscape/certsrv/key/KeyRequestInfos.java b/base/common/src/com/netscape/certsrv/key/KeyRequestInfos.java
index 1fbd363d3..90756f8d3 100644
--- a/base/common/src/com/netscape/certsrv/key/KeyRequestInfos.java
+++ b/base/common/src/com/netscape/certsrv/key/KeyRequestInfos.java
@@ -17,24 +17,38 @@
// --- END COPYRIGHT BLOCK ---
package com.netscape.certsrv.key;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import com.netscape.certsrv.base.Link;
+import com.netscape.certsrv.request.RequestStatus;
@XmlRootElement(name = "KeyRequestInfos")
+@XmlAccessorType(XmlAccessType.FIELD)
public class KeyRequestInfos {
- protected Collection<KeyRequestInfo> requests;
- protected List<Link> links;
+
+ @XmlElementRef
+ protected Collection<KeyRequestInfo> requests = new ArrayList<KeyRequestInfo>();
+
+ @XmlElement(name = "Link")
+ protected List<Link> links = new ArrayList<Link>();
/**
* @return the requests
*/
- @XmlElementRef
public Collection<KeyRequestInfo> getRequests() {
return requests;
}
@@ -43,13 +57,21 @@ public class KeyRequestInfos {
* @param requests the requests to set
*/
public void setRequests(Collection<KeyRequestInfo> requests) {
- this.requests = requests;
+ this.requests.clear();
+ if (requests == null) return;
+ this.requests.addAll(requests);
+ }
+
+ /**
+ * @param request the request to add
+ */
+ public void addRequest(KeyRequestInfo request) {
+ requests.add(request);
}
/**
* @return the links
*/
- @XmlElementRef
public List<Link> getLinks() {
return links;
}
@@ -58,14 +80,20 @@ public class KeyRequestInfos {
* @param links the links to set
*/
public void setLinks(List<Link> links) {
- this.links = links;
+ this.links.clear();
+ if (links == null) return;
+ this.links.addAll(links);
+ }
+
+ /**
+ * @param links the link to add
+ */
+ public void addLink(Link link) {
+ this.links.add(link);
}
@XmlTransient
public String getNext() {
- if (links == null) {
- return null;
- }
for (Link link : links) {
if ("next".equals(link.getRelationship())) {
return link.getHref();
@@ -76,9 +104,6 @@ public class KeyRequestInfos {
@XmlTransient
public String getPrevious() {
- if (links == null) {
- return null;
- }
for (Link link : links) {
if ("previous".equals(link.getRelationship())) {
return link.getHref();
@@ -86,4 +111,75 @@ public class KeyRequestInfos {
}
return null;
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((links == null) ? 0 : links.hashCode());
+ result = prime * result + ((requests == null) ? 0 : requests.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;
+ KeyRequestInfos other = (KeyRequestInfos) obj;
+ if (links == null) {
+ if (other.links != null)
+ return false;
+ } else if (!links.equals(other.links))
+ return false;
+ if (requests == null) {
+ if (other.requests != null)
+ return false;
+ } else if (!requests.equals(other.requests))
+ return false;
+ return true;
+ }
+
+ public String toString() {
+ try {
+ StringWriter sw = new StringWriter();
+ Marshaller marshaller = JAXBContext.newInstance(KeyRequestInfos.class).createMarshaller();
+ marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+ marshaller.marshal(this, sw);
+ return sw.toString();
+
+ } catch (Exception e) {
+ return super.toString();
+ }
+ }
+
+ public static KeyRequestInfos valueOf(String string) throws Exception {
+ try {
+ Unmarshaller unmarshaller = JAXBContext.newInstance(KeyRequestInfos.class).createUnmarshaller();
+ return (KeyRequestInfos)unmarshaller.unmarshal(new StringReader(string));
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ public static void main(String args[]) throws Exception {
+
+ KeyRequestInfos before = new KeyRequestInfos();
+
+ KeyRequestInfo request = new KeyRequestInfo();
+ request.setRequestType("securityDataEnrollment");
+ request.setRequestStatus(RequestStatus.COMPLETE);
+ before.addRequest(request);
+
+ String string = before.toString();
+ System.out.println(string);
+
+ KeyRequestInfos after = KeyRequestInfos.valueOf(string);
+ System.out.println(after);
+
+ System.out.println(before.equals(after));
+ }
}
diff --git a/base/common/src/com/netscape/certsrv/key/KeyRequestResource.java b/base/common/src/com/netscape/certsrv/key/KeyRequestResource.java
index 7fecd0610..356fd1569 100644
--- a/base/common/src/com/netscape/certsrv/key/KeyRequestResource.java
+++ b/base/common/src/com/netscape/certsrv/key/KeyRequestResource.java
@@ -1,7 +1,6 @@
package com.netscape.certsrv.key;
import javax.ws.rs.Consumes;
-import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
@@ -20,11 +19,6 @@ public interface KeyRequestResource {
public final String PASS_PHRASE_TYPE = "passPhrase";
public final String ASYMMETRIC_KEY_TYPE = "asymmetricKey";
- 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
*/
@@ -33,10 +27,10 @@ public interface KeyRequestResource {
public KeyRequestInfos listRequests(@QueryParam("requestState") String requestState,
@QueryParam("requestType") String requestType,
@QueryParam("clientID") String clientID,
- @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);
+ @QueryParam("start") RequestId start,
+ @QueryParam("pageSize") Integer pageSize,
+ @QueryParam("maxResults") Integer maxResults,
+ @QueryParam("maxTime") Integer maxTime);
/**
diff --git a/base/common/src/com/netscape/certsrv/key/KeyResource.java b/base/common/src/com/netscape/certsrv/key/KeyResource.java
index a499ca11f..50fe82cc3 100644
--- a/base/common/src/com/netscape/certsrv/key/KeyResource.java
+++ b/base/common/src/com/netscape/certsrv/key/KeyResource.java
@@ -1,7 +1,6 @@
package com.netscape.certsrv.key;
import javax.ws.rs.Consumes;
-import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
@@ -14,15 +13,12 @@ import javax.ws.rs.core.MultivaluedMap;
@Path("agent/keys")
public interface KeyResource {
- public static final int DEFAULT_MAXTIME = 10;
- public static final int DEFAULT_MAXRESULTS = 100;
-
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
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);
+ @QueryParam("maxResults") Integer maxResults,
+ @QueryParam("maxTime") Integer maxTime);
/**