summaryrefslogtreecommitdiffstats
path: root/base/java-tools/src/com/netscape/cmstools/profile
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/profile
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/profile')
-rw-r--r--base/java-tools/src/com/netscape/cmstools/profile/ProfileCLI.java49
1 files changed, 49 insertions, 0 deletions
diff --git a/base/java-tools/src/com/netscape/cmstools/profile/ProfileCLI.java b/base/java-tools/src/com/netscape/cmstools/profile/ProfileCLI.java
index 59f63c7e9..32b6366b3 100644
--- a/base/java-tools/src/com/netscape/cmstools/profile/ProfileCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/profile/ProfileCLI.java
@@ -12,6 +12,7 @@ import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
+import com.netscape.certsrv.cert.CertEnrollmentRequest;
import com.netscape.certsrv.profile.ProfileAttribute;
import com.netscape.certsrv.profile.ProfileClient;
import com.netscape.certsrv.profile.ProfileData;
@@ -144,4 +145,52 @@ public class ProfileCLI extends CLI {
data = (ProfileData) unmarshaller.unmarshal(fis);
return data;
}
+
+ public static void saveEnrollmentTemplateToFile(String filename, CertEnrollmentRequest request)
+ throws JAXBException, FileNotFoundException {
+ JAXBContext context = JAXBContext.newInstance(CertEnrollmentRequest.class);
+ Marshaller marshaller = context.createMarshaller();
+ marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+
+ FileOutputStream stream = new FileOutputStream(filename);
+ marshaller.marshal(request, stream);
+
+ MainCLI.printMessage("Saved enrollment template for " + request.getProfileId() + " to " + filename);
+ }
+
+ public static void printEnrollmentTemplate(CertEnrollmentRequest request) {
+ System.out.println(" Profile ID: " + request.getProfileId());
+ System.out.println(" Renewal: " + request.getIsRenewal());
+
+ for (ProfileInput input: request.getInputs()) {
+ System.out.println();
+ System.out.println(" Input ID: " + input.getId());
+ System.out.println(" Name: " + input.getName());
+ System.out.println(" Class: " + input.getClassId());
+ for (ProfileAttribute attr: input.getAttrs()) {
+ System.out.println();
+ System.out.println(" Attribute Name: " + attr.getName());
+ System.out.println(" Attribute Description: " +
+ attr.getDescriptor().getDescription(Locale.getDefault()));
+ System.out.println(" Attribute Syntax: " +
+ attr.getDescriptor().getSyntax());
+ }
+ }
+
+ for (ProfileOutput output: request.getOutputs()) {
+ System.out.println();
+ System.out.println(" Output ID: " + output.getId());
+ System.out.println(" Name: " + output.getName());
+ System.out.println(" Class: " + output.getClassId());
+ for (ProfileAttribute attr: output.getAttrs()) {
+ System.out.println();
+ System.out.println(" Attribute Name: " + attr.getName());
+ System.out.println(" Attribute Description: " +
+ attr.getDescriptor().getDescription(Locale.getDefault()));
+ System.out.println(" Attribute Syntax: " +
+ attr.getDescriptor().getSyntax());
+ }
+ }
+
+ }
}