summaryrefslogtreecommitdiffstats
path: root/base/common/src/com/netscape/certsrv/tps
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2013-09-19 10:15:02 -0400
committerEndi S. Dewata <edewata@redhat.com>2013-09-20 12:37:08 -0400
commit5874cad1abe832a4a74cb37a4c22f0e18cf9bd8e (patch)
treead0e88129530f4abcfb588a516c17ab5e0573eb9 /base/common/src/com/netscape/certsrv/tps
parent4c17e821a99318a1cf62ca0862ce9ee404ea5f6a (diff)
downloadpki-5874cad1abe832a4a74cb37a4c22f0e18cf9bd8e.tar.gz
pki-5874cad1abe832a4a74cb37a4c22f0e18cf9bd8e.tar.xz
pki-5874cad1abe832a4a74cb37a4c22f0e18cf9bd8e.zip
Added TPS config resource.
A new REST service and clients have been added to manage the TPS configuration in CS.cfg. When the configuration is updated, the previous configuration will be stored as a backup. Ticket #652
Diffstat (limited to 'base/common/src/com/netscape/certsrv/tps')
-rw-r--r--base/common/src/com/netscape/certsrv/tps/TPSClient.java2
-rw-r--r--base/common/src/com/netscape/certsrv/tps/config/ConfigClient.java60
-rw-r--r--base/common/src/com/netscape/certsrv/tps/config/ConfigCollection.java65
-rw-r--r--base/common/src/com/netscape/certsrv/tps/config/ConfigData.java231
-rw-r--r--base/common/src/com/netscape/certsrv/tps/config/ConfigResource.java53
5 files changed, 411 insertions, 0 deletions
diff --git a/base/common/src/com/netscape/certsrv/tps/TPSClient.java b/base/common/src/com/netscape/certsrv/tps/TPSClient.java
index 8381b1ac2..e30858bfe 100644
--- a/base/common/src/com/netscape/certsrv/tps/TPSClient.java
+++ b/base/common/src/com/netscape/certsrv/tps/TPSClient.java
@@ -25,6 +25,7 @@ import com.netscape.certsrv.group.GroupClient;
import com.netscape.certsrv.logging.ActivityClient;
import com.netscape.certsrv.tps.authenticator.AuthenticatorClient;
import com.netscape.certsrv.tps.cert.TPSCertClient;
+import com.netscape.certsrv.tps.config.ConfigClient;
import com.netscape.certsrv.tps.connection.ConnectionClient;
import com.netscape.certsrv.tps.token.TokenClient;
import com.netscape.certsrv.user.UserClient;
@@ -42,6 +43,7 @@ public class TPSClient extends SubsystemClient {
public void init() throws URISyntaxException {
addClient(new ActivityClient(client, name));
addClient(new AuthenticatorClient(client, name));
+ addClient(new ConfigClient(client, name));
addClient(new ConnectionClient(client, name));
addClient(new GroupClient(client, name));
addClient(new TokenClient(client, name));
diff --git a/base/common/src/com/netscape/certsrv/tps/config/ConfigClient.java b/base/common/src/com/netscape/certsrv/tps/config/ConfigClient.java
new file mode 100644
index 000000000..c3876bf83
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/tps/config/ConfigClient.java
@@ -0,0 +1,60 @@
+//--- 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) 2013 Red Hat, Inc.
+//All rights reserved.
+//--- END COPYRIGHT BLOCK ---
+package com.netscape.certsrv.tps.config;
+
+import java.net.URISyntaxException;
+
+import org.jboss.resteasy.client.ClientResponse;
+
+import com.netscape.certsrv.client.Client;
+import com.netscape.certsrv.client.PKIClient;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class ConfigClient extends Client {
+
+ public ConfigResource resource;
+
+ public ConfigClient(PKIClient client) throws URISyntaxException {
+ this(client, client.getSubsystem());
+ }
+
+ public ConfigClient(PKIClient client, String subsystem) throws URISyntaxException {
+ super(client, subsystem, "config");
+ init();
+ }
+
+ public void init() throws URISyntaxException {
+ resource = createProxy(ConfigResource.class);
+ }
+
+ public ConfigCollection findConfigs() {
+ return resource.findConfigs();
+ }
+
+ public ConfigData getConfig(String configID) {
+ return resource.getConfig(configID);
+ }
+
+ public ConfigData updateConfig(String configID, ConfigData configData) {
+ @SuppressWarnings("unchecked")
+ ClientResponse<ConfigData> response = (ClientResponse<ConfigData>)resource.updateConfig(configID, configData);
+ return client.getEntity(response);
+ }
+}
diff --git a/base/common/src/com/netscape/certsrv/tps/config/ConfigCollection.java b/base/common/src/com/netscape/certsrv/tps/config/ConfigCollection.java
new file mode 100644
index 000000000..a36f61fd1
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/tps/config/ConfigCollection.java
@@ -0,0 +1,65 @@
+// --- 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) 2013 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.certsrv.tps.config;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementRef;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.jboss.resteasy.plugins.providers.atom.Link;
+
+
+/**
+ * @author Endi S. Dewata
+ */
+@XmlRootElement(name="Configurations")
+public class ConfigCollection {
+
+ Collection<ConfigData> configs = new ArrayList<ConfigData>();
+ Collection<Link> links = new ArrayList<Link>();
+
+ @XmlElementRef
+ public Collection<ConfigData> getConfigs() {
+ return configs;
+ }
+
+ public void setConfigs(Collection<ConfigData> configs) {
+ this.configs = configs;
+ }
+
+ public void addConfig(ConfigData configData) {
+ configs.add(configData);
+ }
+
+ @XmlElement(name="Link")
+ public Collection<Link> getLinks() {
+ return links;
+ }
+
+ public void setLink(Collection<Link> links) {
+ this.links = links;
+ }
+
+ public void addLink(Link link) {
+ links.add(link);
+ }
+}
diff --git a/base/common/src/com/netscape/certsrv/tps/config/ConfigData.java b/base/common/src/com/netscape/certsrv/tps/config/ConfigData.java
new file mode 100644
index 000000000..1b3688f5e
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/tps/config/ConfigData.java
@@ -0,0 +1,231 @@
+// --- 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) 2013 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.certsrv.tps.config;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlValue;
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+import org.jboss.resteasy.plugins.providers.atom.Link;
+
+/**
+ * @author Endi S. Dewata
+ */
+@XmlRootElement(name="Configuration")
+public class ConfigData {
+
+ public static Marshaller marshaller;
+ public static Unmarshaller unmarshaller;
+
+ static {
+ try {
+ marshaller = JAXBContext.newInstance(ConfigData.class).createMarshaller();
+ marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+ unmarshaller = JAXBContext.newInstance(ConfigData.class).createUnmarshaller();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ String id;
+ String displayName;
+ Map<String, String> properties = new LinkedHashMap<String, String>();
+ Link link;
+
+ @XmlAttribute(name="id")
+ public String getID() {
+ return id;
+ }
+
+ public void setID(String id) {
+ this.id = id;
+ }
+
+ @XmlElement(name="DisplayName")
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ public void setDisplayName(String displayName) {
+ this.displayName = displayName;
+ }
+
+ @XmlElement(name="Properties")
+ @XmlJavaTypeAdapter(MapAdapter.class)
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Map<String, String> properties) {
+ this.properties.clear();
+ this.properties.putAll(properties);
+ }
+
+ public Collection<String> getPropertyNames() {
+ return properties.keySet();
+ }
+
+ public String getProperty(String name) {
+ return properties.get(name);
+ }
+
+ public void setProperty(String name, String value) {
+ properties.put(name, value);
+ }
+
+ public String removeProperty(String name) {
+ return properties.remove(name);
+ }
+
+ public static class MapAdapter extends XmlAdapter<PropertyList, Map<String, String>> {
+
+ public PropertyList marshal(Map<String, String> map) {
+ PropertyList list = new PropertyList();
+ for (Map.Entry<String, String> entry : map.entrySet()) {
+ Property property = new Property();
+ property.name = entry.getKey();
+ property.value = entry.getValue();
+ list.properties.add(property);
+ }
+ return list;
+ }
+
+ public Map<String, String> unmarshal(PropertyList list) {
+ Map<String, String> map = new LinkedHashMap<String, String>();
+ for (Property property : list.properties) {
+ map.put(property.name, property.value);
+ }
+ return map;
+ }
+ }
+
+ public static class PropertyList {
+ @XmlElement(name="Property")
+ public List<Property> properties = new ArrayList<Property>();
+ }
+
+ public static class Property {
+
+ @XmlAttribute
+ public String name;
+
+ @XmlValue
+ public String value;
+ }
+
+ @XmlElement(name="Link")
+ public Link getLink() {
+ return link;
+ }
+
+ public void setLink(Link link) {
+ this.link = link;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((displayName == null) ? 0 : displayName.hashCode());
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ result = prime * result + ((link == null) ? 0 : link.hashCode());
+ result = prime * result + ((properties == null) ? 0 : properties.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;
+ ConfigData other = (ConfigData) obj;
+ if (displayName == null) {
+ if (other.displayName != null)
+ return false;
+ } else if (!displayName.equals(other.displayName))
+ return false;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ if (link == null) {
+ if (other.link != null)
+ return false;
+ } else if (!link.equals(other.link))
+ return false;
+ if (properties == null) {
+ if (other.properties != null)
+ return false;
+ } else if (!properties.equals(other.properties))
+ return false;
+ return true;
+ }
+
+ public String toString() {
+ try {
+ StringWriter sw = new StringWriter();
+ marshaller.marshal(this, sw);
+ return sw.toString();
+
+ } catch (Exception e) {
+ return super.toString();
+ }
+ }
+
+ public static ConfigData valueOf(String string) throws Exception {
+ try {
+ return (ConfigData)unmarshaller.unmarshal(new StringReader(string));
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ public static void main(String args[]) throws Exception {
+
+ ConfigData before = new ConfigData();
+ before.setID("test");
+ before.setDisplayName("Test Config");
+ before.setProperty("param1", "value1");
+ before.setProperty("param2", "value2");
+
+ String string = before.toString();
+ System.out.println(string);
+
+ ConfigData after = ConfigData.valueOf(string);
+ System.out.println(before.equals(after));
+ }
+}
diff --git a/base/common/src/com/netscape/certsrv/tps/config/ConfigResource.java b/base/common/src/com/netscape/certsrv/tps/config/ConfigResource.java
new file mode 100644
index 000000000..a15730a4b
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/tps/config/ConfigResource.java
@@ -0,0 +1,53 @@
+// --- 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) 2013 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+package com.netscape.certsrv.tps.config;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.jboss.resteasy.annotations.ClientResponseType;
+
+
+/**
+ * @author Endi S. Dewata
+ */
+@Path("configs")
+public interface ConfigResource {
+
+ @GET
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public ConfigCollection findConfigs();
+
+ @GET
+ @Path("{configID}")
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public ConfigData getConfig(@PathParam("configID") String configID);
+
+ @PUT
+ @Path("{configID}")
+ @ClientResponseType(entityType=ConfigData.class)
+ @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response updateConfig(@PathParam("configID") String configID, ConfigData configData);
+}