diff options
author | Ade Lee <alee@redhat.com> | 2015-09-24 23:36:43 -0400 |
---|---|---|
committer | Ade Lee <alee@redhat.com> | 2015-09-27 10:37:01 -0400 |
commit | d8f9c77a62a7bfea82e892f8ecb309630826fed5 (patch) | |
tree | 3f37cb2f1972db3f36d2d793f64acf6f2cb1c926 /base/common/src | |
parent | 058f1cf1e657ba441f1fcd590fa4cec8ca96e5b0 (diff) | |
download | pki-d8f9c77a62a7bfea82e892f8ecb309630826fed5.tar.gz pki-d8f9c77a62a7bfea82e892f8ecb309630826fed5.tar.xz pki-d8f9c77a62a7bfea82e892f8ecb309630826fed5.zip |
Added Features REST API resource
This will help us track whether or not a server has a feature
either offered or enabled. Ultimately, it could be used by
an admin to enable or disable features.
The Java client is not included in this commit. Will add in
a subsequent commit.
Diffstat (limited to 'base/common/src')
-rw-r--r-- | base/common/src/com/netscape/certsrv/system/Feature.java | 151 | ||||
-rw-r--r-- | base/common/src/com/netscape/certsrv/system/FeatureResource.java | 44 |
2 files changed, 195 insertions, 0 deletions
diff --git a/base/common/src/com/netscape/certsrv/system/Feature.java b/base/common/src/com/netscape/certsrv/system/Feature.java new file mode 100644 index 000000000..59b88d2f6 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/system/Feature.java @@ -0,0 +1,151 @@ +// --- 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) 2015 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.system; + +import java.io.StringReader; +import java.io.StringWriter; + +import javax.xml.bind.JAXBContext; +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.XmlRootElement; + +@XmlRootElement(name="Feature") +@XmlAccessorType(XmlAccessType.NONE) +public class Feature { + + String id; + String description; + String version; + boolean enabled; + + @XmlAttribute(name="id") + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + @XmlAttribute(name="description") + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @XmlAttribute(name="enabled") + public boolean getEnabled() { + return enabled; + } + + public void setEnabled(String enabled) { + this.enabled = enabled.equalsIgnoreCase("true"); + } + + @XmlAttribute(name="version") + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String toString() { + try { + StringWriter sw = new StringWriter(); + Marshaller marshaller = JAXBContext.newInstance(Feature.class).createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + marshaller.marshal(this, sw); + return sw.toString(); + + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static Feature valueOf(String string) throws Exception { + try { + Unmarshaller unmarshaller = JAXBContext.newInstance(Feature.class).createUnmarshaller(); + return (Feature)unmarshaller.unmarshal(new StringReader(string)); + } catch (Exception e) { + return null; + } + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + (enabled ? 1231 : 1237); + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((version == null) ? 0 : version.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; + Feature other = (Feature) obj; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (enabled != other.enabled) + return false; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + return true; + } + + public static void main(String args[]) throws Exception { + Feature before = new Feature(); + before.setId("authority"); + before.setEnabled("true"); + before.setDescription("Subordinate CA Feature"); + before.setVersion("1.0"); + + String string = before.toString(); + System.out.println(string); + + Feature after = Feature.valueOf(string); + System.out.println(before.equals(after)); + } +}
\ No newline at end of file diff --git a/base/common/src/com/netscape/certsrv/system/FeatureResource.java b/base/common/src/com/netscape/certsrv/system/FeatureResource.java new file mode 100644 index 000000000..16413f755 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/system/FeatureResource.java @@ -0,0 +1,44 @@ +// --- 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) 2015 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.system; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Response; + +import org.jboss.resteasy.annotations.ClientResponseType; + +/** + * @author alee + */ +@Path("config/features") +public interface FeatureResource { + + @GET + @ClientResponseType(entityType=Feature.class) + // @ACLMapping("features.list") + public Response listFeatures(); + + @GET + @Path("{id}") + @ClientResponseType(entityType=Feature.class) + // @ACLMapping("feature.read") + public Response getFeature(@PathParam("id") String id); + +}
\ No newline at end of file |