2 * This document is a part of the source code and related artifacts
3 * for CollectionSpace, an open source collections management system
4 * for museums and related institutions:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright 2009 University of California at Berkeley
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
24 package org.collectionspace.services.authorization;
26 import javax.ws.rs.PathParam;
27 import javax.ws.rs.WebApplicationException;
28 import javax.ws.rs.core.Context;
29 import javax.ws.rs.core.MultivaluedMap;
30 import javax.ws.rs.core.Response;
31 import javax.ws.rs.core.UriBuilder;
32 import javax.ws.rs.core.UriInfo;
33 import org.collectionspace.services.authorization.storage.PermissionRoleStorageClient;
35 import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl;
36 import org.collectionspace.services.common.context.RemoteServiceContextImpl;
37 import org.collectionspace.services.common.context.ServiceContext;
38 import org.collectionspace.services.common.document.DocumentFilter;
39 import org.collectionspace.services.common.document.DocumentHandler;
40 import org.collectionspace.services.common.storage.StorageClient;
41 import org.jboss.resteasy.util.HttpResponseCodes;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
46 * PermissionRoleSubResource is used to manage permission-role relationship
49 public class PermissionRoleSubResource
50 extends AbstractCollectionSpaceResourceImpl {
52 //this service is never exposed as standalone RESTful service...just use unique
53 //service name to identify binding
54 final private String serviceName = "authorization/permroles";
55 final Logger logger = LoggerFactory.getLogger(PermissionRoleSubResource.class);
56 final StorageClient storageClient = new PermissionRoleStorageClient();
59 protected String getVersionString() {
60 /** The last change revision. */
61 final String lastChangeRevision = "$LastChangedRevision: 1165 $";
62 return lastChangeRevision;
66 public String getServiceName() {
70 private <T> ServiceContext createServiceContext(T obj, SubjectType subject) throws Exception {
71 ServiceContext ctx = new RemoteServiceContextImpl<T, T>(getServiceName());
73 ctx.setDocumentType(PermissionRole.class.getPackage().getName()); //persistence unit
74 ctx.setProperty("entity-name", PermissionRoleRel.class.getName());
75 //subject name is necessary to indicate if role or permission is a subject
76 ctx.setProperty("subject", subject);
81 public StorageClient getStorageClient(ServiceContext ctx) {
82 //FIXME use ctx to identify storage client
87 public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
88 DocumentHandler docHandler = ctx.getDocumentHandler();
89 docHandler.setCommonPart(ctx.getInput());
94 * createPermissionRole creates one or more permission-role relationships
95 * between object (permission/role) and subject (role/permission)
101 public String createPermissionRole(PermissionRole input, SubjectType subject)
104 ServiceContext ctx = createServiceContext(input, subject);
105 DocumentHandler handler = createDocumentHandler(ctx);
106 return getStorageClient(ctx).create(ctx, handler);
110 * getPermissionRole retrieves permission-role relationships using given
111 * csid of object (permission/role) and subject (role/permission)
117 public PermissionRole getPermissionRole(
118 String csid, SubjectType subject) throws Exception {
120 if (logger.isDebugEnabled()) {
121 logger.debug("getPermissionRole with csid=" + csid);
123 PermissionRole result = null;
124 ServiceContext ctx = createServiceContext((PermissionRole) null, subject);
125 DocumentHandler handler = createDocumentHandler(ctx);
126 getStorageClient(ctx).get(ctx, csid, handler);
127 result = (PermissionRole) ctx.getOutput();
133 * deletePermissionRole deletes permission-role relationships using given
134 * csid of object (permission/role) and subject (role/permission)
140 public void deletePermissionRole(String csid,
141 SubjectType subject) throws Exception {
143 if (logger.isDebugEnabled()) {
144 logger.debug("deletePermissionRole with csid=" + csid);
146 ServiceContext ctx = createServiceContext((PermissionRole) null, subject);
147 getStorageClient(ctx).delete(ctx, csid);