summaryrefslogtreecommitdiffstats
path: root/base/common/src/com/netscape/certsrv
diff options
context:
space:
mode:
authorEndi Sukma Dewata <edewata@redhat.com>2012-05-19 11:12:12 -0500
committerEndi Sukma Dewata <edewata@redhat.com>2012-05-31 12:01:49 -0500
commitafa68fa3c69d1617a312f1f2f75f7e6c27bb06c7 (patch)
tree21d1c2774b0d6512f8c708d34a966c5d25077076 /base/common/src/com/netscape/certsrv
parent770cc205a0108be22922c46a39d162dc31c55724 (diff)
downloadpki-afa68fa3c69d1617a312f1f2f75f7e6c27bb06c7.tar.gz
pki-afa68fa3c69d1617a312f1f2f75f7e6c27bb06c7.tar.xz
pki-afa68fa3c69d1617a312f1f2f75f7e6c27bb06c7.zip
Added group REST service.
The group REST service is based on UsrGrpAdminServlet. It provides an interface to manage groups and group members. Ticket #160
Diffstat (limited to 'base/common/src/com/netscape/certsrv')
-rw-r--r--base/common/src/com/netscape/certsrv/common/ScopeDef.java1
-rw-r--r--base/common/src/com/netscape/certsrv/group/GroupCollection.java65
-rw-r--r--base/common/src/com/netscape/certsrv/group/GroupData.java99
-rw-r--r--base/common/src/com/netscape/certsrv/group/GroupMemberCollection.java83
-rw-r--r--base/common/src/com/netscape/certsrv/group/GroupMemberData.java83
-rw-r--r--base/common/src/com/netscape/certsrv/group/GroupMemberResource.java62
-rw-r--r--base/common/src/com/netscape/certsrv/group/GroupResource.java69
-rw-r--r--base/common/src/com/netscape/certsrv/usrgrp/IUGSubsystem.java11
8 files changed, 473 insertions, 0 deletions
diff --git a/base/common/src/com/netscape/certsrv/common/ScopeDef.java b/base/common/src/com/netscape/certsrv/common/ScopeDef.java
index e8919de5e..017d082c8 100644
--- a/base/common/src/com/netscape/certsrv/common/ScopeDef.java
+++ b/base/common/src/com/netscape/certsrv/common/ScopeDef.java
@@ -28,6 +28,7 @@ public interface ScopeDef {
// users and groups
public final static String SC_GROUPS = "groups";
+ public final static String SC_GROUP_MEMBERS = "members";
public final static String SC_USERS = "users";
public final static String SC_USER_CERTS = "certs";
diff --git a/base/common/src/com/netscape/certsrv/group/GroupCollection.java b/base/common/src/com/netscape/certsrv/group/GroupCollection.java
new file mode 100644
index 000000000..26d108e7b
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/group/GroupCollection.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.group;
+
+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="Groups")
+public class GroupCollection {
+
+ Collection<GroupData> groups = new ArrayList<GroupData>();
+ Collection<Link> links = new ArrayList<Link>();
+
+ @XmlElementRef
+ public Collection<GroupData> getGroups() {
+ return groups;
+ }
+
+ public void setGroups(Collection<GroupData> groups) {
+ this.groups = groups;
+ }
+
+ public void addGroup(GroupData groupData) {
+ groups.add(groupData);
+ }
+
+ @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/group/GroupData.java b/base/common/src/com/netscape/certsrv/group/GroupData.java
new file mode 100644
index 000000000..a21ad7f01
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/group/GroupData.java
@@ -0,0 +1,99 @@
+// --- 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.group;
+
+import javax.ws.rs.FormParam;
+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="Group")
+public class GroupData {
+
+ String id;
+ String description;
+
+ Link link;
+
+ @XmlAttribute(name="id")
+ public String getID() {
+ return id;
+ }
+
+ public void setID(String id) {
+ this.id = id;
+ }
+
+ @FormParam(Constants.PR_GROUP_DESC)
+ @XmlElement(name="Description")
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ @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 + ((description == null) ? 0 : description.hashCode());
+ result = prime * result + ((id == null) ? 0 : id.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;
+ GroupData other = (GroupData) obj;
+ if (description == null) {
+ if (other.description != null)
+ return false;
+ } else if (!description.equals(other.description))
+ return false;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ return true;
+ }
+}
diff --git a/base/common/src/com/netscape/certsrv/group/GroupMemberCollection.java b/base/common/src/com/netscape/certsrv/group/GroupMemberCollection.java
new file mode 100644
index 000000000..d19d939ad
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/group/GroupMemberCollection.java
@@ -0,0 +1,83 @@
+// --- 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.group;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+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="GroupMembers")
+public class GroupMemberCollection {
+
+ Collection<GroupMemberData> members = new ArrayList<GroupMemberData>();
+ Collection<Link> links = new ArrayList<Link>();
+
+ @XmlElement(name="Member")
+ public Collection<GroupMemberData> getMembers() {
+ return members;
+ }
+
+ public void setMembers(Collection<GroupMemberData> members) {
+ this.members = members;
+ }
+
+ public void addMember(GroupMemberData member) {
+ members.add(member);
+ }
+
+ @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);
+ }
+
+ public static void main(String args[]) throws Exception {
+
+ GroupMemberCollection response = new GroupMemberCollection();
+
+ GroupMemberData member1 = new GroupMemberData();
+ member1.setID("User 1");
+ response.addMember(member1);
+
+ GroupMemberData member2 = new GroupMemberData();
+ member2.setID("User 2");
+ response.addMember(member2);
+
+ JAXBContext context = JAXBContext.newInstance(GroupMemberCollection.class);
+ Marshaller marshaller = context.createMarshaller();
+ marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+ marshaller.marshal(response, System.out);
+ }
+}
diff --git a/base/common/src/com/netscape/certsrv/group/GroupMemberData.java b/base/common/src/com/netscape/certsrv/group/GroupMemberData.java
new file mode 100644
index 000000000..11f3a2147
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/group/GroupMemberData.java
@@ -0,0 +1,83 @@
+// --- 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.group;
+
+import javax.ws.rs.FormParam;
+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="GroupMember")
+public class GroupMemberData {
+
+ String id;
+
+ Link link;
+
+ @FormParam(Constants.PR_GROUP_USER)
+ @XmlAttribute(name="id")
+ public String getID() {
+ return id;
+ }
+
+ public void setID(String id) {
+ this.id = id;
+ }
+
+ @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());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ GroupMemberData other = (GroupMemberData) obj;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ return true;
+ }
+}
diff --git a/base/common/src/com/netscape/certsrv/group/GroupMemberResource.java b/base/common/src/com/netscape/certsrv/group/GroupMemberResource.java
new file mode 100644
index 000000000..51370f573
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/group/GroupMemberResource.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) 2012 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.certsrv.group;
+
+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("/groups/{groupID}/members")
+public interface GroupMemberResource {
+
+ @GET
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public GroupMemberCollection findGroupMembers(
+ @PathParam("groupID") String groupID,
+ @QueryParam("start") Integer start,
+ @QueryParam("size") Integer size);
+
+ @POST
+ @ClientResponseType(entityType=GroupMemberData.class)
+ @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response addGroupMember(@PathParam("groupID") String groupID, String memberID);
+
+ @GET
+ @Path("/{memberID}")
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public GroupMemberData getGroupMember(@PathParam("groupID") String groupID, @PathParam("memberID") String memberID);
+
+ @DELETE
+ @Path("/{memberID}")
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public void removeGroupMember(@PathParam("groupID") String groupID, @PathParam("memberID") String memberID);
+}
diff --git a/base/common/src/com/netscape/certsrv/group/GroupResource.java b/base/common/src/com/netscape/certsrv/group/GroupResource.java
new file mode 100644
index 000000000..5889048ea
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/group/GroupResource.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.group;
+
+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("/groups")
+public interface GroupResource {
+
+ @GET
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public GroupCollection findGroups(
+ @QueryParam("filter") String filter,
+ @QueryParam("start") Integer start,
+ @QueryParam("size") Integer size);
+
+ @POST
+ @ClientResponseType(entityType=GroupData.class)
+ @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response addGroup(GroupData groupData);
+
+ @GET
+ @Path("/{groupID}")
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public GroupData getGroup(@PathParam("groupID") String groupID);
+
+ @POST
+ @Path("/{groupID}")
+ @ClientResponseType(entityType=GroupData.class)
+ @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response modifyGroup(@PathParam("groupID") String groupID, GroupData groupData);
+
+ @DELETE
+ @Path("/{groupID}")
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public void removeGroup(@PathParam("groupID") String groupID);
+}
diff --git a/base/common/src/com/netscape/certsrv/usrgrp/IUGSubsystem.java b/base/common/src/com/netscape/certsrv/usrgrp/IUGSubsystem.java
index 60a1f70ea..c101187c4 100644
--- a/base/common/src/com/netscape/certsrv/usrgrp/IUGSubsystem.java
+++ b/base/common/src/com/netscape/certsrv/usrgrp/IUGSubsystem.java
@@ -205,6 +205,17 @@ public interface IUGSubsystem extends ISubsystem, IUsrGrp {
public void modifyGroup(IGroup group) throws EUsrGrpException;
/**
+ * Adds the user with the given id into the given group
+ *
+ * @param grp the given group
+ * @param userid the given user id
+ * @exception EUsrGrpException thrown when failed to add the user into
+ * the given group
+ */
+ public void addUserToGroup(IGroup grp, String userid)
+ throws EUsrGrpException;
+
+ /**
* Removes the user with the given id from the given group
*
* @param grp the given group