summaryrefslogtreecommitdiffstats
path: root/base/common/src/com/netscape/certsrv/key
diff options
context:
space:
mode:
authorAde Lee <alee@redhat.com>2014-01-25 00:49:41 -0500
committerAde Lee <alee@redhat.com>2014-02-04 13:36:03 -0500
commit5a9a7d9c1e3cedffe828bb004e7038de55c8e47f (patch)
tree9edf056dfc8cd32570e5d12be858ac75f7d7b0c1 /base/common/src/com/netscape/certsrv/key
parent12eef29a23c4cccc09d1e51a60766f87a782cf46 (diff)
downloadpki-5a9a7d9c1e3cedffe828bb004e7038de55c8e47f.tar.gz
pki-5a9a7d9c1e3cedffe828bb004e7038de55c8e47f.tar.xz
pki-5a9a7d9c1e3cedffe828bb004e7038de55c8e47f.zip
Add new POST endpoint for creating requests
Diffstat (limited to 'base/common/src/com/netscape/certsrv/key')
-rw-r--r--base/common/src/com/netscape/certsrv/key/KeyArchivalRequest.java6
-rw-r--r--base/common/src/com/netscape/certsrv/key/KeyRecoveryRequest.java6
-rw-r--r--base/common/src/com/netscape/certsrv/key/KeyRequest.java (renamed from base/common/src/com/netscape/certsrv/key/Request.java)15
-rw-r--r--base/common/src/com/netscape/certsrv/key/KeyRequestResource.java12
-rw-r--r--base/common/src/com/netscape/certsrv/key/SymKeyGenerationRequest.java86
5 files changed, 117 insertions, 8 deletions
diff --git a/base/common/src/com/netscape/certsrv/key/KeyArchivalRequest.java b/base/common/src/com/netscape/certsrv/key/KeyArchivalRequest.java
index 9343d0afe..9a8d29131 100644
--- a/base/common/src/com/netscape/certsrv/key/KeyArchivalRequest.java
+++ b/base/common/src/com/netscape/certsrv/key/KeyArchivalRequest.java
@@ -32,7 +32,7 @@ import javax.xml.bind.annotation.XmlRootElement;
*/
@XmlRootElement(name="KeyArchivalRequest")
@XmlAccessorType(XmlAccessType.FIELD)
-public class KeyArchivalRequest extends Request {
+public class KeyArchivalRequest extends KeyRequest {
private static final String CLIENT_ID = "clientID";
private static final String DATA_TYPE = "dataType";
@@ -92,7 +92,7 @@ public class KeyArchivalRequest extends Request {
public String toString() {
try {
- return Request.marshal(this, KeyArchivalRequest.class);
+ return KeyRequest.marshal(this, KeyArchivalRequest.class);
} catch (Exception e) {
return super.toString();
}
@@ -100,7 +100,7 @@ public class KeyArchivalRequest extends Request {
public static KeyArchivalRequest valueOf(String string) throws Exception {
try {
- return Request.unmarshal(string, KeyArchivalRequest.class);
+ return KeyRequest.unmarshal(string, KeyArchivalRequest.class);
} catch (Exception e) {
return null;
}
diff --git a/base/common/src/com/netscape/certsrv/key/KeyRecoveryRequest.java b/base/common/src/com/netscape/certsrv/key/KeyRecoveryRequest.java
index f2d259bf8..74f4bcd44 100644
--- a/base/common/src/com/netscape/certsrv/key/KeyRecoveryRequest.java
+++ b/base/common/src/com/netscape/certsrv/key/KeyRecoveryRequest.java
@@ -35,7 +35,7 @@ import com.netscape.certsrv.request.RequestId;
*/
@XmlRootElement(name="KeyRecoveryRequest")
@XmlAccessorType(XmlAccessType.FIELD)
-public class KeyRecoveryRequest extends Request {
+public class KeyRecoveryRequest extends KeyRequest {
private static final String KEY_ID = "keyId";
private static final String REQUEST_ID = "requestId";
@@ -167,7 +167,7 @@ public class KeyRecoveryRequest extends Request {
public static KeyRecoveryRequest valueOf(String string) throws Exception {
try {
- return Request.unmarshal(string, KeyRecoveryRequest.class);
+ return KeyRequest.unmarshal(string, KeyRecoveryRequest.class);
} catch (Exception e) {
return null;
}
@@ -175,7 +175,7 @@ public class KeyRecoveryRequest extends Request {
public String toString() {
try {
- return Request.marshal(this, KeyRecoveryRequest.class);
+ return KeyRequest.marshal(this, KeyRecoveryRequest.class);
} catch (Exception e) {
return super.toString();
}
diff --git a/base/common/src/com/netscape/certsrv/key/Request.java b/base/common/src/com/netscape/certsrv/key/KeyRequest.java
index f65809b02..364136877 100644
--- a/base/common/src/com/netscape/certsrv/key/Request.java
+++ b/base/common/src/com/netscape/certsrv/key/KeyRequest.java
@@ -8,6 +8,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import javax.ws.rs.core.MultivaluedMap;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
@@ -23,12 +24,22 @@ import org.jboss.resteasy.plugins.providers.atom.Link;
/**
* @author Ade Lee
*/
-public class Request {
+public class KeyRequest {
Map<String, String> properties = new LinkedHashMap<String, String>();
Link link;
String requestType;
+ public KeyRequest() {
+ // required for jax-b
+ }
+
+ public KeyRequest(MultivaluedMap<String, String> form) {
+ for (Map.Entry<String, List<String>> entry: form.entrySet()) {
+ properties.put(entry.getKey(), entry.getValue().get(0));
+ }
+ }
+
@XmlElement(name = "RequestType")
public String getRequestType() {
return requestType;
@@ -128,7 +139,7 @@ public class Request {
return false;
if (getClass() != obj.getClass())
return false;
- Request other = (Request) obj;
+ KeyRequest other = (KeyRequest) obj;
if (link == null) {
if (other.link != null)
return false;
diff --git a/base/common/src/com/netscape/certsrv/key/KeyRequestResource.java b/base/common/src/com/netscape/certsrv/key/KeyRequestResource.java
index 5d576c05f..412908fc9 100644
--- a/base/common/src/com/netscape/certsrv/key/KeyRequestResource.java
+++ b/base/common/src/com/netscape/certsrv/key/KeyRequestResource.java
@@ -45,6 +45,18 @@ public interface KeyRequestResource {
@QueryParam("maxResults") Integer maxResults,
@QueryParam("maxTime") Integer maxTime);
+ // Archiving - used to test integration with a browser
+ @POST
+ @ClientResponseType(entityType=KeyRequestInfo.class)
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ @Consumes({ MediaType.APPLICATION_FORM_URLENCODED})
+ public Response createRequest(MultivaluedMap<String, String> form);
+
+ @POST
+ @ClientResponseType(entityType=KeyRequestInfo.class)
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response createRequest(KeyRequest data);
/**
* Used to retrieve key request info for a specific request
diff --git a/base/common/src/com/netscape/certsrv/key/SymKeyGenerationRequest.java b/base/common/src/com/netscape/certsrv/key/SymKeyGenerationRequest.java
new file mode 100644
index 000000000..1abaaab00
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/key/SymKeyGenerationRequest.java
@@ -0,0 +1,86 @@
+package com.netscape.certsrv.key;
+
+import javax.ws.rs.core.MultivaluedMap;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * @author alee
+ *
+ */
+@XmlRootElement(name="SymKeyGenerationRequest")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class SymKeyGenerationRequest extends KeyRequest {
+
+ private static final String CLIENT_ID = "clientID";
+ private static final String DATA_TYPE = "dataType";
+
+ public SymKeyGenerationRequest() {
+ // required for JAXB (defaults)
+ }
+
+ public SymKeyGenerationRequest(MultivaluedMap<String, String> form) {
+ this.properties.put(CLIENT_ID, form.getFirst(CLIENT_ID));
+ this.properties.put(DATA_TYPE, form.getFirst(DATA_TYPE));
+ }
+
+ /**
+ * @return the clientId
+ */
+ public String getClientId() {
+ return properties.get(CLIENT_ID);
+ }
+
+ /**
+ * @param clientId the clientId to set
+ */
+ public void setClientId(String clientId) {
+ this.properties.put(CLIENT_ID, clientId);
+ }
+
+ /**
+ * @return the dataType
+ */
+ public String getDataType() {
+ return this.properties.get(DATA_TYPE);
+ }
+
+ /**
+ * @param dataType the dataType to set
+ */
+ public void setDataType(String dataType) {
+ this.properties.put(DATA_TYPE, dataType);
+ }
+
+ public String toString() {
+ try {
+ return KeyRequest.marshal(this, SymKeyGenerationRequest.class);
+ } catch (Exception e) {
+ return super.toString();
+ }
+ }
+
+ public static SymKeyGenerationRequest valueOf(String string) throws Exception {
+ try {
+ return KeyRequest.unmarshal(string, SymKeyGenerationRequest.class);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ public static void main(String args[]) throws Exception {
+
+ SymKeyGenerationRequest before = new SymKeyGenerationRequest();
+ before.setClientId("vek 12345");
+ before.setDataType(KeyRequestResource.SYMMETRIC_KEY_TYPE);
+ before.setRequestType(KeyRequestResource.KEY_GENERATION_REQUEST);
+
+ String string = before.toString();
+ System.out.println(string);
+
+ SymKeyGenerationRequest after = SymKeyGenerationRequest.valueOf(string);
+ System.out.println(before.equals(after));
+ }
+
+}