diff options
Diffstat (limited to 'base/common/src/com/netscape/certsrv')
6 files changed, 278 insertions, 0 deletions
diff --git a/base/common/src/com/netscape/certsrv/group/GroupMemberCollection.java b/base/common/src/com/netscape/certsrv/group/GroupMemberCollection.java index d19d939ad..6ec013bca 100644 --- a/base/common/src/com/netscape/certsrv/group/GroupMemberCollection.java +++ b/base/common/src/com/netscape/certsrv/group/GroupMemberCollection.java @@ -69,10 +69,12 @@ public class GroupMemberCollection { GroupMemberData member1 = new GroupMemberData(); member1.setID("User 1"); + member1.setGroupID("Group 1"); response.addMember(member1); GroupMemberData member2 = new GroupMemberData(); member2.setID("User 2"); + member2.setGroupID("Group 1"); response.addMember(member2); JAXBContext context = JAXBContext.newInstance(GroupMemberCollection.class); diff --git a/base/common/src/com/netscape/certsrv/group/GroupMemberData.java b/base/common/src/com/netscape/certsrv/group/GroupMemberData.java index 11f3a2147..8502f3e8f 100644 --- a/base/common/src/com/netscape/certsrv/group/GroupMemberData.java +++ b/base/common/src/com/netscape/certsrv/group/GroupMemberData.java @@ -34,6 +34,7 @@ import com.netscape.certsrv.common.Constants; public class GroupMemberData { String id; + String groupID; Link link; @@ -47,6 +48,15 @@ public class GroupMemberData { this.id = id; } + @XmlAttribute(name="GroupID") + public String getGroupID() { + return groupID; + } + + public void setGroupID(String groupID) { + this.groupID = groupID; + } + @XmlElement(name="Link") public Link getLink() { return link; @@ -60,6 +70,7 @@ public class GroupMemberData { public int hashCode() { final int prime = 31; int result = 1; + result = prime * result + ((groupID == null) ? 0 : groupID.hashCode()); result = prime * result + ((id == null) ? 0 : id.hashCode()); return result; } @@ -73,6 +84,11 @@ public class GroupMemberData { if (getClass() != obj.getClass()) return false; GroupMemberData other = (GroupMemberData) obj; + if (groupID == null) { + if (other.groupID != null) + return false; + } else if (!groupID.equals(other.groupID)) + return false; if (id == null) { if (other.id != null) return false; 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); +} |