]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
367076a0589a475de1ea773ab8564eabf3b58279
[tmp/jakarta-migration.git] /
1 /**
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:
5
6  *  http://www.collectionspace.org
7  *  http://wiki.collectionspace.org
8
9  *  Copyright 2009 University of California at Berkeley
10
11  *  Licensed under the Educational Community License (ECL), Version 2.0.
12  *  You may not use this file except in compliance with this License.
13
14  *  You may obtain a copy of the ECL 2.0 License at
15
16  *  https://source.collectionspace.org/collection-space/LICENSE.txt
17
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.
23  */
24 package org.collectionspace.services.authorization;
25
26 import javax.ws.rs.Consumes;
27 import javax.ws.rs.GET;
28 import javax.ws.rs.Path;
29 import javax.ws.rs.Produces;
30 import javax.ws.rs.DELETE;
31 import javax.ws.rs.POST;
32 import javax.ws.rs.PUT;
33 import javax.ws.rs.PathParam;
34 import javax.ws.rs.QueryParam;
35 import javax.ws.rs.WebApplicationException;
36 import javax.ws.rs.core.Context;
37 import javax.ws.rs.core.MultivaluedMap;
38 import javax.ws.rs.core.Response;
39 import javax.ws.rs.core.UriBuilder;
40 import javax.ws.rs.core.UriInfo;
41
42 import org.collectionspace.services.authorization.storage.PermissionRoleDocumentHandler;
43 import org.collectionspace.services.authorization.storage.AuthorizationDelegate;
44
45 import org.collectionspace.services.common.storage.StorageClient;
46 import org.collectionspace.services.common.storage.jpa.JpaStorageClientImpl;
47 import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl;
48 import org.collectionspace.services.common.ServiceMessages;
49 import org.collectionspace.services.common.context.ServiceContext;
50 import org.collectionspace.services.common.context.RemoteServiceContextFactory;
51 import org.collectionspace.services.common.context.ServiceContextFactory;
52 import org.collectionspace.services.common.document.BadRequestException;
53 import org.collectionspace.services.common.document.DocumentFilter;
54 import org.collectionspace.services.common.document.DocumentNotFoundException;
55 import org.collectionspace.services.common.document.DocumentHandler;
56 import org.collectionspace.services.common.security.UnauthorizedException;
57
58 import org.jboss.resteasy.util.HttpResponseCodes;
59 import org.slf4j.Logger;
60 import org.slf4j.LoggerFactory;
61
62 /**
63  * The Class PermissionResource.
64  */
65 @Path("/authorization/permissions")
66 @Consumes("application/xml")
67 @Produces("application/xml")
68 public class PermissionResource
69         extends AbstractCollectionSpaceResourceImpl<Permission, Permission> {
70
71     /** The service name. */
72     final private String serviceName = "authorization/permissions";
73     /** The logger. */
74     final Logger logger = LoggerFactory.getLogger(PermissionResource.class);
75     /** The storage client. */
76     final StorageClient storageClient = new JpaStorageClientImpl();
77
78     /* (non-Javadoc)
79      * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getVersionString()
80      */
81     @Override
82     protected String getVersionString() {
83         /** The last change revision. */
84         final String lastChangeRevision = "$LastChangedRevision: 1165 $";
85         return lastChangeRevision;
86     }
87
88     /* (non-Javadoc)
89      * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getServiceName()
90      */
91     @Override
92     public String getServiceName() {
93         return serviceName;
94     }
95
96     /* (non-Javadoc)
97      * @see org.collectionspace.services.common.CollectionSpaceResource#getCommonPartClass()
98      */
99     @Override
100     public Class<Permission> getCommonPartClass() {
101         return Permission.class;
102     }
103
104     /* (non-Javadoc)
105      * @see org.collectionspace.services.common.CollectionSpaceResource#getServiceContextFactory()
106      */
107     @Override
108     public ServiceContextFactory<Permission, Permission> getServiceContextFactory() {
109         return RemoteServiceContextFactory.get();
110     }
111
112     /* (non-Javadoc)
113      * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getStorageClient(org.collectionspace.services.common.context.ServiceContext)
114      */
115     @Override
116     public StorageClient getStorageClient(ServiceContext ctx) {
117         //FIXME use ctx to identify storage client
118         return storageClient;
119     }
120
121 //    @Override
122 //    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
123 //        DocumentHandler docHandler = ctx.getDocumentHandler();
124 //        docHandler.setCommonPart(ctx.getInput());
125 //        return docHandler;
126 //    }
127     /**
128      * Creates the permission.
129      *
130      * @param input the input
131      *
132      * @return the response
133      */
134     @POST
135     public Response createPermission(Permission input) {
136         try {
137             ServiceContext<Permission, Permission> ctx = createServiceContext(input, Permission.class);
138             DocumentHandler handler = createDocumentHandler(ctx);
139             String csid = getStorageClient(ctx).create(ctx, handler);
140             UriBuilder path = UriBuilder.fromResource(PermissionResource.class);
141             path.path("" + csid);
142             Response response = Response.created(path.build()).build();
143             return response;
144         } catch (BadRequestException bre) {
145             Response response = Response.status(
146                     Response.Status.BAD_REQUEST).entity(ServiceMessages.POST_FAILED
147                     + bre.getErrorReason()).type("text/plain").build();
148             throw new WebApplicationException(response);
149         } catch (UnauthorizedException ue) {
150             Response response = Response.status(
151                     Response.Status.UNAUTHORIZED).entity(ServiceMessages.POST_FAILED
152                     + ue.getErrorReason()).type("text/plain").build();
153             throw new WebApplicationException(response);
154         } catch (Exception e) {
155             if (logger.isDebugEnabled()) {
156                 logger.debug("Caught exception in createPermission", e);
157             }
158             logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
159             Response response = Response.status(
160                     Response.Status.INTERNAL_SERVER_ERROR).entity(
161                     ServiceMessages.POST_FAILED
162                     + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
163             throw new WebApplicationException(response);
164         }
165     }
166
167     /**
168      * Gets the permission.
169      * 
170      * @param csid the csid
171      * 
172      * @return the permission
173      */
174     @GET
175     @Path("{csid}")
176     public Permission getPermission(
177             @PathParam("csid") String csid) {
178         if (logger.isDebugEnabled()) {
179             logger.debug("getPermission with csid=" + csid);
180         }
181         if (csid == null || "".equals(csid)) {
182             logger.error("getPermission: missing csid!");
183             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
184                     ServiceMessages.GET_FAILED + "permission "
185                     + ServiceMessages.MISSING_INVALID_CSID + csid).type(
186                     "text/plain").build();
187             throw new WebApplicationException(response);
188         }
189         Permission result = null;
190         try {
191             ServiceContext<Permission, Permission> ctx = createServiceContext((Permission) null, Permission.class);
192             DocumentHandler handler = createDocumentHandler(ctx);
193             getStorageClient(ctx).get(ctx, csid, handler);
194             result = (Permission) ctx.getOutput();
195         } catch (UnauthorizedException ue) {
196             Response response = Response.status(
197                     Response.Status.UNAUTHORIZED).entity(ServiceMessages.GET_FAILED
198                     + ue.getErrorReason()).type("text/plain").build();
199             throw new WebApplicationException(response);
200         } catch (DocumentNotFoundException dnfe) {
201             if (logger.isDebugEnabled()) {
202                 logger.debug("getPermission", dnfe);
203             }
204             Response response = Response.status(Response.Status.NOT_FOUND).entity(
205                     ServiceMessages.GET_FAILED + "permission csid=" + csid).type(
206                     "text/plain").build();
207             throw new WebApplicationException(response);
208         } catch (Exception e) {
209             if (logger.isDebugEnabled()) {
210                 logger.debug("getPermission", e);
211             }
212             logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
213             Response response = Response.status(
214                     Response.Status.INTERNAL_SERVER_ERROR).entity(
215                     ServiceMessages.GET_FAILED
216                     + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
217             throw new WebApplicationException(response);
218         }
219
220         if (result == null) {
221             Response response = Response.status(Response.Status.NOT_FOUND).entity(
222                     ServiceMessages.GET_FAILED + " permission csid=" + csid + ": was not found.").type(
223                     "text/plain").build();
224             throw new WebApplicationException(response);
225         }
226         return result;
227     }
228
229     /**
230      * Gets the permission list.
231      * 
232      * @param ui the ui
233      * 
234      * @return the permission list
235      */
236     @GET
237     @Produces("application/xml")
238     public PermissionsList getPermissionList(
239             @Context UriInfo ui) {
240         PermissionsList permissionList = new PermissionsList();
241         try {
242             ServiceContext<Permission, Permission> ctx = createServiceContext((Permission) null, Permission.class);
243             DocumentHandler handler = createDocumentHandler(ctx);
244             MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
245             DocumentFilter myFilter = handler.createDocumentFilter();
246             myFilter.setPagination(queryParams);
247             myFilter.setQueryParams(queryParams);
248             handler.setDocumentFilter(myFilter);
249             getStorageClient(ctx).getFiltered(ctx, handler);
250             permissionList = (PermissionsList) handler.getCommonPartList();
251         } catch (UnauthorizedException ue) {
252             Response response = Response.status(
253                     Response.Status.UNAUTHORIZED).entity(ServiceMessages.LIST_FAILED
254                     + ue.getErrorReason()).type("text/plain").build();
255             throw new WebApplicationException(response);
256
257         } catch (Exception e) {
258             if (logger.isDebugEnabled()) {
259                 logger.debug("Caught exception in getPermissionsList", e);
260             }
261             logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
262             Response response = Response.status(
263                     Response.Status.INTERNAL_SERVER_ERROR).entity(
264                     ServiceMessages.LIST_FAILED
265                     + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
266             throw new WebApplicationException(response);
267         }
268         return permissionList;
269     }
270
271     /**
272      * Update permission.
273      * 
274      * @param csid the csid
275      * @param theUpdate the the update
276      * 
277      * @return the permission
278      */
279     @PUT
280     @Path("{csid}")
281     public Permission updatePermission(
282             @PathParam("csid") String csid,
283             Permission theUpdate) {
284         if (logger.isDebugEnabled()) {
285             logger.debug("updatePermission with csid=" + csid);
286         }
287         if (csid == null || "".equals(csid)) {
288             logger.error("updatePermission: missing csid!");
289             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
290                     ServiceMessages.PUT_FAILED + "permission "
291                     + ServiceMessages.MISSING_INVALID_CSID + csid).type(
292                     "text/plain").build();
293             throw new WebApplicationException(response);
294         }
295         Permission result = null;
296         try {
297             ServiceContext<Permission, Permission> ctx = createServiceContext(theUpdate, Permission.class);
298             DocumentHandler handler = createDocumentHandler(ctx);
299             getStorageClient(ctx).update(ctx, csid, handler);
300             result = (Permission) ctx.getOutput();
301         } catch (BadRequestException bre) {
302             Response response = Response.status(
303                     Response.Status.BAD_REQUEST).entity(ServiceMessages.PUT_FAILED
304                     + bre.getErrorReason()).type("text/plain").build();
305             throw new WebApplicationException(response);
306         } catch (UnauthorizedException ue) {
307             Response response = Response.status(
308                     Response.Status.UNAUTHORIZED).entity(ServiceMessages.PUT_FAILED
309                     + ue.getErrorReason()).type("text/plain").build();
310             throw new WebApplicationException(response);
311         } catch (DocumentNotFoundException dnfe) {
312             if (logger.isDebugEnabled()) {
313                 logger.debug("caugth exception in updatePermission", dnfe);
314             }
315             Response response = Response.status(Response.Status.NOT_FOUND).entity(
316                     ServiceMessages.PUT_FAILED + "permission csid=" + csid).type(
317                     "text/plain").build();
318             throw new WebApplicationException(response);
319         } catch (Exception e) {
320             logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
321             Response response = Response.status(
322                     Response.Status.INTERNAL_SERVER_ERROR).entity(
323                     ServiceMessages.PUT_FAILED
324                     + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
325             throw new WebApplicationException(response);
326         }
327         return result;
328     }
329
330     /**
331      * Delete permission.
332      * 
333      * @param csid the csid
334      * 
335      * @return the response
336      */
337     @DELETE
338     @Path("{csid}")
339     public Response deletePermission(@PathParam("csid") String csid) {
340
341         if (logger.isDebugEnabled()) {
342             logger.debug("deletePermission with csid=" + csid);
343         }
344         if (csid == null || "".equals(csid)) {
345             logger.error("deletePermission: missing csid!");
346             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
347                     ServiceMessages.DELETE_FAILED + "permission "
348                     + ServiceMessages.MISSING_INVALID_CSID + csid).type(
349                     "text/plain").build();
350             throw new WebApplicationException(response);
351         }
352         try {
353             //FIXME ideally the following two ops should be in the same tx CSPACE-658
354             //delete all relationships for this permission
355             PermissionRoleSubResource subResource =
356                     new PermissionRoleSubResource(PermissionRoleSubResource.PERMISSION_PERMROLE_SERVICE);
357             subResource.deletePermissionRole(csid, SubjectType.ROLE);
358             //NOTE for delete permissions in the authz provider
359             //at the PermissionRoleSubResource/DocHandler level, there is no visibility
360             //if permission is deleted, so do it here, however,
361             //this is a very dangerous operation as it deletes the Spring ACL instead of ACE(s)
362             //the ACL might be needed for other ACEs roles...
363             AuthorizationDelegate.deletePermissions(csid);
364
365             ServiceContext<Permission, Permission> ctx = createServiceContext((Permission) null, Permission.class);
366             getStorageClient(ctx).delete(ctx, csid);
367             return Response.status(HttpResponseCodes.SC_OK).build();
368         } catch (UnauthorizedException ue) {
369             Response response = Response.status(
370                     Response.Status.UNAUTHORIZED).entity(ServiceMessages.DELETE_FAILED
371                     + ue.getErrorReason()).type("text/plain").build();
372             throw new WebApplicationException(response);
373
374         } catch (DocumentNotFoundException dnfe) {
375             if (logger.isDebugEnabled()) {
376                 logger.debug("caught exception in deletePermission", dnfe);
377             }
378             Response response = Response.status(Response.Status.NOT_FOUND).entity(
379                     ServiceMessages.DELETE_FAILED + "permission csid=" + csid).type(
380                     "text/plain").build();
381             throw new WebApplicationException(response);
382         } catch (Exception e) {
383             logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
384             Response response = Response.status(
385                     Response.Status.INTERNAL_SERVER_ERROR).entity(
386                     ServiceMessages.DELETE_FAILED
387                     + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
388             throw new WebApplicationException(response);
389         }
390
391     }
392
393     @POST
394     @Path("{csid}/permroles")
395     public Response createPermissionRole(@QueryParam("_method") String method,
396             @PathParam("csid") String permCsid,
397             PermissionRole input) {
398                 if (method != null) {
399             if ("delete".equalsIgnoreCase(method)) {
400                 return deletePermissionRole(permCsid, input);
401             }
402         }
403         if (logger.isDebugEnabled()) {
404             logger.debug("createPermissionRole with permCsid=" + permCsid);
405         }
406         if (permCsid == null || "".equals(permCsid)) {
407             logger.error("createPermissionRole: missing permCsid!");
408             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
409                     ServiceMessages.POST_FAILED + "permroles permission "
410                     + ServiceMessages.MISSING_INVALID_CSID + permCsid).type(
411                     "text/plain").build();
412             throw new WebApplicationException(response);
413         }
414         try {
415             PermissionRoleSubResource subResource =
416                     new PermissionRoleSubResource(PermissionRoleSubResource.PERMISSION_PERMROLE_SERVICE);
417             String permrolecsid = subResource.createPermissionRole(input, SubjectType.ROLE);
418             UriBuilder path = UriBuilder.fromResource(PermissionResource.class);
419             path.path(permCsid + "/permroles/" + permrolecsid);
420             Response response = Response.created(path.build()).build();
421             return response;
422         } catch (BadRequestException bre) {
423             Response response = Response.status(
424                     Response.Status.BAD_REQUEST).entity("Create failed reason "
425                     + bre.getErrorReason()).type("text/plain").build();
426             throw new WebApplicationException(response);
427         } catch (UnauthorizedException ue) {
428             Response response = Response.status(
429                     Response.Status.UNAUTHORIZED).entity("Create failed reason "
430                     + ue.getErrorReason()).type("text/plain").build();
431             throw new WebApplicationException(response);
432         } catch (Exception e) {
433             if (logger.isDebugEnabled()) {
434                 logger.debug("Caught exception in createPermissionRole", e);
435             }
436             logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
437             Response response = Response.status(
438                     Response.Status.INTERNAL_SERVER_ERROR).entity(
439                     ServiceMessages.POST_FAILED
440                     + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
441             throw new WebApplicationException(response);
442         }
443     }
444
445     @GET
446     @Path("{csid}/permroles/{permrolecsid}")
447     public PermissionRoleRel getPermissionRole(
448             @PathParam("csid") String permCsid,
449             @PathParam("permrolecsid") String permrolecsid) {
450         if (logger.isDebugEnabled()) {
451             logger.debug("getPermissionRole with permCsid=" + permCsid);
452         }
453         if (permCsid == null || "".equals(permCsid)) {
454             logger.error("getPermissionRole: missing permCsid!");
455             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
456                     ServiceMessages.GET_FAILED + "permroles permission "
457                     + ServiceMessages.MISSING_INVALID_CSID + permCsid).type(
458                     "text/plain").build();
459             throw new WebApplicationException(response);
460         }
461         PermissionRoleRel result = null;
462         try {
463             PermissionRoleSubResource subResource =
464                     new PermissionRoleSubResource(PermissionRoleSubResource.PERMISSION_PERMROLE_SERVICE);
465             //get relationships for a permission
466             result = subResource.getPermissionRoleRel(permCsid, SubjectType.ROLE, permrolecsid);
467         } catch (UnauthorizedException ue) {
468             Response response = Response.status(
469                     Response.Status.UNAUTHORIZED).entity(ServiceMessages.GET_FAILED
470                     + ue.getErrorReason()).type("text/plain").build();
471             throw new WebApplicationException(response);
472         } catch (DocumentNotFoundException dnfe) {
473             if (logger.isDebugEnabled()) {
474                 logger.debug("getPermissionRole", dnfe);
475             }
476             Response response = Response.status(Response.Status.NOT_FOUND).entity(
477                     ServiceMessages.GET_FAILED + "permroles permission csid=" + permCsid).type(
478                     "text/plain").build();
479             throw new WebApplicationException(response);
480         } catch (Exception e) {
481             if (logger.isDebugEnabled()) {
482                 logger.debug("getPermissionRole", e);
483             }
484             logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
485             Response response = Response.status(
486                     Response.Status.INTERNAL_SERVER_ERROR).entity(
487                     ServiceMessages.GET_FAILED
488                     + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
489             throw new WebApplicationException(response);
490         }
491         if (result == null) {
492             Response response = Response.status(Response.Status.NOT_FOUND).entity(
493                     ServiceMessages.GET_FAILED + "permroles permisison csid=" + permCsid
494                     + ": was not found.").type(
495                     "text/plain").build();
496             throw new WebApplicationException(response);
497         }
498         return result;
499     }
500
501     @GET
502     @Path("{csid}/permroles")
503     public PermissionRole getPermissionRole(
504             @PathParam("csid") String permCsid) {
505         if (logger.isDebugEnabled()) {
506             logger.debug("getPermissionRole with permCsid=" + permCsid);
507         }
508         if (permCsid == null || "".equals(permCsid)) {
509             logger.error("getPermissionRole: missing permCsid!");
510             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
511                     ServiceMessages.GET_FAILED + "permroles permission "
512                     + ServiceMessages.MISSING_INVALID_CSID + permCsid).type(
513                     "text/plain").build();
514             throw new WebApplicationException(response);
515         }
516         PermissionRole result = null;
517         try {
518             PermissionRoleSubResource subResource =
519                     new PermissionRoleSubResource(PermissionRoleSubResource.PERMISSION_PERMROLE_SERVICE);
520             //get relationships for a permission
521             result = subResource.getPermissionRole(permCsid, SubjectType.ROLE);
522         } catch (UnauthorizedException ue) {
523             Response response = Response.status(
524                     Response.Status.UNAUTHORIZED).entity(ServiceMessages.GET_FAILED
525                     + ue.getErrorReason()).type("text/plain").build();
526             throw new WebApplicationException(response);
527         } catch (DocumentNotFoundException dnfe) {
528             if (logger.isDebugEnabled()) {
529                 logger.debug("getPermissionRole", dnfe);
530             }
531             Response response = Response.status(Response.Status.NOT_FOUND).entity(
532                     ServiceMessages.GET_FAILED + "permroles permission csid=" + permCsid).type(
533                     "text/plain").build();
534             throw new WebApplicationException(response);
535         } catch (Exception e) {
536             if (logger.isDebugEnabled()) {
537                 logger.debug("getPermissionRole", e);
538             }
539             logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
540             Response response = Response.status(
541                     Response.Status.INTERNAL_SERVER_ERROR).entity(
542                     ServiceMessages.GET_FAILED
543                     + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
544             throw new WebApplicationException(response);
545         }
546         if (result == null) {
547             Response response = Response.status(Response.Status.NOT_FOUND).entity(
548                     ServiceMessages.GET_FAILED + "permroles permisison csid=" + permCsid
549                     + ": was not found.").type(
550                     "text/plain").build();
551             throw new WebApplicationException(response);
552         }
553         return result;
554     }
555
556     /**
557      * Delete permission role.
558      *
559      * @param permCsid the perm csid
560      * @param input the input
561      * @return the response
562      */
563     public Response deletePermissionRole(String permCsid, PermissionRole input) {
564         if (logger.isDebugEnabled()) {
565             logger.debug("Delete payload of permrole relationships with permission permCsid=" + permCsid);
566         }
567         if (permCsid == null || "".equals(permCsid)) {
568             logger.error("deletePermissionRole: missing permCsid!");
569             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
570                     ServiceMessages.DELETE_FAILED + "permroles permission "
571                     + ServiceMessages.MISSING_INVALID_CSID + permCsid).type(
572                     "text/plain").build();
573             throw new WebApplicationException(response);
574         }
575         try {
576             PermissionRoleSubResource subResource =
577                     new PermissionRoleSubResource(PermissionRoleSubResource.PERMISSION_PERMROLE_SERVICE);
578             //delete all relationships for a permission
579             subResource.deletePermissionRole(permCsid, SubjectType.ROLE, input);
580             return Response.status(HttpResponseCodes.SC_OK).build();
581         } catch (UnauthorizedException ue) {
582             Response response = Response.status(
583                     Response.Status.UNAUTHORIZED).entity(ServiceMessages.DELETE_FAILED
584                     + ue.getErrorReason()).type("text/plain").build();
585             throw new WebApplicationException(response);
586         } catch (DocumentNotFoundException dnfe) {
587             if (logger.isDebugEnabled()) {
588                 logger.debug("caught exception in deletePermissionRole", dnfe);
589             }
590             Response response = Response.status(Response.Status.NOT_FOUND).entity(
591                     ServiceMessages.DELETE_FAILED + "permisison csid=" + permCsid).type(
592                     "text/plain").build();
593             throw new WebApplicationException(response);
594         } catch (Exception e) {
595             logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
596             Response response = Response.status(
597                     Response.Status.INTERNAL_SERVER_ERROR).entity(
598                     ServiceMessages.DELETE_FAILED
599                     + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
600             throw new WebApplicationException(response);
601         }
602
603     }
604     
605     /**
606      * Delete permission role.
607      *
608      * @param permCsid the perm csid
609      * @return the response
610      */
611     @DELETE
612     @Path("{csid}/permroles")    
613     public Response deletePermissionRole(
614             @PathParam("csid") String permCsid) {
615         if (logger.isDebugEnabled()) {
616             logger.debug("Delete all the role relationships of the permissions with permCsid=" + permCsid);
617         }
618         if (permCsid == null || "".equals(permCsid)) {
619             logger.error("deletePermissionRole: missing permCsid!");
620             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
621                     ServiceMessages.DELETE_FAILED + "permroles permission "
622                     + ServiceMessages.MISSING_INVALID_CSID + permCsid).type(
623                     "text/plain").build();
624             throw new WebApplicationException(response);
625         }
626         try {
627             PermissionRoleSubResource subResource =
628                     new PermissionRoleSubResource(PermissionRoleSubResource.PERMISSION_PERMROLE_SERVICE);
629             //delete all relationships for a permission
630             subResource.deletePermissionRole(permCsid, SubjectType.ROLE);
631             return Response.status(HttpResponseCodes.SC_OK).build();
632         } catch (UnauthorizedException ue) {
633             Response response = Response.status(
634                     Response.Status.UNAUTHORIZED).entity(ServiceMessages.DELETE_FAILED
635                     + ue.getErrorReason()).type("text/plain").build();
636             throw new WebApplicationException(response);
637         } catch (DocumentNotFoundException dnfe) {
638             if (logger.isDebugEnabled()) {
639                 logger.debug("caught exception in deletePermissionRole", dnfe);
640             }
641             Response response = Response.status(Response.Status.NOT_FOUND).entity(
642                     ServiceMessages.DELETE_FAILED + "permisison csid=" + permCsid).type(
643                     "text/plain").build();
644             throw new WebApplicationException(response);
645         } catch (Exception e) {
646             logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
647             Response response = Response.status(
648                     Response.Status.INTERNAL_SERVER_ERROR).entity(
649                     ServiceMessages.DELETE_FAILED
650                     + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build();
651             throw new WebApplicationException(response);
652         }
653     }
654     
655 }