summaryrefslogtreecommitdiffstats
path: root/base/java-tools/src/com/netscape/cmstools/cert
diff options
context:
space:
mode:
authorAde Lee <alee@redhat.com>2013-08-28 13:01:44 -0400
committerAde Lee <alee@redhat.com>2013-09-03 01:04:11 -0400
commit4afa12c4321f08de115bad85db561a3e5b5853c0 (patch)
treee9378113b6da87d2803a94232b5bf748cb27ca58 /base/java-tools/src/com/netscape/cmstools/cert
parent9c7e89d813b640619d02f9076eaa90829f4395ef (diff)
downloadpki-4afa12c4321f08de115bad85db561a3e5b5853c0.tar.gz
pki-4afa12c4321f08de115bad85db561a3e5b5853c0.tar.xz
pki-4afa12c4321f08de115bad85db561a3e5b5853c0.zip
Provide enrollment template per profile
This adds an API call to get a template which can be used to generate an enrollment request which can be passed into the REST API. The template is simply a CertRequest with the relevant inputs for that profile added in. Per code review comments, have added the templates interface to CertRequestResource instead. This patch now includes /certrequests/profiles and /certrequests/profiles/{id}. In a subsequent patch, all calls in ProfileResource will be restricted to admins and agents.
Diffstat (limited to 'base/java-tools/src/com/netscape/cmstools/cert')
-rw-r--r--base/java-tools/src/com/netscape/cmstools/cert/CertCLI.java3
-rw-r--r--base/java-tools/src/com/netscape/cmstools/cert/CertRequestProfileFindCLI.java39
-rw-r--r--base/java-tools/src/com/netscape/cmstools/cert/CertRequestProfileShowCLI.java70
3 files changed, 112 insertions, 0 deletions
diff --git a/base/java-tools/src/com/netscape/cmstools/cert/CertCLI.java b/base/java-tools/src/com/netscape/cmstools/cert/CertCLI.java
index 9b69c992c..32d580c08 100644
--- a/base/java-tools/src/com/netscape/cmstools/cert/CertCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/cert/CertCLI.java
@@ -53,6 +53,9 @@ public class CertCLI extends CLI {
addModule(new CertRequestShowCLI(this));
addModule(new CertRequestSubmitCLI(this));
addModule(new CertRequestReviewCLI(this));
+
+ addModule(new CertRequestProfileFindCLI(this));
+ addModule(new CertRequestProfileShowCLI(this));
}
public String getFullName() {
diff --git a/base/java-tools/src/com/netscape/cmstools/cert/CertRequestProfileFindCLI.java b/base/java-tools/src/com/netscape/cmstools/cert/CertRequestProfileFindCLI.java
new file mode 100644
index 000000000..48c051905
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/cert/CertRequestProfileFindCLI.java
@@ -0,0 +1,39 @@
+package com.netscape.cmstools.cert;
+
+import java.util.Collection;
+
+import com.netscape.certsrv.profile.ProfileDataInfo;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+import com.netscape.cmstools.profile.ProfileCLI;
+
+public class CertRequestProfileFindCLI extends CLI {
+
+ public CertCLI certCLI;
+
+ public CertRequestProfileFindCLI(CertCLI certCLI) {
+ super("request-profile-find", "List Enrollment templates", certCLI);
+ this.certCLI = certCLI;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(getFullName() + " <Profile ID>", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+ Collection<ProfileDataInfo> infos = certCLI.certClient.listEnrollmentTemplates().getProfileInfos();
+ boolean first = true;
+
+ for (ProfileDataInfo info: infos) {
+ if (first) {
+ first = false;
+ } else {
+ System.out.println();
+ }
+ ProfileCLI.printProfileDataInfo(info);
+ }
+
+ MainCLI.printMessage("Number of entries returned " + infos.size());
+ }
+}
+
diff --git a/base/java-tools/src/com/netscape/cmstools/cert/CertRequestProfileShowCLI.java b/base/java-tools/src/com/netscape/cmstools/cert/CertRequestProfileShowCLI.java
new file mode 100644
index 000000000..df83b19ed
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/cert/CertRequestProfileShowCLI.java
@@ -0,0 +1,70 @@
+package com.netscape.cmstools.cert;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.ParseException;
+
+import com.netscape.certsrv.cert.CertEnrollmentRequest;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+import com.netscape.cmstools.profile.ProfileCLI;
+
+public class CertRequestProfileShowCLI extends CLI {
+
+ public CertCLI certCLI;
+
+ public CertRequestProfileShowCLI(CertCLI certCLI) {
+ super("request-profile-show", "Get Enrollment template", certCLI);
+ this.certCLI = certCLI;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(getFullName() + " <Profile ID>", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+ CommandLine cmd = null;
+
+ Option option = new Option(null, "output", true, "Output filename");
+ option.setArgName("filename");
+ options.addOption(option);
+
+ 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: Missing profile ID.");
+ printHelp();
+ System.exit(-1);
+ }
+
+ String profileId = cLineArgs[0];
+
+ String filename = null;
+ if (cmd.hasOption("output")) {
+ filename = cmd.getOptionValue("output");
+
+ if (filename == null || filename.trim().length() == 0) {
+ System.err.println("Error: Missing output file name.");
+ printHelp();
+ System.exit(-1);
+ }
+ }
+
+ CertEnrollmentRequest request = certCLI.certClient.getEnrollmentTemplate(profileId);
+
+ MainCLI.printMessage("Enrollment Template for Profile \"" + profileId + "\"");
+
+ if (filename != null) {
+ ProfileCLI.saveEnrollmentTemplateToFile(filename, request);
+ } else {
+ ProfileCLI.printEnrollmentTemplate(request);
+ }
+ }
+}