summaryrefslogtreecommitdiffstats
path: root/base/common/src/com/netscape/certsrv/tps
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2013-10-01 17:39:29 -0400
committerEndi S. Dewata <edewata@redhat.com>2013-10-01 19:26:24 -0400
commit7c0fb95b77f0f91c572e0242c09a88605497a455 (patch)
treedd387f97194f17d5f26d089cd72e0f81194e73ab /base/common/src/com/netscape/certsrv/tps
parentbcf463c6afb042543fec93759c02211f6d5c0a60 (diff)
downloadpki-7c0fb95b77f0f91c572e0242c09a88605497a455.tar.gz
pki-7c0fb95b77f0f91c572e0242c09a88605497a455.tar.xz
pki-7c0fb95b77f0f91c572e0242c09a88605497a455.zip
Added TPS profile mapping resource.
A new REST service and clients have been added to manage the profile mappings in the TPS configuration file. 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/profile/ProfileMappingClient.java70
-rw-r--r--base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingCollection.java38
-rw-r--r--base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingData.java232
-rw-r--r--base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingResource.java71
5 files changed, 413 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 b35893505..fcd87f182 100644
--- a/base/common/src/com/netscape/certsrv/tps/TPSClient.java
+++ b/base/common/src/com/netscape/certsrv/tps/TPSClient.java
@@ -27,6 +27,7 @@ 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.profile.ProfileMappingClient;
import com.netscape.certsrv.tps.token.TokenClient;
import com.netscape.certsrv.user.UserClient;
@@ -47,6 +48,7 @@ public class TPSClient extends SubsystemClient {
addClient(new ConfigClient(client, name));
addClient(new ConnectionClient(client, name));
addClient(new GroupClient(client, name));
+ addClient(new ProfileMappingClient(client, name));
addClient(new TokenClient(client, name));
addClient(new UserClient(client, name));
}
diff --git a/base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingClient.java b/base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingClient.java
new file mode 100644
index 000000000..dd02825c8
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingClient.java
@@ -0,0 +1,70 @@
+//--- 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.profile;
+
+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 ProfileMappingClient extends Client {
+
+ public ProfileMappingResource resource;
+
+ public ProfileMappingClient(PKIClient client) throws URISyntaxException {
+ this(client, client.getSubsystem());
+ }
+
+ public ProfileMappingClient(PKIClient client, String subsystem) throws URISyntaxException {
+ super(client, subsystem, "profile-mapping");
+ init();
+ }
+
+ public void init() throws URISyntaxException {
+ resource = createProxy(ProfileMappingResource.class);
+ }
+
+ public ProfileMappingCollection findProfileMappings(Integer start, Integer size) {
+ return resource.findProfileMappings(start, size);
+ }
+
+ public ProfileMappingData getProfileMapping(String profileMappingID) {
+ return resource.getProfileMapping(profileMappingID);
+ }
+
+ public ProfileMappingData addProfileMapping(ProfileMappingData profileMappingData) {
+ @SuppressWarnings("unchecked")
+ ClientResponse<ProfileMappingData> response = (ClientResponse<ProfileMappingData>)resource.addProfileMapping(profileMappingData);
+ return client.getEntity(response);
+ }
+
+ public ProfileMappingData updateProfileMapping(String profileMappingID, ProfileMappingData profileMappingData) {
+ @SuppressWarnings("unchecked")
+ ClientResponse<ProfileMappingData> response = (ClientResponse<ProfileMappingData>)resource.updateProfileMapping(profileMappingID, profileMappingData);
+ return client.getEntity(response);
+ }
+
+ public void removeProfileMapping(String profileMappingID) {
+ resource.removeProfileMapping(profileMappingID);
+ }
+}
diff --git a/base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingCollection.java b/base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingCollection.java
new file mode 100644
index 000000000..9f3bbbb94
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingCollection.java
@@ -0,0 +1,38 @@
+// --- 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.profile;
+
+import java.util.Collection;
+
+import javax.xml.bind.annotation.XmlElementRef;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import com.netscape.certsrv.base.DataCollection;
+
+/**
+ * @author Endi S. Dewata
+ */
+@XmlRootElement(name="ProfileMappings")
+public class ProfileMappingCollection extends DataCollection<ProfileMappingData> {
+
+ @XmlElementRef
+ public Collection<ProfileMappingData> getEntries() {
+ return super.getEntries();
+ }
+}
diff --git a/base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingData.java b/base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingData.java
new file mode 100644
index 000000000..2ca955b4e
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingData.java
@@ -0,0 +1,232 @@
+// --- 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.profile;
+
+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="ProfileMapping")
+public class ProfileMappingData {
+
+ public static Marshaller marshaller;
+ public static Unmarshaller unmarshaller;
+
+ static {
+ try {
+ marshaller = JAXBContext.newInstance(ProfileMappingData.class).createMarshaller();
+ marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+ unmarshaller = JAXBContext.newInstance(ProfileMappingData.class).createUnmarshaller();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ String id;
+ String status;
+ 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="Status")
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ @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 + ((id == null) ? 0 : id.hashCode());
+ result = prime * result + ((link == null) ? 0 : link.hashCode());
+ result = prime * result + ((properties == null) ? 0 : properties.hashCode());
+ result = prime * result + ((status == null) ? 0 : status.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;
+ ProfileMappingData other = (ProfileMappingData) obj;
+ 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;
+ if (status == null) {
+ if (other.status != null)
+ return false;
+ } else if (!status.equals(other.status))
+ 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 ProfileMappingData valueOf(String string) throws Exception {
+ try {
+ return (ProfileMappingData)unmarshaller.unmarshal(new StringReader(string));
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ public static void main(String args[]) throws Exception {
+
+ ProfileMappingData before = new ProfileMappingData();
+ before.setID("profileMapping1");
+ before.setStatus("ENABLED");
+ before.setProperty("param1", "value1");
+ before.setProperty("param2", "value2");
+
+ String string = before.toString();
+ System.out.println(string);
+
+ ProfileMappingData after = ProfileMappingData.valueOf(string);
+ System.out.println(before.equals(after));
+ }
+}
diff --git a/base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingResource.java b/base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingResource.java
new file mode 100644
index 000000000..20e360310
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingResource.java
@@ -0,0 +1,71 @@
+// --- 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.profile;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.jboss.resteasy.annotations.ClientResponseType;
+
+
+/**
+ * @author Endi S. Dewata
+ */
+@Path("profile-mappings")
+public interface ProfileMappingResource {
+
+ @GET
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public ProfileMappingCollection findProfileMappings(
+ @QueryParam("start") Integer start,
+ @QueryParam("size") Integer size);
+
+ @GET
+ @Path("{profileMappingID}")
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public ProfileMappingData getProfileMapping(@PathParam("profileMappingID") String profileMappingID);
+
+ @POST
+ @ClientResponseType(entityType=ProfileMappingData.class)
+ @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response addProfileMapping(ProfileMappingData profileMappingData);
+
+ @PUT
+ @Path("{profileMappingID}")
+ @ClientResponseType(entityType=ProfileMappingData.class)
+ @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response updateProfileMapping(
+ @PathParam("profileMappingID") String profileMappingID,
+ ProfileMappingData profileMappingData);
+
+ @DELETE
+ @Path("{profileMappingID}")
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public void removeProfileMapping(@PathParam("profileMappingID") String profileMappingID);
+}