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.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;
42 import org.collectionspace.services.authorization.storage.PermissionRoleDocumentHandler;
43 import org.collectionspace.services.authorization.storage.AuthorizationDelegate;
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;
58 import org.jboss.resteasy.util.HttpResponseCodes;
59 import org.slf4j.Logger;
60 import org.slf4j.LoggerFactory;
63 * The Class PermissionResource.
65 @Path("/authorization/permissions")
66 @Consumes("application/xml")
67 @Produces("application/xml")
68 public class PermissionResource
69 extends AbstractCollectionSpaceResourceImpl<Permission, Permission> {
71 /** The service name. */
72 final private String serviceName = "authorization/permissions";
74 final Logger logger = LoggerFactory.getLogger(PermissionResource.class);
75 /** The storage client. */
76 final StorageClient storageClient = new JpaStorageClientImpl();
79 * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getVersionString()
82 protected String getVersionString() {
83 /** The last change revision. */
84 final String lastChangeRevision = "$LastChangedRevision: 1165 $";
85 return lastChangeRevision;
89 * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getServiceName()
92 public String getServiceName() {
97 * @see org.collectionspace.services.common.CollectionSpaceResource#getCommonPartClass()
100 public Class<Permission> getCommonPartClass() {
101 return Permission.class;
105 * @see org.collectionspace.services.common.CollectionSpaceResource#getServiceContextFactory()
108 public ServiceContextFactory<Permission, Permission> getServiceContextFactory() {
109 return RemoteServiceContextFactory.get();
113 * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getStorageClient(org.collectionspace.services.common.context.ServiceContext)
116 public StorageClient getStorageClient(ServiceContext ctx) {
117 //FIXME use ctx to identify storage client
118 return storageClient;
122 // public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
123 // DocumentHandler docHandler = ctx.getDocumentHandler();
124 // docHandler.setCommonPart(ctx.getInput());
125 // return docHandler;
128 * Creates the permission.
130 * @param input the input
132 * @return the response
135 public Response createPermission(Permission input) {
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();
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);
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);
168 * Gets the permission.
170 * @param csid the csid
172 * @return the permission
176 public Permission getPermission(
177 @PathParam("csid") String csid) {
178 if (logger.isDebugEnabled()) {
179 logger.debug("getPermission with csid=" + csid);
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);
189 Permission result = null;
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);
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);
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);
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);
230 * Gets the permission list.
234 * @return the permission list
237 @Produces("application/xml")
238 public PermissionsList getPermissionList(
239 @Context UriInfo ui) {
240 PermissionsList permissionList = new PermissionsList();
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);
257 } catch (Exception e) {
258 if (logger.isDebugEnabled()) {
259 logger.debug("Caught exception in getPermissionsList", e);
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);
268 return permissionList;
274 * @param csid the csid
275 * @param theUpdate the the update
277 * @return the permission
281 public Permission updatePermission(
282 @PathParam("csid") String csid,
283 Permission theUpdate) {
284 if (logger.isDebugEnabled()) {
285 logger.debug("updatePermission with csid=" + csid);
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);
295 Permission result = null;
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);
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);
333 * @param csid the csid
335 * @return the response
339 public Response deletePermission(@PathParam("csid") String csid) {
341 if (logger.isDebugEnabled()) {
342 logger.debug("deletePermission with csid=" + csid);
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);
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);
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);
374 } catch (DocumentNotFoundException dnfe) {
375 if (logger.isDebugEnabled()) {
376 logger.debug("caught exception in deletePermission", dnfe);
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);
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);
403 if (logger.isDebugEnabled()) {
404 logger.debug("createPermissionRole with permCsid=" + permCsid);
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);
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();
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);
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);
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);
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);
461 PermissionRoleRel result = null;
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);
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);
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);
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);
502 @Path("{csid}/permroles")
503 public PermissionRole getPermissionRole(
504 @PathParam("csid") String permCsid) {
505 if (logger.isDebugEnabled()) {
506 logger.debug("getPermissionRole with permCsid=" + permCsid);
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);
516 PermissionRole result = null;
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);
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);
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);
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);
557 * Delete permission role.
559 * @param permCsid the perm csid
560 * @param input the input
561 * @return the response
563 public Response deletePermissionRole(String permCsid, PermissionRole input) {
564 if (logger.isDebugEnabled()) {
565 logger.debug("Delete payload of permrole relationships with permission permCsid=" + permCsid);
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);
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);
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);
606 * Delete permission role.
608 * @param permCsid the perm csid
609 * @return the response
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);
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);
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);
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);