summaryrefslogtreecommitdiffstats
path: root/base/common/src/com/netscape/certsrv/user
diff options
context:
space:
mode:
authorEndi Sukma Dewata <edewata@redhat.com>2012-05-19 11:05:20 -0500
committerEndi Sukma Dewata <edewata@redhat.com>2012-05-31 12:01:36 -0500
commitae03c6bdf570cb36a1b139aeb0e467081665459e (patch)
treef586fe5e5c3e4e1c4c1eb73f184d7bc4438296a5 /base/common/src/com/netscape/certsrv/user
parent83bca19f80ea0deef4034e80a559ffa88da44a1a (diff)
downloadpki-ae03c6bdf570cb36a1b139aeb0e467081665459e.tar.gz
pki-ae03c6bdf570cb36a1b139aeb0e467081665459e.tar.xz
pki-ae03c6bdf570cb36a1b139aeb0e467081665459e.zip
Added user REST service.
The user REST service is based on UsrGrpAdminServlet. It provides an interface to manage users and user certificates. Ticket #160
Diffstat (limited to 'base/common/src/com/netscape/certsrv/user')
-rw-r--r--base/common/src/com/netscape/certsrv/user/UserCertCollection.java60
-rw-r--r--base/common/src/com/netscape/certsrv/user/UserCertData.java254
-rw-r--r--base/common/src/com/netscape/certsrv/user/UserCertResource.java63
-rw-r--r--base/common/src/com/netscape/certsrv/user/UserCollection.java65
-rw-r--r--base/common/src/com/netscape/certsrv/user/UserData.java239
-rw-r--r--base/common/src/com/netscape/certsrv/user/UserResource.java69
6 files changed, 750 insertions, 0 deletions
diff --git a/base/common/src/com/netscape/certsrv/user/UserCertCollection.java b/base/common/src/com/netscape/certsrv/user/UserCertCollection.java
new file mode 100644
index 000000000..a395ed73c
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/user/UserCertCollection.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) 2012 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.certsrv.user;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.jboss.resteasy.plugins.providers.atom.Link;
+
+/**
+ * @author Endi S. Dewata
+ */
+@XmlRootElement(name="UserCerts")
+public class UserCertCollection {
+
+ List<UserCertData> certs = new ArrayList<UserCertData>();
+ Collection<Link> links = new ArrayList<Link>();
+
+ @XmlElement(name="Cert")
+ public Collection<UserCertData> getCerts() {
+ return certs;
+ }
+
+ public void addCert(UserCertData cert) {
+ certs.add(cert);
+ }
+
+ @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/user/UserCertData.java b/base/common/src/com/netscape/certsrv/user/UserCertData.java
new file mode 100644
index 000000000..d77e1dc8b
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/user/UserCertData.java
@@ -0,0 +1,254 @@
+// --- 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.user;
+
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.math.BigInteger;
+import java.util.StringTokenizer;
+
+import javax.ws.rs.FormParam;
+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 org.jboss.resteasy.plugins.providers.atom.Link;
+
+import com.netscape.certsrv.common.Constants;
+
+/**
+ * @author Endi S. Dewata
+ */
+@XmlRootElement(name="UserCert")
+public class UserCertData {
+
+ public static Marshaller marshaller;
+ public static Unmarshaller unmarshaller;
+
+ static {
+ try {
+ marshaller = JAXBContext.newInstance(UserCertData.class).createMarshaller();
+ marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+ unmarshaller = JAXBContext.newInstance(UserCertData.class).createUnmarshaller();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ Integer version;
+ BigInteger serialNumber;
+ String issuerDN;
+ String subjectDN;
+ String prettyPrint;
+ String encoded;
+
+ Link link;
+
+ @XmlAttribute(name="id")
+ public String getID() {
+ if (version == null && serialNumber == null && issuerDN == null && subjectDN == null) {
+ return null;
+ } else {
+ return version + ";" + serialNumber + ";" + issuerDN + ";" + subjectDN;
+ }
+ }
+
+ public void setID(String id) {
+ StringTokenizer st = new StringTokenizer(id, ";");
+ version = Integer.valueOf(st.nextToken());
+ serialNumber = new BigInteger(st.nextToken());
+ issuerDN = st.nextToken();
+ subjectDN = st.nextToken();
+ }
+
+ @XmlElement(name="Version")
+ public Integer getVersion() {
+ return version;
+ }
+
+ public void setVersion(Integer version) {
+ this.version = version;
+ }
+
+ @XmlElement(name="SerialNumber")
+ public BigInteger getSerialNumber() {
+ return serialNumber;
+ }
+
+ public void setSerialNumber(BigInteger serialNumber) {
+ this.serialNumber = serialNumber;
+ }
+
+ @XmlElement(name="IssuerDN")
+ public String getIssuerDN() {
+ return issuerDN;
+ }
+
+ public void setIssuerDN(String issuerDN) {
+ this.issuerDN = issuerDN;
+ }
+
+ @XmlElement(name="SubjectDN")
+ public String getSubjectDN() {
+ return subjectDN;
+ }
+
+ public void setSubjectDN(String subjectDN) {
+ this.subjectDN = subjectDN;
+ }
+
+ @XmlElement(name="PrettyPrint")
+ public String getPrettyPrint() {
+ return prettyPrint;
+ }
+
+ public void setPrettyPrint(String prettyPrint) {
+ this.prettyPrint = prettyPrint;
+ }
+
+ @FormParam(Constants.PR_USER_CERT)
+ @XmlElement(name="Encoded")
+ public String getEncoded() {
+ return encoded;
+ }
+
+ public void setEncoded(String encoded) {
+ this.encoded = encoded;
+ }
+
+ @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 + ((encoded == null) ? 0 : encoded.hashCode());
+ result = prime * result + ((issuerDN == null) ? 0 : issuerDN.hashCode());
+ result = prime * result + ((prettyPrint == null) ? 0 : prettyPrint.hashCode());
+ result = prime * result + ((serialNumber == null) ? 0 : serialNumber.hashCode());
+ result = prime * result + ((subjectDN == null) ? 0 : subjectDN.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;
+ UserCertData other = (UserCertData) obj;
+ if (encoded == null) {
+ if (other.encoded != null)
+ return false;
+ } else if (!encoded.equals(other.encoded))
+ return false;
+ if (issuerDN == null) {
+ if (other.issuerDN != null)
+ return false;
+ } else if (!issuerDN.equals(other.issuerDN))
+ return false;
+ if (prettyPrint == null) {
+ if (other.prettyPrint != null)
+ return false;
+ } else if (!prettyPrint.equals(other.prettyPrint))
+ return false;
+ if (serialNumber == null) {
+ if (other.serialNumber != null)
+ return false;
+ } else if (!serialNumber.equals(other.serialNumber))
+ return false;
+ if (subjectDN == null) {
+ if (other.subjectDN != null)
+ return false;
+ } else if (!subjectDN.equals(other.subjectDN))
+ return false;
+ if (version == null) {
+ if (other.version != null)
+ return false;
+ } else if (!version.equals(other.version))
+ 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 UserCertData valueOf(String string) throws Exception {
+ try {
+ return (UserCertData)unmarshaller.unmarshal(new StringReader(string));
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ public static void main(String args[]) throws Exception {
+
+ StringWriter sw = new StringWriter();
+ PrintWriter out = new PrintWriter(sw, true);
+
+ out.println("-----BEGIN CERTIFICATE-----");
+ out.println("MIIB/zCCAWgCCQCtpWH58pqsejANBgkqhkiG9w0BAQUFADBEMRQwEgYDVQQKDAtF");
+ out.println("WEFNUExFLUNPTTEYMBYGCgmSJomT8ixkAQEMCHRlc3R1c2VyMRIwEAYDVQQDDAlU");
+ out.println("ZXN0IFVzZXIwHhcNMTIwNTE0MTcxNzI3WhcNMTMwNTE0MTcxNzI3WjBEMRQwEgYD");
+ out.println("VQQKDAtFWEFNUExFLUNPTTEYMBYGCgmSJomT8ixkAQEMCHRlc3R1c2VyMRIwEAYD");
+ out.println("VQQDDAlUZXN0IFVzZXIwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAKmmiPJp");
+ out.println("Agh/gPUAZjfgJ3a8QiHvpMzZ/hZy1FVP3+2sNhCkMv+D/I8Y7AsrbJGxxvD7bTDm");
+ out.println("zQYtYx2ryGyOgY7KBRxEj/IrNVHIkJMYq5G/aIU4FAzpc6ntNSwUQBYUAamfK8U6");
+ out.println("Wo4Cp6rLePXIDE6sfGn3VX6IeSJ8U2V+vwtzAgMBAAEwDQYJKoZIhvcNAQEFBQAD");
+ out.println("gYEAY9bjcD/7Z+oX6gsJtX6Rd79E7X5IBdOdArYzHNE4vjdaQrZw6oCxrY8ffpKC");
+ out.println("0T0q5PX9I7er+hx/sQjGPMrJDEN+vFBSNrZE7sTeLRgkyiqGvChSyuG05GtGzXO4");
+ out.println("bFBr+Gwk2VF2wJvOhTXU2hN8sfkkd9clzIXuL8WCDhWk1bY=");
+ out.println("-----END CERTIFICATE-----");
+
+ UserCertData before = new UserCertData();
+ before.setVersion(1);
+ before.setSerialNumber(new BigInteger("12512514865863765114"));
+ before.setIssuerDN("CN=Test User,UID=testuser,O=EXAMPLE-COM");
+ before.setSubjectDN("CN=Test User,UID=testuser,O=EXAMPLE-COM");
+ before.setEncoded(sw.toString());
+
+ String string = before.toString();
+ System.out.println(string);
+
+ UserCertData after = UserCertData.valueOf(string);
+ System.out.println(before.equals(after));
+ }
+}
diff --git a/base/common/src/com/netscape/certsrv/user/UserCertResource.java b/base/common/src/com/netscape/certsrv/user/UserCertResource.java
new file mode 100644
index 000000000..b9339bc33
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/user/UserCertResource.java
@@ -0,0 +1,63 @@
+// --- 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.user;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+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("/users/{userID}/certs")
+public interface UserCertResource {
+
+ @GET
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public UserCertCollection findUserCerts(
+ @PathParam("userID") String userID,
+ @QueryParam("start") Integer start,
+ @QueryParam("size") Integer size);
+
+
+ @POST
+ @ClientResponseType(entityType=UserCertData.class)
+ @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response addUserCert(@PathParam("userID") String userID, UserCertData userCertData);
+
+ @GET
+ @Path("/{certID}")
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public UserCertData getUserCert(@PathParam("userID") String userID, @PathParam("certID") String certID);
+
+ @DELETE
+ @Path("/{certID}")
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public void removeUserCert(@PathParam("userID") String userID, @PathParam("certID") String certID);
+}
diff --git a/base/common/src/com/netscape/certsrv/user/UserCollection.java b/base/common/src/com/netscape/certsrv/user/UserCollection.java
new file mode 100644
index 000000000..d92ecc208
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/user/UserCollection.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) 2012 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.certsrv.user;
+
+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="Users")
+public class UserCollection {
+
+ Collection<UserData> users = new ArrayList<UserData>();
+ Collection<Link> links = new ArrayList<Link>();
+
+ @XmlElementRef
+ public Collection<UserData> getUsers() {
+ return users;
+ }
+
+ public void setUsers(Collection<UserData> users) {
+ this.users = users;
+ }
+
+ public void addUser(UserData userData) {
+ users.add(userData);
+ }
+
+ @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/user/UserData.java b/base/common/src/com/netscape/certsrv/user/UserData.java
new file mode 100644
index 000000000..b62d02231
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/user/UserData.java
@@ -0,0 +1,239 @@
+// --- 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.user;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import javax.ws.rs.FormParam;
+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 org.jboss.resteasy.plugins.providers.atom.Link;
+
+import com.netscape.certsrv.common.Constants;
+
+/**
+ * @author Endi S. Dewata
+ */
+@XmlRootElement(name="User")
+public class UserData {
+
+ public static Marshaller marshaller;
+ public static Unmarshaller unmarshaller;
+
+ static {
+ try {
+ marshaller = JAXBContext.newInstance(UserData.class).createMarshaller();
+ marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+ unmarshaller = JAXBContext.newInstance(UserData.class).createUnmarshaller();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ String id;
+ String fullName;
+ String email;
+ String password;
+ String phone;
+ String type;
+ String state;
+
+ Link link;
+
+ @XmlAttribute(name="id")
+ public String getID() {
+ return id;
+ }
+
+ public void setID(String id) {
+ this.id = id;
+ }
+
+ @FormParam(Constants.PR_USER_FULLNAME)
+ @XmlElement(name="FullName")
+ public String getFullName() {
+ return fullName;
+ }
+
+ public void setFullName(String fullName) {
+ this.fullName = fullName;
+ }
+
+ @FormParam(Constants.PR_USER_EMAIL)
+ @XmlElement(name="Email")
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ @FormParam(Constants.PR_USER_PASSWORD)
+ @XmlElement(name="Password")
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ @FormParam(Constants.PR_USER_PHONE)
+ @XmlElement(name="Phone")
+ public String getPhone() {
+ return phone;
+ }
+
+ public void setPhone(String phone) {
+ this.phone = phone;
+ }
+
+ @FormParam(Constants.PR_USER_TYPE)
+ @XmlElement(name="Type")
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ @FormParam(Constants.PR_USER_STATE)
+ @XmlElement(name="State")
+ public String getState() {
+ return state;
+ }
+
+ public void setState(String state) {
+ this.state = state;
+ }
+
+ @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 + ((email == null) ? 0 : email.hashCode());
+ result = prime * result + ((fullName == null) ? 0 : fullName.hashCode());
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ result = prime * result + ((password == null) ? 0 : password.hashCode());
+ result = prime * result + ((phone == null) ? 0 : phone.hashCode());
+ result = prime * result + ((state == null) ? 0 : state.hashCode());
+ result = prime * result + ((type == null) ? 0 : type.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;
+ UserData other = (UserData) obj;
+ if (email == null) {
+ if (other.email != null)
+ return false;
+ } else if (!email.equals(other.email))
+ return false;
+ if (fullName == null) {
+ if (other.fullName != null)
+ return false;
+ } else if (!fullName.equals(other.fullName))
+ return false;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ if (password == null) {
+ if (other.password != null)
+ return false;
+ } else if (!password.equals(other.password))
+ return false;
+ if (phone == null) {
+ if (other.phone != null)
+ return false;
+ } else if (!phone.equals(other.phone))
+ return false;
+ if (state == null) {
+ if (other.state != null)
+ return false;
+ } else if (!state.equals(other.state))
+ return false;
+ if (type == null) {
+ if (other.type != null)
+ return false;
+ } else if (!type.equals(other.type))
+ 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 UserData valueOf(String string) throws Exception {
+ try {
+ return (UserData)unmarshaller.unmarshal(new StringReader(string));
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ public static void main(String args[]) throws Exception {
+
+ UserData before = new UserData();
+ before.setID("testuser");
+ before.setFullName("Test User");
+ before.setEmail("testuser@example.com");
+ before.setPassword("12345");
+ before.setPhone("1234567890");
+ before.setState("1");
+
+ String string = before.toString();
+ System.out.println(string);
+
+ UserData after = UserData.valueOf(string);
+ System.out.println(before.equals(after));
+ }
+}
diff --git a/base/common/src/com/netscape/certsrv/user/UserResource.java b/base/common/src/com/netscape/certsrv/user/UserResource.java
new file mode 100644
index 000000000..fae700bc3
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/user/UserResource.java
@@ -0,0 +1,69 @@
+// --- 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.user;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+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("/users")
+public interface UserResource {
+
+ @GET
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public UserCollection findUsers(
+ @QueryParam("filter") String filter,
+ @QueryParam("start") Integer start,
+ @QueryParam("size") Integer size);
+
+ @POST
+ @ClientResponseType(entityType=UserData.class)
+ @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response addUser(UserData userData);
+
+ @GET
+ @Path("/{userID}")
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public UserData getUser(@PathParam("userID") String userID);
+
+ @POST
+ @Path("/{userID}")
+ @ClientResponseType(entityType=UserData.class)
+ @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response modifyUser(@PathParam("userID") String userID, UserData userData);
+
+ @DELETE
+ @Path("/{userID}")
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public void removeUser(@PathParam("userID") String userID);
+}