diff options
author | Endi S. Dewata <edewata@redhat.com> | 2013-10-11 11:42:31 -0400 |
---|---|---|
committer | Endi S. Dewata <edewata@redhat.com> | 2013-10-25 17:18:33 -0400 |
commit | 533029c934843c75d1a01561d3200cc41292aeda (patch) | |
tree | 6ea4b6cd5c6e8c9ffe4b7dda6c8df225e3d9def7 /base | |
parent | 2119f1b218e9d68b13496e7042785d9c68753966 (diff) | |
download | pki-533029c934843c75d1a01561d3200cc41292aeda.tar.gz pki-533029c934843c75d1a01561d3200cc41292aeda.tar.xz pki-533029c934843c75d1a01561d3200cc41292aeda.zip |
Cleaned up CertEnrollmentRequest.
The CertEnrollmentRequest, ProfileInput, ProfileAttribute, and Descriptor
have been cleaned up to fix some bugs and minor formatting issues.
Diffstat (limited to 'base')
12 files changed, 270 insertions, 162 deletions
diff --git a/base/ca/functional/src/com/netscape/cms/servlet/test/CATest.java b/base/ca/functional/src/com/netscape/cms/servlet/test/CATest.java index 904e60c62..d50bfedf3 100644 --- a/base/ca/functional/src/com/netscape/cms/servlet/test/CATest.java +++ b/base/ca/functional/src/com/netscape/cms/servlet/test/CATest.java @@ -317,7 +317,7 @@ public class CATest { private static CertEnrollmentRequest createUserCertEnrollment() { CertEnrollmentRequest data = new CertEnrollmentRequest(); data.setProfileId("caUserCert"); - data.setIsRenewal(false); + data.setRenewal(false); //Simulate a "caUserCert" Profile enrollment @@ -348,7 +348,7 @@ public class CATest { private static CertEnrollmentRequest createRAUserCertEnrollment() { CertEnrollmentRequest data = new CertEnrollmentRequest(); data.setProfileId("caDualRAuserCert"); - data.setIsRenewal(false); + data.setRenewal(false); //Simulate a "caUserCert" Profile enrollment @@ -373,7 +373,7 @@ public class CATest { private static CertEnrollmentRequest createServerCertEnrollment() { CertEnrollmentRequest data = new CertEnrollmentRequest(); data.setProfileId("caServerCert"); - data.setIsRenewal(false); + data.setRenewal(false); //Simulate a "caUserCert" Profile enrollment @@ -441,7 +441,7 @@ public class CATest { List<ProfileInput> inputs = info.getInputs(); for (ProfileInput input : inputs) { log("Input Id: " + input.getId()); - for (ProfileAttribute attr: input.getAttrs()) { + for (ProfileAttribute attr : input.getAttributes()) { log("Input Attribute Name: " + attr.getName() + "\n"); log("Input Attribute Value: " + attr.getValue() + "\n"); } diff --git a/base/common/src/com/netscape/certsrv/cert/CertEnrollmentRequest.java b/base/common/src/com/netscape/certsrv/cert/CertEnrollmentRequest.java index f5feda0fd..732efae0a 100644 --- a/base/common/src/com/netscape/certsrv/cert/CertEnrollmentRequest.java +++ b/base/common/src/com/netscape/certsrv/cert/CertEnrollmentRequest.java @@ -21,11 +21,11 @@ */ package com.netscape.certsrv.cert; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; +import java.io.StringReader; +import java.io.StringWriter; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; -import java.util.List; import javax.ws.rs.core.MultivaluedMap; import javax.xml.bind.JAXBContext; @@ -54,26 +54,26 @@ public class CertEnrollmentRequest { private static final String RENEWAL = "renewal"; private static final String SERIAL_NUM = "serial_num"; - @XmlElement + @XmlElement(name="ProfileID") protected String profileId; - @XmlElement - protected boolean isRenewal; + @XmlElement(name="Renewal") + protected boolean renewal; - @XmlElement + @XmlElement(name="SerialNumber") protected String serialNum; // used for one type of renewal - @XmlElement + @XmlElement(name="RemoteHost") protected String remoteHost; - @XmlElement + @XmlElement(name="RemoteAddress") protected String remoteAddr; @XmlElement(name = "Input") - protected List<ProfileInput> inputs = new ArrayList<ProfileInput>(); + protected Collection<ProfileInput> inputs = new ArrayList<ProfileInput>(); @XmlElement(name = "Output") - protected List<ProfileOutput> outputs = new ArrayList<ProfileOutput>(); + protected Collection<ProfileOutput> outputs = new ArrayList<ProfileOutput>(); public CertEnrollmentRequest() { // required for jaxb @@ -83,7 +83,7 @@ public class CertEnrollmentRequest { profileId = form.getFirst(PROFILE_ID); String renewalStr = form.getFirst(RENEWAL); serialNum = form.getFirst(SERIAL_NUM); - isRenewal = new Boolean(renewalStr); + renewal = new Boolean(renewalStr); } /** @@ -96,7 +96,6 @@ public class CertEnrollmentRequest { /** * @param profileId the profileId to set */ - public void setProfileId(String profileId) { this.profileId = profileId; } @@ -104,23 +103,29 @@ public class CertEnrollmentRequest { /** * @return renewal */ + public boolean isRenewal() { + return renewal; + } - public boolean getIsRenewal() { - return isRenewal; + /** + * @param renewal the renewal to set + */ + public void setRenewal(boolean renewal) { + this.renewal = renewal; } public void addInput(ProfileInput input) { ProfileInput curInput = getInput(input.getName()); if (curInput != null) { - getInputs().remove(curInput); + inputs.remove(curInput); } - getInputs().add(input); + inputs.add(input); } public void deleteInput(ProfileInput input) { ProfileInput curInput = getInput(input.getName()); if (curInput != null) { - getInputs().remove(curInput); + inputs.remove(curInput); } } @@ -134,61 +139,52 @@ public class CertEnrollmentRequest { ProfileInput newInput = new ProfileInput(); newInput.setName(name); - getInputs().add(newInput); + inputs.add(newInput); return newInput; } public ProfileInput getInput(String name) { - ProfileInput input = null; - for (ProfileInput curInput: getInputs()) { - if (curInput != null && curInput.getName().equals(name)) - break; + for (ProfileInput input : inputs) { + if (input.getName().equals(name)) + return input; } - return input; + return null; } public void addOutput(ProfileOutput output) { ProfileOutput curOutput = getOutput(output.getName()); if (curOutput != null) { - getOutputs().remove(curOutput); + outputs.remove(curOutput); } - getOutputs().add(output); + outputs.add(output); } public void deleteOutput(ProfileOutput output) { ProfileOutput curOutput = getOutput(output.getName()); if (curOutput != null) { - getInputs().remove(curOutput); + outputs.remove(curOutput); } } public ProfileOutput getOutput(String name) { - ProfileOutput output = null; - for (ProfileOutput curOutput: getOutputs()) { - if (curOutput != null && curOutput.getName().equals(name)) - break; + for (ProfileOutput output : outputs) { + if (output.getName().equals(name)) + return output; } - return output; - } - - /** - * @param renewal the renewal to set - */ - public void setIsRenewal(boolean isRenewal) { - this.isRenewal = isRenewal; + return null; } public HashMap<String, String> toParams() { HashMap<String, String> ret = new HashMap<String, String>(); - ret.put("isRenewal", Boolean.valueOf(isRenewal).toString()); + ret.put("isRenewal", Boolean.valueOf(renewal).toString()); if (profileId != null) ret.put(PROFILE_ID, profileId); if (serialNum != null) ret.put(SERIAL_NUM, serialNum); if (remoteHost != null) ret.put("remoteHost", remoteHost); if (remoteAddr != null) ret.put("remoteAddr", remoteAddr); for (ProfileInput input: inputs) { - for (ProfileAttribute attr:input.getAttrs()) { + for (ProfileAttribute attr : input.getAttributes()) { ret.put(attr.getName(), attr.getValue()); } } @@ -196,71 +192,6 @@ public class CertEnrollmentRequest { return ret; } - public static void main(String args[]) throws Exception { - CertEnrollmentRequest data = new CertEnrollmentRequest(); - data.setProfileId("caUserCert"); - data.setIsRenewal(false); - - //Simulate a "caUserCert" Profile enrollment - - ProfileInput certReq = data.createInput("KeyGenInput"); - certReq.addAttribute(new ProfileAttribute("cert_request_type", "crmf", null)); - certReq.addAttribute(new ProfileAttribute( - "cert_request", - "MIIBozCCAZ8wggEFAgQBMQp8MIHHgAECpQ4wDDEKMAgGA1UEAxMBeKaBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA2NgaPHp0jiohcP4M+ufrJOZEqH8GV+liu5JLbT8nWpkfhC+8EUBqT6g+n3qroSxIcNVGNdcsBEqs1utvpItzyslAbpdyat3WwQep1dWMzo6RHrPDuIoxNA0Yka1n3qEX4U//08cLQtUv2bYglYgN/hOCNQemLV6vZWAv0n7zelkCAwEAAakQMA4GA1UdDwEB/wQEAwIF4DAzMBUGCSsGAQUFBwUBAQwIcmVnVG9rZW4wGgYJKwYBBQUHBQECDA1hdXRoZW50aWNhdG9yoYGTMA0GCSqGSIb3DQEBBQUAA4GBAJ1VOQcaSEhdHa94s8kifVbSZ2WZeYE5//qxL6wVlEst20vq4ybj13CetnbN3+WT49Zkwp7Fg+6lALKgSk47suTg3EbbQDm+8yOrC0nc/q4PTRoHl0alMmUxIhirYc1t3xoCMqJewmjX1bNP8lpVIZAYFZo4eZCpZaiSkM5BeHhz", - null)); - - ProfileInput subjectName = data.createInput("SubjectNameInput"); - subjectName.addAttribute(new ProfileAttribute("sn_uid", "jmagne", null)); - subjectName.addAttribute(new ProfileAttribute("sn_e", "jmagne@redhat.com", null)); - subjectName.addAttribute(new ProfileAttribute("sn_c", "US", null)); - subjectName.addAttribute(new ProfileAttribute("sn_ou", "Development", null)); - subjectName.addAttribute(new ProfileAttribute("sn_ou1", "IPA", null)); - subjectName.addAttribute(new ProfileAttribute("sn_ou2", "Dogtag", null)); - subjectName.addAttribute(new ProfileAttribute("sn_ou3", "CA", null)); - subjectName.addAttribute(new ProfileAttribute("sn_cn", "Common", null)); - subjectName.addAttribute(new ProfileAttribute("sn_o", "RedHat", null)); - - ProfileInput submitter = data.createInput("SubmitterInfoInput"); - submitter.addAttribute(new ProfileAttribute("requestor_name", "admin", null)); - submitter.addAttribute(new ProfileAttribute("requestor_email", "admin@redhat.com", null)); - submitter.addAttribute(new ProfileAttribute("requestor_phone", "650-555-5555", null)); - - try { - JAXBContext context = JAXBContext.newInstance(CertEnrollmentRequest.class); - Marshaller marshaller = context.createMarshaller(); - marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); - - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - - marshaller.marshal(data, stream); - - System.out.println("Originally marshalled enrollment object. \n"); - - System.out.println(stream.toString()); - - //Try to unmarshall - - Unmarshaller unmarshaller = context.createUnmarshaller(); - - ByteArrayInputStream bais = new ByteArrayInputStream(stream.toByteArray()); - Object unmarshalled = unmarshaller.unmarshal(bais); - - //Try re-marshalling, unmarshalled object to compare - - stream.reset(); - - marshaller.marshal(unmarshalled, stream); - - System.out.println("Remarshalled unmarshalled enrollment object. \n"); - - System.out.println(stream.toString()); - - } catch (JAXBException e) { - System.out.println(e.toString()); - } - } - public String getSerialNum() { return serialNum; } @@ -269,12 +200,13 @@ public class CertEnrollmentRequest { this.serialNum = serialNum; } - public List<ProfileInput> getInputs() { + public Collection<ProfileInput> getInputs() { return inputs; } - public void setInputs(List<ProfileInput> inputs) { - this.inputs = inputs; + public void setInputs(Collection<ProfileInput> inputs) { + this.inputs.clear(); + this.inputs.addAll(inputs); } public String getRemoteAddr() { @@ -293,16 +225,124 @@ public class CertEnrollmentRequest { this.remoteHost = remoteHost; } - public List<ProfileOutput> getOutputs() { + public Collection<ProfileOutput> getOutputs() { return outputs; } - public void setOutputs(List<ProfileOutput> outputs) { - this.outputs = outputs; + public void setOutputs(Collection<ProfileOutput> outputs) { + this.outputs.clear(); + this.outputs.addAll(outputs); } - public void setRenewal(boolean isRenewal) { - this.isRenewal = isRenewal; + public static CertEnrollmentRequest fromXML(String string) throws JAXBException { + JAXBContext context = JAXBContext.newInstance(CertEnrollmentRequest.class); + Unmarshaller unmarshaller = context.createUnmarshaller(); + return (CertEnrollmentRequest) unmarshaller.unmarshal(new StringReader(string)); } + public String toXML() throws JAXBException { + JAXBContext context = JAXBContext.newInstance(CertEnrollmentRequest.class); + Marshaller marshaller = context.createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + StringWriter sw = new StringWriter(); + marshaller.marshal(this, sw); + return sw.toString(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((inputs == null) ? 0 : inputs.hashCode()); + result = prime * result + ((outputs == null) ? 0 : outputs.hashCode()); + result = prime * result + ((profileId == null) ? 0 : profileId.hashCode()); + result = prime * result + ((remoteAddr == null) ? 0 : remoteAddr.hashCode()); + result = prime * result + ((remoteHost == null) ? 0 : remoteHost.hashCode()); + result = prime * result + (renewal ? 1231 : 1237); + result = prime * result + ((serialNum == null) ? 0 : serialNum.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; + CertEnrollmentRequest other = (CertEnrollmentRequest) obj; + if (inputs == null) { + if (other.inputs != null) + return false; + } else if (!inputs.equals(other.inputs)) + return false; + if (outputs == null) { + if (other.outputs != null) + return false; + } else if (!outputs.equals(other.outputs)) + return false; + if (profileId == null) { + if (other.profileId != null) + return false; + } else if (!profileId.equals(other.profileId)) + return false; + if (remoteAddr == null) { + if (other.remoteAddr != null) + return false; + } else if (!remoteAddr.equals(other.remoteAddr)) + return false; + if (remoteHost == null) { + if (other.remoteHost != null) + return false; + } else if (!remoteHost.equals(other.remoteHost)) + return false; + if (renewal != other.renewal) + return false; + if (serialNum == null) { + if (other.serialNum != null) + return false; + } else if (!serialNum.equals(other.serialNum)) + return false; + return true; + } + + public static void main(String args[]) throws Exception { + CertEnrollmentRequest before = new CertEnrollmentRequest(); + before.setProfileId("caUserCert"); + before.setRenewal(false); + + //Simulate a "caUserCert" Profile enrollment + + ProfileInput certReq = before.createInput("KeyGenInput"); + certReq.addAttribute(new ProfileAttribute("cert_request_type", "crmf", null)); + certReq.addAttribute(new ProfileAttribute( + "cert_request", + "MIIBozCCAZ8wggEFAgQBMQp8MIHHgAECpQ4wDDEKMAgGA1UEAxMBeKaBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA2NgaPHp0jiohcP4M+ufrJOZEqH8GV+liu5JLbT8nWpkfhC+8EUBqT6g+n3qroSxIcNVGNdcsBEqs1utvpItzyslAbpdyat3WwQep1dWMzo6RHrPDuIoxNA0Yka1n3qEX4U//08cLQtUv2bYglYgN/hOCNQemLV6vZWAv0n7zelkCAwEAAakQMA4GA1UdDwEB/wQEAwIF4DAzMBUGCSsGAQUFBwUBAQwIcmVnVG9rZW4wGgYJKwYBBQUHBQECDA1hdXRoZW50aWNhdG9yoYGTMA0GCSqGSIb3DQEBBQUAA4GBAJ1VOQcaSEhdHa94s8kifVbSZ2WZeYE5//qxL6wVlEst20vq4ybj13CetnbN3+WT49Zkwp7Fg+6lALKgSk47suTg3EbbQDm+8yOrC0nc/q4PTRoHl0alMmUxIhirYc1t3xoCMqJewmjX1bNP8lpVIZAYFZo4eZCpZaiSkM5BeHhz", + null)); + + ProfileInput subjectName = before.createInput("SubjectNameInput"); + subjectName.addAttribute(new ProfileAttribute("sn_uid", "jmagne", null)); + subjectName.addAttribute(new ProfileAttribute("sn_e", "jmagne@redhat.com", null)); + subjectName.addAttribute(new ProfileAttribute("sn_c", "US", null)); + subjectName.addAttribute(new ProfileAttribute("sn_ou", "Development", null)); + subjectName.addAttribute(new ProfileAttribute("sn_ou1", "IPA", null)); + subjectName.addAttribute(new ProfileAttribute("sn_ou2", "Dogtag", null)); + subjectName.addAttribute(new ProfileAttribute("sn_ou3", "CA", null)); + subjectName.addAttribute(new ProfileAttribute("sn_cn", "Common", null)); + subjectName.addAttribute(new ProfileAttribute("sn_o", "RedHat", null)); + + ProfileInput submitter = before.createInput("SubmitterInfoInput"); + submitter.addAttribute(new ProfileAttribute("requestor_name", "admin", null)); + submitter.addAttribute(new ProfileAttribute("requestor_email", "admin@redhat.com", null)); + submitter.addAttribute(new ProfileAttribute("requestor_phone", "650-555-5555", null)); + + String xml = before.toXML(); + System.out.println(xml); + + CertEnrollmentRequest after = CertEnrollmentRequest.fromXML(xml); + System.out.println(after.toXML()); + + System.out.println(before.equals(after)); + } } diff --git a/base/common/src/com/netscape/certsrv/profile/ProfileAttribute.java b/base/common/src/com/netscape/certsrv/profile/ProfileAttribute.java index c3549424c..be91fd2e4 100644 --- a/base/common/src/com/netscape/certsrv/profile/ProfileAttribute.java +++ b/base/common/src/com/netscape/certsrv/profile/ProfileAttribute.java @@ -25,17 +25,17 @@ import javax.xml.bind.annotation.XmlRootElement; import com.netscape.certsrv.property.Descriptor; -@XmlRootElement +@XmlRootElement(name="Attribute") @XmlAccessorType(XmlAccessType.FIELD) public class ProfileAttribute { @XmlAttribute private String name; - @XmlElement + @XmlElement(name="Value") private String value; - @XmlElement + @XmlElement(name="Descriptor") private Descriptor descriptor; public ProfileAttribute() { diff --git a/base/common/src/com/netscape/certsrv/profile/ProfileInput.java b/base/common/src/com/netscape/certsrv/profile/ProfileInput.java index 2826f50d8..b53630d9f 100644 --- a/base/common/src/com/netscape/certsrv/profile/ProfileInput.java +++ b/base/common/src/com/netscape/certsrv/profile/ProfileInput.java @@ -17,32 +17,60 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.certsrv.profile; +import java.io.StringReader; +import java.io.StringWriter; import java.util.ArrayList; +import java.util.Collection; import java.util.Enumeration; import java.util.List; import java.util.Locale; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +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.XmlAttribute; import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; import com.netscape.certsrv.property.Descriptor; +@XmlRootElement(name="Input") +@XmlAccessorType(XmlAccessType.FIELD) public class ProfileInput { + + @XmlAttribute(name="id") private String id; + + @XmlElement(name="ClassID") private String classId; + + @XmlElement(name="Name") private String name; + + @XmlElement(name="Text") private String text; + + @XmlElement(name = "Attribute") private List<ProfileAttribute> attrs = new ArrayList<ProfileAttribute>(); + + @XmlElement(name = "ConfigAttribute") private List<ProfileAttribute> configAttrs = new ArrayList<ProfileAttribute>(); public ProfileInput() { // required for jaxb } - public ProfileInput(IProfileInput input, String id, String classId, Locale locale) { - this.name = input.getName(locale); + public ProfileInput(String id, String name, String classId) { this.id = id; + this.name = name; this.classId = classId; + } + + public ProfileInput(IProfileInput input, String id, String classId, Locale locale) { + this(id, input.getName(locale), classId); Enumeration<String> names = input.getValueNames(); while (names.hasMoreElements()) { String name = names.nextElement(); @@ -51,17 +79,14 @@ public class ProfileInput { } } - @XmlElement public String getClassId() { return classId; } - @XmlElement public String getName() { return name; } - @XmlElement public String getText() { return text; } @@ -70,7 +95,6 @@ public class ProfileInput { this.classId = classId; } - @XmlAttribute public String getId() { return id; } @@ -87,28 +111,34 @@ public class ProfileInput { this.text = text; } - @XmlElement(name = "attribute") - public List<ProfileAttribute> getAttrs() { + public Collection<ProfileAttribute> getAttributes() { return attrs; } - public void setAttrs(List<ProfileAttribute> attrs) { - this.attrs = attrs; + public void setAttributes(Collection<ProfileAttribute> attrs) { + this.attrs.clear(); + this.attrs.addAll(attrs); + } + + public ProfileAttribute getAttribute(String name) { + for (ProfileAttribute attr : attrs) { + if (attr.getName().equals(name)) return attr; + } + return null; } public void addAttribute(ProfileAttribute attr) { attrs.add(attr); } - public void removeAttribute(ProfileAttribute attr) { - attrs.remove(attr); + public void removeAttribute(String name) { + attrs.remove(name); } public void clearAttributes() { attrs.clear(); } - @XmlElement(name = "config_attribute") public List<ProfileAttribute> getConfigAttrs() { return configAttrs; } @@ -118,11 +148,11 @@ public class ProfileInput { } public void addConfigAttribute(ProfileAttribute configAttr) { - attrs.add(configAttr); + configAttrs.add(configAttr); } public void removeConfigAttribute(ProfileAttribute configAttr) { - attrs.remove(configAttr); + configAttrs.remove(configAttr); } public void clearConfigAttributes() { @@ -184,4 +214,40 @@ public class ProfileInput { return true; } + public static ProfileInput fromXML(String string) throws JAXBException { + JAXBContext context = JAXBContext.newInstance(ProfileInput.class); + Unmarshaller unmarshaller = context.createUnmarshaller(); + return (ProfileInput) unmarshaller.unmarshal(new StringReader(string)); + } + + public String toXML() throws JAXBException { + JAXBContext context = JAXBContext.newInstance(ProfileInput.class); + Marshaller marshaller = context.createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + StringWriter sw = new StringWriter(); + marshaller.marshal(this, sw); + return sw.toString(); + } + + public static void main(String args[]) throws Exception { + + ProfileInput before = new ProfileInput("i1", "SubjectNameInput", null); + before.addAttribute(new ProfileAttribute("sn_uid", "jmagne", null)); + before.addAttribute(new ProfileAttribute("sn_e", "jmagne@redhat.com", null)); + before.addAttribute(new ProfileAttribute("sn_c", "US", null)); + before.addAttribute(new ProfileAttribute("sn_ou", "Development", null)); + before.addAttribute(new ProfileAttribute("sn_ou1", "IPA", null)); + before.addAttribute(new ProfileAttribute("sn_ou2", "Dogtag", null)); + before.addAttribute(new ProfileAttribute("sn_ou3", "CA", null)); + before.addAttribute(new ProfileAttribute("sn_cn", "Common", null)); + before.addAttribute(new ProfileAttribute("sn_o", "RedHat", null)); + + String xml = before.toXML(); + System.out.println(xml); + + ProfileInput after = ProfileInput.fromXML(xml); + System.out.println(after.toXML()); + + System.out.println(before.equals(after)); + } } diff --git a/base/common/src/com/netscape/certsrv/property/Descriptor.java b/base/common/src/com/netscape/certsrv/property/Descriptor.java index 63e154466..b6a9900b6 100644 --- a/base/common/src/com/netscape/certsrv/property/Descriptor.java +++ b/base/common/src/com/netscape/certsrv/property/Descriptor.java @@ -35,16 +35,16 @@ import javax.xml.bind.annotation.XmlRootElement; @XmlAccessorType(XmlAccessType.FIELD) public class Descriptor implements IDescriptor { - @XmlElement(name = "syntax") + @XmlElement(name = "Syntax") protected String mSyntax = null; - @XmlElement(name = "constraint") + @XmlElement(name = "Constraint") protected String mConstraint = null; - @XmlElement(name = "description") + @XmlElement(name = "Description") protected String mDescription = null; - @XmlElement(name = "defaultValue") + @XmlElement(name = "DefaultValue") protected String mDef = null; public Descriptor() { diff --git a/base/java-tools/src/com/netscape/cmstools/cert/CertRequestSubmitCLI.java b/base/java-tools/src/com/netscape/cmstools/cert/CertRequestSubmitCLI.java index 917a697b6..d43763f11 100644 --- a/base/java-tools/src/com/netscape/cmstools/cert/CertRequestSubmitCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/cert/CertRequestSubmitCLI.java @@ -1,12 +1,11 @@ package com.netscape.cmstools.cert; -import java.io.FileInputStream; +import java.io.File; import java.io.FileNotFoundException; import java.util.Collection; +import java.util.Scanner; -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; @@ -50,16 +49,16 @@ public class CertRequestSubmitCLI extends CLI { System.exit(-1); } - CertEnrollmentRequest erd = null; - try { - erd = getEnrollmentRequest(cLineArgs[0]); + CertEnrollmentRequest erd = getEnrollmentRequest(cLineArgs[0]); CertRequestInfos cri = certCLI.certClient.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); @@ -67,19 +66,22 @@ public class CertRequestSubmitCLI extends CLI { } private CertEnrollmentRequest getEnrollmentRequest(String fileName) throws JAXBException, FileNotFoundException { - CertEnrollmentRequest erd = null; - JAXBContext context = JAXBContext.newInstance(CertEnrollmentRequest.class); - Unmarshaller unmarshaller = context.createUnmarshaller(); - FileInputStream fis = new FileInputStream(fileName); - erd = (CertEnrollmentRequest) unmarshaller.unmarshal(fis); - return erd; + try (Scanner scanner = new Scanner(new File(fileName))) { + String xml = scanner.useDelimiter("\\A").next(); + return CertEnrollmentRequest.fromXML(xml); + } } private void printRequestInformation(CertRequestInfos cri) { Collection<CertRequestInfo> allRequests = cri.getRequests(); + boolean first = true; for (CertRequestInfo x : allRequests) { + if (first) { + first = false; + } else { + System.out.println(); + } CertCLI.printCertRequestInfo(x); } - System.out.println(); } } 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 775398283..732b597af 100644 --- a/base/java-tools/src/com/netscape/cmstools/profile/ProfileCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/profile/ProfileCLI.java @@ -82,7 +82,7 @@ public class ProfileCLI extends CLI { System.out.println(" Input ID: " + input.getId()); System.out.println(" Name: " + input.getName()); System.out.println(" Class: " + input.getClassId()); - for (ProfileAttribute attr: input.getAttrs()) { + for (ProfileAttribute attr : input.getAttributes()) { System.out.println(); System.out.println(" Attribute Name: " + attr.getName()); System.out.println(" Attribute Description: " + @@ -144,14 +144,14 @@ public class ProfileCLI extends CLI { public static void printEnrollmentTemplate(CertEnrollmentRequest request) { System.out.println(" Profile ID: " + request.getProfileId()); - System.out.println(" Renewal: " + request.getIsRenewal()); + System.out.println(" Renewal: " + request.isRenewal()); 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()) { + for (ProfileAttribute attr : input.getAttributes()) { System.out.println(); System.out.println(" Attribute Name: " + attr.getName()); System.out.println(" Attribute Description: " + diff --git a/base/server/cms/src/com/netscape/cms/servlet/cert/CertProcessor.java b/base/server/cms/src/com/netscape/cms/servlet/cert/CertProcessor.java index 8ffa65d9b..8498f31c3 100644 --- a/base/server/cms/src/com/netscape/cms/servlet/cert/CertProcessor.java +++ b/base/server/cms/src/com/netscape/cms/servlet/cert/CertProcessor.java @@ -78,7 +78,7 @@ public class CertProcessor extends Processor { // put profile inputs into a local map HashMap<String, String> dataInputs = new HashMap<String, String>(); for (ProfileInput input : data.getInputs()) { - for (ProfileAttribute attr: input.getAttrs()) { + for (ProfileAttribute attr : input.getAttributes()) { dataInputs.put(attr.getName(), attr.getValue()); } } diff --git a/base/server/cms/src/com/netscape/cms/servlet/cert/CertRequestDAO.java b/base/server/cms/src/com/netscape/cms/servlet/cert/CertRequestDAO.java index d4785e957..e68896a9d 100644 --- a/base/server/cms/src/com/netscape/cms/servlet/cert/CertRequestDAO.java +++ b/base/server/cms/src/com/netscape/cms/servlet/cert/CertRequestDAO.java @@ -168,7 +168,7 @@ public class CertRequestDAO extends CMSRequestDAO { CertRequestInfos ret = new CertRequestInfos(); HashMap<String, Object> results = null; - if (data.getIsRenewal()) { + if (data.isRenewal()) { RenewalProcessor processor = new RenewalProcessor("caProfileSubmit", locale); results = processor.processRenewal(data, request); } else { diff --git a/base/server/cms/src/com/netscape/cms/servlet/cert/CertReviewResponseFactory.java b/base/server/cms/src/com/netscape/cms/servlet/cert/CertReviewResponseFactory.java index 6071b1dcb..6fcd94104 100644 --- a/base/server/cms/src/com/netscape/cms/servlet/cert/CertReviewResponseFactory.java +++ b/base/server/cms/src/com/netscape/cms/servlet/cert/CertReviewResponseFactory.java @@ -51,9 +51,9 @@ public class CertReviewResponseFactory { CertReviewResponse ret = new CertReviewResponse(); if (request.getRequestType().equals("renewal")) { - ret.setIsRenewal(true); + ret.setRenewal(true); } else { - ret.setIsRenewal(false); + ret.setRenewal(false); } ret.setRequestId(request.getRequestId()); diff --git a/base/server/cms/src/com/netscape/cms/servlet/cert/EnrollmentProcessor.java b/base/server/cms/src/com/netscape/cms/servlet/cert/EnrollmentProcessor.java index 31b235d2a..ee56f0139 100644 --- a/base/server/cms/src/com/netscape/cms/servlet/cert/EnrollmentProcessor.java +++ b/base/server/cms/src/com/netscape/cms/servlet/cert/EnrollmentProcessor.java @@ -51,7 +51,7 @@ public class EnrollmentProcessor extends CertProcessor { // put profile inputs into a local map HashMap<String, String> dataInputs = new HashMap<String, String>(); for (ProfileInput input : data.getInputs()) { - for (ProfileAttribute attr: input.getAttrs()) { + for (ProfileAttribute attr : input.getAttributes()) { dataInputs.put(attr.getName(), attr.getValue()); } } diff --git a/base/server/cms/src/com/netscape/cms/servlet/request/CertRequestService.java b/base/server/cms/src/com/netscape/cms/servlet/request/CertRequestService.java index dd3065427..620084208 100644 --- a/base/server/cms/src/com/netscape/cms/servlet/request/CertRequestService.java +++ b/base/server/cms/src/com/netscape/cms/servlet/request/CertRequestService.java @@ -319,7 +319,7 @@ public class CertRequestService extends PKIService implements CertRequestResourc String id = inputIds.nextElement(); try { ProfileInput input = ProfileService.createProfileInput(profile, id, getLocale(headers)); - for (ProfileAttribute attr: input.getAttrs()) { + for (ProfileAttribute attr : input.getAttributes()) { attr.setValue(""); } request.addInput(input); |