summaryrefslogtreecommitdiffstats
path: root/base/common
diff options
context:
space:
mode:
authorAbhishek Koneru <akoneru@redhat.com>2012-07-16 17:42:27 -0400
committerEndi Sukma Dewata <edewata@redhat.com>2012-07-19 22:40:50 -0500
commitaa8a82d5d09ec621f2b100ccdd27ffdc6df541d0 (patch)
tree11ca95030db5d126c8b4b1473aaacde6e6ef5bf2 /base/common
parent5ff8f1cc33678ff6188ee39114439353cd3007bf (diff)
downloadpki-aa8a82d5d09ec621f2b100ccdd27ffdc6df541d0.tar.gz
pki-aa8a82d5d09ec621f2b100ccdd27ffdc6df541d0.tar.xz
pki-aa8a82d5d09ec621f2b100ccdd27ffdc6df541d0.zip
Changes for CertRequestSubmitCLI feature addition.
Allows the user to send a certificate request through cli. Command : pki cert-request-submit <filename>
Diffstat (limited to 'base/common')
-rw-r--r--base/common/src/com/netscape/cms/client/cert/CertCLI.java1
-rw-r--r--base/common/src/com/netscape/cms/client/cert/CertRequestSubmitCLI.java85
-rw-r--r--base/common/src/com/netscape/cms/client/cert/CertRestClient.java9
3 files changed, 95 insertions, 0 deletions
diff --git a/base/common/src/com/netscape/cms/client/cert/CertCLI.java b/base/common/src/com/netscape/cms/client/cert/CertCLI.java
index b0789ef6a..ff2383cd1 100644
--- a/base/common/src/com/netscape/cms/client/cert/CertCLI.java
+++ b/base/common/src/com/netscape/cms/client/cert/CertCLI.java
@@ -47,6 +47,7 @@ public class CertCLI extends CLI {
addModule(new CertRevokeCLI(this));
addModule(new CertHoldCLI(this));
addModule(new CertReleaseHoldCLI(this));
+ addModule(new CertRequestSubmitCLI(this));
}
public void printHelp() {
diff --git a/base/common/src/com/netscape/cms/client/cert/CertRequestSubmitCLI.java b/base/common/src/com/netscape/cms/client/cert/CertRequestSubmitCLI.java
new file mode 100644
index 000000000..e09f8be5b
--- /dev/null
+++ b/base/common/src/com/netscape/cms/client/cert/CertRequestSubmitCLI.java
@@ -0,0 +1,85 @@
+package com.netscape.cms.client.cert;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.util.Collection;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.ParseException;
+
+import com.netscape.cms.client.cli.CLI;
+import com.netscape.cms.client.cli.MainCLI;
+import com.netscape.cms.servlet.request.model.CertRequestInfo;
+import com.netscape.cms.servlet.request.model.CertRequestInfos;
+import com.netscape.cms.servlet.request.model.EnrollmentRequestData;
+
+public class CertRequestSubmitCLI extends CLI {
+
+ CertCLI parent;
+
+ public CertRequestSubmitCLI(CertCLI parent) {
+ super("request-submit", "Submit certificate request");
+ this.parent = parent;
+ }
+
+ @Override
+ public void execute(String[] args) {
+ CommandLine cmd = null;
+
+ try {
+ cmd = parser.parse(options, args);
+ } catch (ParseException e) {
+ System.err.println("Error: " + e.getMessage());
+ printHelp();
+ System.exit(-1);
+ }
+
+ String[] cLineArgs = cmd.getArgs();
+
+ if (cLineArgs.length < 1) {
+ System.err.println("Error: No filename specified.");
+ printHelp();
+ System.exit(-1);
+ }
+
+ EnrollmentRequestData erd = null;
+
+ try {
+ erd = getEnrollmentRequest(cLineArgs[0]);
+ CertRequestInfos cri = parent.client.enrollRequest(erd);
+ MainCLI.printMessage("Submitted certificate request");
+ printRequestInformation(cri);
+ } catch (FileNotFoundException e) {
+ System.err.println("Error: " + e.getMessage());
+ System.exit(-1);
+ } catch (JAXBException e) {
+ System.err.println("Error: " + e.getMessage());
+ System.exit(-1);
+ }
+ }
+
+ private EnrollmentRequestData getEnrollmentRequest(String fileName) throws JAXBException, FileNotFoundException {
+ EnrollmentRequestData erd = null;
+ JAXBContext context = JAXBContext.newInstance(EnrollmentRequestData.class);
+ Unmarshaller unmarshaller = context.createUnmarshaller();
+ FileInputStream fis = new FileInputStream(fileName);
+ erd = (EnrollmentRequestData) unmarshaller.unmarshal(fis);
+ return erd;
+ }
+
+ private void printRequestInformation(CertRequestInfos cri) {
+ Collection<CertRequestInfo> allRequests = cri.getRequests();
+ for (CertRequestInfo x : allRequests) {
+ CertCLI.printCertRequestInfo(x);
+ }
+ System.out.println();
+ }
+
+ public void printHelp() {
+ formatter.printHelp(parent.name + "-" + name + " <filename>", options);
+ }
+}
diff --git a/base/common/src/com/netscape/cms/client/cert/CertRestClient.java b/base/common/src/com/netscape/cms/client/cert/CertRestClient.java
index 39d393321..4ddc1d77a 100644
--- a/base/common/src/com/netscape/cms/client/cert/CertRestClient.java
+++ b/base/common/src/com/netscape/cms/client/cert/CertRestClient.java
@@ -28,7 +28,10 @@ import com.netscape.cms.servlet.cert.model.CertSearchData;
import com.netscape.cms.servlet.cert.model.CertUnrevokeRequest;
import com.netscape.cms.servlet.cert.model.CertificateData;
import com.netscape.cms.servlet.csadmin.CMSRestClient;
+import com.netscape.cms.servlet.request.CertRequestResource;
import com.netscape.cms.servlet.request.model.CertRequestInfo;
+import com.netscape.cms.servlet.request.model.CertRequestInfos;
+import com.netscape.cms.servlet.request.model.EnrollmentRequestData;
/**
* @author Endi S. Dewata
@@ -37,6 +40,7 @@ public class CertRestClient extends CMSRestClient {
public CertResource certClient;
public CertsResource certsClient;
+ public CertRequestResource certRequestResource;
public CertRestClient(String baseUri) throws URISyntaxException {
this(baseUri, null);
@@ -47,6 +51,7 @@ public class CertRestClient extends CMSRestClient {
certClient = createProxy(CertResource.class);
certsClient = createProxy(CertsResource.class);
+ certRequestResource = createProxy(CertRequestResource.class);
}
public CertificateData getCert(CertId id) {
@@ -71,4 +76,8 @@ public class CertRestClient extends CMSRestClient {
public CertRequestInfo unrevokeCert(CertId id, CertUnrevokeRequest request) {
return certClient.unrevokeCert(id, request);
}
+
+ public CertRequestInfos enrollRequest(EnrollmentRequestData data){
+ return certRequestResource.enrollCert(data);
+ }
}