summaryrefslogtreecommitdiffstats
path: root/base/common/src/com/netscape/certsrv/user
diff options
context:
space:
mode:
Diffstat (limited to 'base/common/src/com/netscape/certsrv/user')
-rw-r--r--base/common/src/com/netscape/certsrv/user/UserClient.java16
-rw-r--r--base/common/src/com/netscape/certsrv/user/UserMembershipCollection.java85
-rw-r--r--base/common/src/com/netscape/certsrv/user/UserMembershipData.java99
-rw-r--r--base/common/src/com/netscape/certsrv/user/UserMembershipResource.java60
4 files changed, 260 insertions, 0 deletions
diff --git a/base/common/src/com/netscape/certsrv/user/UserClient.java b/base/common/src/com/netscape/certsrv/user/UserClient.java
index 23136200d..2dd350354 100644
--- a/base/common/src/com/netscape/certsrv/user/UserClient.java
+++ b/base/common/src/com/netscape/certsrv/user/UserClient.java
@@ -32,6 +32,7 @@ public class UserClient extends PKIClient {
public UserResource userClient;
public UserCertResource userCertClient;
+ public UserMembershipResource userMembershipClient;
public UserClient(PKIConnection connection) throws URISyntaxException {
super(connection);
@@ -46,6 +47,7 @@ public class UserClient extends PKIClient {
public void init() throws URISyntaxException {
userClient = createProxy(UserResource.class);
userCertClient = createProxy(UserCertResource.class);
+ userMembershipClient = createProxy(UserMembershipResource.class);
}
public UserCollection findUsers(String filter, Integer start, Integer size) {
@@ -89,4 +91,18 @@ public class UserClient extends PKIClient {
public void removeUserCert(String userID, String certID) {
userCertClient.removeUserCert(userID, certID);
}
+
+ public UserMembershipCollection findUserMemberships(String userID, Integer start, Integer size) {
+ return userMembershipClient.findUserMemberships(userID, start, size);
+ }
+
+ public UserMembershipData addUserMembership(String userID, String groupID) {
+ @SuppressWarnings("unchecked")
+ ClientResponse<UserMembershipData> response = (ClientResponse<UserMembershipData>)userMembershipClient.addUserMembership(userID, groupID);
+ return getEntity(response);
+ }
+
+ public void removeUserMembership(String userD, String groupID) {
+ userMembershipClient.removeUserMembership(userD, groupID);
+ }
}
diff --git a/base/common/src/com/netscape/certsrv/user/UserMembershipCollection.java b/base/common/src/com/netscape/certsrv/user/UserMembershipCollection.java
new file mode 100644
index 000000000..069840d13
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/user/UserMembershipCollection.java
@@ -0,0 +1,85 @@
+// --- 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.user;
+
+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="UserMemberships")
+public class UserMembershipCollection {
+
+ Collection<UserMembershipData> memberships = new ArrayList<UserMembershipData>();
+ Collection<Link> links = new ArrayList<Link>();
+
+ @XmlElement(name="Membership")
+ public Collection<UserMembershipData> getMemberships() {
+ return memberships;
+ }
+
+ public void setMemberships(Collection<UserMembershipData> members) {
+ this.memberships = members;
+ }
+
+ public void addMembership(UserMembershipData member) {
+ memberships.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 {
+
+ UserMembershipCollection response = new UserMembershipCollection();
+
+ UserMembershipData membership1 = new UserMembershipData();
+ membership1.setID("Group 1");
+ membership1.setUserID("User 1");
+ response.addMembership(membership1);
+
+ UserMembershipData membership2 = new UserMembershipData();
+ membership2.setID("Group 2");
+ membership2.setUserID("User 1");
+ response.addMembership(membership2);
+
+ JAXBContext context = JAXBContext.newInstance(UserMembershipCollection.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/user/UserMembershipData.java b/base/common/src/com/netscape/certsrv/user/UserMembershipData.java
new file mode 100644
index 000000000..8db70e21e
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/user/UserMembershipData.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) 2013 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.certsrv.user;
+
+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="UserMembership")
+public class UserMembershipData {
+
+ String id;
+ String userID;
+
+ Link link;
+
+ @FormParam(Constants.PR_GROUP_GROUP)
+ @XmlAttribute(name="id")
+ public String getID() {
+ return id;
+ }
+
+ public void setID(String id) {
+ this.id = id;
+ }
+
+ @XmlElement(name="UserID")
+ public String getUserID() {
+ return userID;
+ }
+
+ public void setUserID(String userID) {
+ this.userID = userID;
+ }
+
+ @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 + ((userID == null) ? 0 : userID.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;
+ UserMembershipData other = (UserMembershipData) obj;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ if (userID == null) {
+ if (other.userID != null)
+ return false;
+ } else if (!userID.equals(other.userID))
+ return false;
+ return true;
+ }
+}
diff --git a/base/common/src/com/netscape/certsrv/user/UserMembershipResource.java b/base/common/src/com/netscape/certsrv/user/UserMembershipResource.java
new file mode 100644
index 000000000..eedc2c961
--- /dev/null
+++ b/base/common/src/com/netscape/certsrv/user/UserMembershipResource.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.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;
+
+import com.netscape.certsrv.acls.ACLMapping;
+
+/**
+ * @author Endi S. Dewata
+ */
+@Path("admin/users/{userID}/memberships")
+@ACLMapping("admin.users")
+public interface UserMembershipResource {
+
+ @GET
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public UserMembershipCollection findUserMemberships(
+ @PathParam("userID") String userID,
+ @QueryParam("start") Integer start,
+ @QueryParam("size") Integer size);
+
+ @POST
+ @ClientResponseType(entityType=UserMembershipData.class)
+ @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response addUserMembership(@PathParam("userID") String userID, String groupID);
+
+ @DELETE
+ @Path("{groupID}")
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public void removeUserMembership(@PathParam("userID") String userID, @PathParam("groupID") String groupID);
+}