From 1aa02e5207514d210e903d23e1d698b85fc29344 Mon Sep 17 00:00:00 2001 From: Endi Sukma Dewata Date: Sat, 11 Aug 2012 09:47:39 -0500 Subject: Reorganized REST common classes. The common classes used by REST client and services have been moved into the com.netscape.certsrv. packages. Ticket #215 --- .../netscape/certsrv/profile/PolicyConstraint.java | 73 ++++++++++ .../certsrv/profile/PolicyConstraintValue.java | 61 +++++++++ .../netscape/certsrv/profile/PolicyDefault.java | 73 ++++++++++ .../netscape/certsrv/profile/ProfileAttribute.java | 80 +++++++++++ .../com/netscape/certsrv/profile/ProfileData.java | 147 +++++++++++++++++++++ .../netscape/certsrv/profile/ProfileDataInfo.java | 68 ++++++++++ .../netscape/certsrv/profile/ProfileDataInfos.java | 90 +++++++++++++ .../com/netscape/certsrv/profile/ProfileInput.java | 94 +++++++++++++ .../certsrv/profile/ProfileNotFoundException.java | 62 +++++++++ .../netscape/certsrv/profile/ProfileOutput.java | 84 ++++++++++++ .../netscape/certsrv/profile/ProfilePolicy.java | 82 ++++++++++++ .../netscape/certsrv/profile/ProfilePolicySet.java | 50 +++++++ .../netscape/certsrv/profile/ProfileResource.java | 43 ++++++ .../certsrv/profile/ProfileRetrievalRequest.java | 67 ++++++++++ 14 files changed, 1074 insertions(+) create mode 100644 base/common/src/com/netscape/certsrv/profile/PolicyConstraint.java create mode 100644 base/common/src/com/netscape/certsrv/profile/PolicyConstraintValue.java create mode 100644 base/common/src/com/netscape/certsrv/profile/PolicyDefault.java create mode 100644 base/common/src/com/netscape/certsrv/profile/ProfileAttribute.java create mode 100644 base/common/src/com/netscape/certsrv/profile/ProfileData.java create mode 100644 base/common/src/com/netscape/certsrv/profile/ProfileDataInfo.java create mode 100644 base/common/src/com/netscape/certsrv/profile/ProfileDataInfos.java create mode 100644 base/common/src/com/netscape/certsrv/profile/ProfileInput.java create mode 100644 base/common/src/com/netscape/certsrv/profile/ProfileNotFoundException.java create mode 100644 base/common/src/com/netscape/certsrv/profile/ProfileOutput.java create mode 100644 base/common/src/com/netscape/certsrv/profile/ProfilePolicy.java create mode 100644 base/common/src/com/netscape/certsrv/profile/ProfilePolicySet.java create mode 100644 base/common/src/com/netscape/certsrv/profile/ProfileResource.java create mode 100644 base/common/src/com/netscape/certsrv/profile/ProfileRetrievalRequest.java (limited to 'base/common/src/com/netscape/certsrv/profile') diff --git a/base/common/src/com/netscape/certsrv/profile/PolicyConstraint.java b/base/common/src/com/netscape/certsrv/profile/PolicyConstraint.java new file mode 100644 index 000000000..8b43661a2 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/profile/PolicyConstraint.java @@ -0,0 +1,73 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2012 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.profile; + +import java.util.ArrayList; +import java.util.List; + +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; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.FIELD) +public class PolicyConstraint { + @XmlAttribute(name="id") + private String name; + + @XmlElement(name="description") + private String text; + + @XmlElement(name = "constraint") + private List constraints = new ArrayList(); + + public PolicyConstraint() { + // required for jaxb + } + + public void addConstraint(PolicyConstraintValue constraint) { + constraints.add(constraint); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public List getConstraints() { + return constraints; + } + + public void setConstraints(List constraints) { + this.constraints = constraints; + } + +} diff --git a/base/common/src/com/netscape/certsrv/profile/PolicyConstraintValue.java b/base/common/src/com/netscape/certsrv/profile/PolicyConstraintValue.java new file mode 100644 index 000000000..5241ad832 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/profile/PolicyConstraintValue.java @@ -0,0 +1,61 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2012 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.profile; + +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 +@XmlAccessorType(XmlAccessType.FIELD) +public class PolicyConstraintValue { + @XmlAttribute(name="id") + private String name; + + @XmlElement + private Descriptor descriptor; + + public PolicyConstraintValue() { + // required for jax-b + } + + public PolicyConstraintValue(String name, Descriptor descriptor) { + this.name = name; + this.descriptor = descriptor; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Descriptor getDescriptor() { + return descriptor; + } + + public void setDescriptor(Descriptor descriptor) { + this.descriptor = descriptor; + } +} diff --git a/base/common/src/com/netscape/certsrv/profile/PolicyDefault.java b/base/common/src/com/netscape/certsrv/profile/PolicyDefault.java new file mode 100644 index 000000000..2b95cf5f0 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/profile/PolicyDefault.java @@ -0,0 +1,73 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2012 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.profile; + +import java.util.ArrayList; +import java.util.List; + +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; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.FIELD) +public class PolicyDefault { + @XmlAttribute(name="id") + private String name; + + @XmlElement(name="description") + private String text; + + @XmlElement(name="policyAttribute") + private List attributes = new ArrayList(); + + public PolicyDefault() { + // required for jaxb + } + + public void addAttribute(ProfileAttribute attr) { + attributes.add(attr); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public List getAttributes() { + return attributes; + } + + public void setAttributes(List attributes) { + this.attributes = attributes; + } + +} diff --git a/base/common/src/com/netscape/certsrv/profile/ProfileAttribute.java b/base/common/src/com/netscape/certsrv/profile/ProfileAttribute.java new file mode 100644 index 000000000..9c889bb8a --- /dev/null +++ b/base/common/src/com/netscape/certsrv/profile/ProfileAttribute.java @@ -0,0 +1,80 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2012 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.profile; + +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 +@XmlAccessorType(XmlAccessType.FIELD) +public class ProfileAttribute { + + @XmlAttribute + private String name; + + @XmlElement + private String value; + + @XmlElement + private Descriptor descriptor; + + public ProfileAttribute() { + // required for jax-b + } + + public ProfileAttribute(String name, String value, Descriptor descriptor) { + this.name = name; + this.value = value; + this.descriptor = descriptor; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public Descriptor getDescriptor() { + return descriptor; + } + + public void setDescriptor(Descriptor descriptor) { + this.descriptor = descriptor; + } + + @Override + public String toString() { + return "PolicyAttribute [name=" + name + ", value=" + value + ", descriptor=" + descriptor + "]"; + } + +} diff --git a/base/common/src/com/netscape/certsrv/profile/ProfileData.java b/base/common/src/com/netscape/certsrv/profile/ProfileData.java new file mode 100644 index 000000000..465981add --- /dev/null +++ b/base/common/src/com/netscape/certsrv/profile/ProfileData.java @@ -0,0 +1,147 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2011 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- + +/** + * + */ +package com.netscape.certsrv.profile; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author jmagne + * + */ + +@XmlRootElement(name = "ProfileData") +@XmlAccessorType(XmlAccessType.FIELD) +public class ProfileData { + + @XmlElement + protected String id; + + @XmlElement + protected String name; + + @XmlElement + protected String description; + + @XmlElement + protected boolean isEnabled; + + @XmlElement + protected boolean isVisible; + + @XmlElement + protected String enabledBy; + + @XmlElement(name = "Input") + protected List inputs = new ArrayList(); + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getDescription() { + return description; + } + + public void setIsEnabled(boolean isEnabled) { + this.isEnabled = isEnabled; + } + + public boolean getIsEnabled() { + return isEnabled; + } + + public void setIsVisible(boolean isVisible) { + this.isVisible = isVisible; + } + + public boolean getIsVisible() { + return isVisible; + } + + public void setEnabledBy(String enabledBy) { + this.enabledBy = enabledBy; + } + + public String getEnabledBy() { + return enabledBy; + } + + public void setId(String id) { + this.id = id; + } + + public String getId() { + return id; + } + + public ProfileInput addProfileInput(String name) { + + ProfileInput oldInput = getProfileInput(name); + + if (oldInput != null) + return oldInput; + + ProfileInput newInput = new ProfileInput(); + newInput.setInputId(name); + + inputs.add(newInput); + + return newInput; + } + + public ProfileInput getProfileInput(String name) { + + ProfileInput input = null; + + Iterator it = inputs.iterator(); + + ProfileInput curInput = null; + while (it.hasNext()) { + curInput = it.next(); + + if (curInput != null && curInput.getInputId().equals(name)) + break; + } + + return input; + } + + public List getProfileInputsList() { + return inputs; + } + +} \ No newline at end of file diff --git a/base/common/src/com/netscape/certsrv/profile/ProfileDataInfo.java b/base/common/src/com/netscape/certsrv/profile/ProfileDataInfo.java new file mode 100644 index 000000000..22062309d --- /dev/null +++ b/base/common/src/com/netscape/certsrv/profile/ProfileDataInfo.java @@ -0,0 +1,68 @@ +//--- BEGIN COPYRIGHT BLOCK --- +//This program is free software; you can redistribute it and/or modify +//it under the terms of the GNU General Public License as published by +//the Free Software Foundation; version 2 of the License. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License along +//with this program; if not, write to the Free Software Foundation, Inc., +//51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +//(C) 2011 Red Hat, Inc. +//All rights reserved. +//--- END COPYRIGHT BLOCK --- + +package com.netscape.certsrv.profile; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author alee + * + */ +@XmlRootElement(name = "ProfileDataInfo") +@XmlAccessorType(XmlAccessType.FIELD) +public class ProfileDataInfo { + + @XmlElement + protected String profileURL; + + @XmlElement + protected String profileId; + + public ProfileDataInfo() { + // required for JAXB (defaults) + } + + /** + * @return the profileURL + */ + public String getProfileURL() { + return profileURL; + } + + /** + * @param keyURL the profileURL to set + */ + public void setProfileURL(String profileURL) { + this.profileURL = profileURL; + } + + public void setProfileId(String profileId) { + this.profileId = profileId; + } + + /** + * @return the profile ID in the profileURL + */ + public String getProfileId() { + return profileId; + } + +} diff --git a/base/common/src/com/netscape/certsrv/profile/ProfileDataInfos.java b/base/common/src/com/netscape/certsrv/profile/ProfileDataInfos.java new file mode 100644 index 000000000..ed2c11cf7 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/profile/ProfileDataInfos.java @@ -0,0 +1,90 @@ +//--- BEGIN COPYRIGHT BLOCK --- +//This program is free software; you can redistribute it and/or modify +//it under the terms of the GNU General Public License as published by +//the Free Software Foundation; version 2 of the License. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License along +//with this program; if not, write to the Free Software Foundation, Inc., +//51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +//(C) 2012 Red Hat, Inc. +//All rights reserved. +//--- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.profile; + +import java.util.Collection; +import java.util.List; + +import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; + +import com.netscape.certsrv.base.Link; + +@XmlRootElement(name = "ProfileDataInfos") +public class ProfileDataInfos { + + protected Collection profileInfos; + protected List links; + + /** + * @return the ProfileInfos + */ + @XmlElementRef + public Collection getProfileInfos() { + return profileInfos; + } + + /** + * @param ProfileInfos theProfileInfos to set + */ + public void setProfileInfos(Collection profileInfos) { + this.profileInfos = profileInfos; + } + + /** + * @return the links + */ + @XmlElementRef + public List getLinks() { + return links; + } + + /** + * @param links the links to set + */ + public void setLinks(List links) { + this.links = links; + } + + @XmlTransient + public String getNext() { + if (links == null) { + return null; + } + for (Link link : links) { + if ("next".equals(link.getRelationship())) { + return link.getHref(); + } + } + return null; + } + + @XmlTransient + public String getPrevious() { + if (links == null) { + return null; + } + for (Link link : links) { + if ("previous".equals(link.getRelationship())) { + return link.getHref(); + } + } + return null; + } +} diff --git a/base/common/src/com/netscape/certsrv/profile/ProfileInput.java b/base/common/src/com/netscape/certsrv/profile/ProfileInput.java new file mode 100644 index 000000000..64d2aafdb --- /dev/null +++ b/base/common/src/com/netscape/certsrv/profile/ProfileInput.java @@ -0,0 +1,94 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.profile; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlValue; +import javax.xml.bind.annotation.adapters.XmlAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; + +public class ProfileInput { + + public ProfileInput() { + // required for jaxb + } + + @XmlElement + public String getInputId() { + return inputId; + } + + private String inputId; + + @XmlJavaTypeAdapter(InputAttrsAdapter.class) + public Map InputAttrs = new LinkedHashMap(); + + public void setInputAttr(String name, String value) { + InputAttrs.put(name, value); + } + + public void setInputId(String inputId) { + this.inputId = inputId; + } + + public static class InputAttrsAdapter extends XmlAdapter> { + + public InputAttrList marshal(Map map) { + InputAttrList list = new InputAttrList(); + for (Map.Entry entry : map.entrySet()) { + Attribute attribute = new Attribute(); + attribute.name = entry.getKey(); + attribute.value = entry.getValue(); + list.attributes.add(attribute); + } + return list; + } + + public Map unmarshal(InputAttrList list) { + Map map = new LinkedHashMap(); + for (Attribute attribute : list.attributes) { + map.put(attribute.name, attribute.value); + } + return map; + } + } + + public static class InputAttrList { + @XmlElement(name = "InputAttr") + public List attributes = new ArrayList(); + } + + public static class Attribute { + + @XmlAttribute + public String name; + + @XmlValue + public String value; + } + + public Map getAttributes() { + return InputAttrs; + } +} diff --git a/base/common/src/com/netscape/certsrv/profile/ProfileNotFoundException.java b/base/common/src/com/netscape/certsrv/profile/ProfileNotFoundException.java new file mode 100644 index 000000000..7a1c9ea62 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/profile/ProfileNotFoundException.java @@ -0,0 +1,62 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.profile; + +import javax.ws.rs.core.Response; + +import com.netscape.certsrv.base.PKIException; + +public class ProfileNotFoundException extends PKIException { + + private static final long serialVersionUID = -4784839378360933483L; + + public String profileId; + + public ProfileNotFoundException(String profileId) { + this(profileId, "Profile ID " + profileId + " not found"); + } + + public ProfileNotFoundException(String profileId, String message) { + super(Response.Status.NOT_FOUND, message); + this.profileId = profileId; + } + + public ProfileNotFoundException(String profileId, String message, Throwable cause) { + super(Response.Status.NOT_FOUND, message, cause); + this.profileId = profileId; + } + + public ProfileNotFoundException(Data data) { + super(data); + profileId = data.getAttribute("profileId"); + } + + public Data getData() { + Data data = super.getData(); + data.setAttribute("profileId", profileId); + return data; + } + + public String getProfileId() { + return profileId; + } + + public void setRequestId(String profileId) { + this.profileId = profileId; + } +} diff --git a/base/common/src/com/netscape/certsrv/profile/ProfileOutput.java b/base/common/src/com/netscape/certsrv/profile/ProfileOutput.java new file mode 100644 index 000000000..2e25f619d --- /dev/null +++ b/base/common/src/com/netscape/certsrv/profile/ProfileOutput.java @@ -0,0 +1,84 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.profile; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.FIELD) +public class ProfileOutput { + + public ProfileOutput() { + // required for jaxb + } + + @XmlElement + private String outputId; + + @XmlElement(name = "attributes") + private List attrs = new ArrayList(); + + @XmlElement + private String name; + + @XmlElement + private String text; + + public String getOutputId() { + return outputId; + } + + public void setOutputId(String OutputId) { + this.outputId = OutputId; + } + + public List getAttrs() { + return attrs; + } + + public void setAttrs(List attrs) { + this.attrs = attrs; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public void addAttribute(ProfileAttribute attr) { + attrs.add(attr); + } + +} diff --git a/base/common/src/com/netscape/certsrv/profile/ProfilePolicy.java b/base/common/src/com/netscape/certsrv/profile/ProfilePolicy.java new file mode 100644 index 000000000..d5f84f188 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/profile/ProfilePolicy.java @@ -0,0 +1,82 @@ +//--- BEGIN COPYRIGHT BLOCK --- +//This program is free software; you can redistribute it and/or modify +//it under the terms of the GNU General Public License as published by +//the Free Software Foundation; version 2 of the License. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License along +//with this program; if not, write to the Free Software Foundation, Inc., +//51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +//(C) 2012 Red Hat, Inc. +//All rights reserved. +//--- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.profile; + +import java.io.ByteArrayOutputStream; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +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; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.FIELD) +public class ProfilePolicy { + @XmlAttribute + private String id = null; + + @XmlElement + private PolicyDefault def = null; + + @XmlElement + private PolicyConstraint constraint = null; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public PolicyDefault getDef() { + return def; + } + + public void setDef(PolicyDefault def) { + this.def = def; + } + + public PolicyConstraint getConstraint() { + return constraint; + } + + public void setConstraint(PolicyConstraint constraint) { + this.constraint = constraint; + } + + public String toString() { + try { + JAXBContext context = JAXBContext.newInstance(ProfilePolicy.class); + Marshaller marshaller = context.createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + + marshaller.marshal(this, stream); + return stream.toString(); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + +} diff --git a/base/common/src/com/netscape/certsrv/profile/ProfilePolicySet.java b/base/common/src/com/netscape/certsrv/profile/ProfilePolicySet.java new file mode 100644 index 000000000..6c1dc2b9d --- /dev/null +++ b/base/common/src/com/netscape/certsrv/profile/ProfilePolicySet.java @@ -0,0 +1,50 @@ +//--- BEGIN COPYRIGHT BLOCK --- +//This program is free software; you can redistribute it and/or modify +//it under the terms of the GNU General Public License as published by +//the Free Software Foundation; version 2 of the License. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License along +//with this program; if not, write to the Free Software Foundation, Inc., +//51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +//(C) 2012 Red Hat, Inc. +//All rights reserved. +//--- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.profile; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.FIELD) +public class ProfilePolicySet { + @XmlElement + protected List policies = new ArrayList(); + + public List getPolicies() { + return policies; + } + + public void setPolicies(List policies) { + this.policies = policies; + } + + public void addPolicy(ProfilePolicy policy) { + policies.add(policy); + } + + public void removePolicy(ProfilePolicy policy) { + policies.remove(policy); + } + +} diff --git a/base/common/src/com/netscape/certsrv/profile/ProfileResource.java b/base/common/src/com/netscape/certsrv/profile/ProfileResource.java new file mode 100644 index 000000000..6dadef560 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/profile/ProfileResource.java @@ -0,0 +1,43 @@ +package com.netscape.certsrv.profile; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + + +@Path("agent/profiles") +public interface ProfileResource { + + @GET + @Path("{id}") + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public ProfileData retrieveProfile(@PathParam("id") String id); + + @GET + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public ProfileDataInfos listProfiles(); + + /** + * Used to retrieve a key + * + * @param data + * @return + */ + + /* + @POST + @Path("retrieve") + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + public ProfileData retrieveProfile(ProfileRetrievalRequestData request); + + // retrieval - used to test integration with a browser + @POST + @Path("retrieve") + @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) + @Consumes({ MediaType.APPLICATION_FORM_URLENCODED }) + public ProfileData retrievProfile(MultivaluedMap form); + */ +} \ No newline at end of file diff --git a/base/common/src/com/netscape/certsrv/profile/ProfileRetrievalRequest.java b/base/common/src/com/netscape/certsrv/profile/ProfileRetrievalRequest.java new file mode 100644 index 000000000..608686b79 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/profile/ProfileRetrievalRequest.java @@ -0,0 +1,67 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2011 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- + +/** + * + */ +package com.netscape.certsrv.profile; + +import javax.ws.rs.core.MultivaluedMap; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author alee + * + */ +@XmlRootElement(name = "ProfileRetrievalRequest") +@XmlAccessorType(XmlAccessType.FIELD) +public class ProfileRetrievalRequest { + + private static final String PROFILE_ID = "profileId"; + + @XmlElement + protected String profileId; + + public ProfileRetrievalRequest() { + // required for JAXB (defaults) + } + + public ProfileRetrievalRequest(MultivaluedMap form) { + if (form.containsKey(PROFILE_ID)) { + profileId = form.getFirst(PROFILE_ID); + } + } + + /** + * @return the ProfileId + */ + public String getProfileId() { + return profileId; + } + + /** + * @param ProfileId the ProfileId to set + */ + public void setProfileId(String profileId) { + this.profileId = profileId; + } + +} \ No newline at end of file -- cgit