Ignore:
Timestamp:
09/26/14 09:14:41 (10 years ago)
Author:
olhsha@mpi.nl
Message:

bug fixed with the little code restructuring. 403 was not thrown (but 500 for another reason was thrown) when a not-owner tries to update permissions of an annotation. Now it is fixed by removing catching exceptions and messaging errors from auxiliary request wrappers to REST methods directly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/RequestWrappers.java

    r5385 r5679  
    1818package eu.dasish.annotation.backend.rest;
    1919
     20import eu.dasish.annotation.backend.ForbiddenException;
    2021import eu.dasish.annotation.backend.NotInDataBaseException;
    2122import eu.dasish.annotation.backend.PrincipalExists;
     
    6768    }
    6869
    69     public T wrapRequestResource(Map params, ILambda<Map, T> dbRequestor, Resource resource, ResourceAction action, String externalId) throws IOException {
     70    public T wrapRequestResource(Map params, ILambda<Map, T> dbRequestor, Resource resource, ResourceAction action, String externalId) throws IOException, ForbiddenException, NotInDataBaseException {
    7071        Number principalID = resourceResource.getPrincipalID();
    7172        if (principalID == null) {
     
    7374        }
    7475        params.put(_principalID, principalID);
    75         try {
    76             final Number resourceID = resourceResource.dbDispatcher.getResourceInternalIdentifier(UUID.fromString(externalId), resource);
    77             if (resourceResource.dbDispatcher.canDo(action, principalID, resourceID, resource)) {
    78                 params.put(_externalId, externalId);           
    79                 params.put(_internalID, resourceID);
    80                 params.put(_resourceType, resource);
    81                 return dbRequestor.apply(params);
    82             } else {
    83                 this.FORBIDDEN_RESOURCE_ACTION(externalId, resource.name(), action.name());
    84                 resourceResource.loggerServer.debug("Principal " + resourceResource.dbDispatcher.getResourceExternalIdentifier(principalID, Resource.PRINCIPAL) + " cannot " + action.name() + " " + resource.name() + " with the id " + externalId);
    85                 resourceResource.httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
    86                 return null;
    87             }
    88         } catch (NotInDataBaseException e2) {
    89             resourceResource.loggerServer.debug(e2.toString());
    90             resourceResource.httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e2.toString());
    91             return null;
    92         }
    93     }
    94 
    95     public JAXBElement<Principal> wrapAddPrincipalRequest(Map params, ILambdaPrincipal<Map, Principal> dbRequestor) throws IOException {
    96 
    97         try {
    98             try {
    99                 return new ObjectFactory().createPrincipal(dbRequestor.apply(params));
    100             } catch (NotInDataBaseException e1) {
    101                 resourceResource.loggerServer.debug(e1.toString());
    102                 resourceResource.httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e1.toString());
    103                 return new ObjectFactory().createPrincipal(new Principal());
    104             }
    105         } catch (PrincipalExists e) {
    106             resourceResource.loggerServer.debug(e.toString());
    107             resourceResource.httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString());
    108             return new ObjectFactory().createPrincipal(new Principal());
     76        final Number resourceID = resourceResource.dbDispatcher.getResourceInternalIdentifier(UUID.fromString(externalId), resource);
     77        if (resourceResource.dbDispatcher.canDo(action, principalID, resourceID, resource)) {
     78            params.put(_externalId, externalId);
     79            params.put(_internalID, resourceID);
     80            params.put(_resourceType, resource);
     81            return dbRequestor.apply(params);
     82        } else {
     83            throw new ForbiddenException(this.FORBIDDEN_RESOURCE_ACTION(externalId, resource.name(), action.name()));
    10984        }
    11085
    11186    }
     87
     88    public JAXBElement<Principal> wrapAddPrincipalRequest(Map params, ILambdaPrincipal<Map, Principal> dbRequestor) throws IOException, NotInDataBaseException, PrincipalExists {
     89        return new ObjectFactory().createPrincipal(dbRequestor.apply(params));
     90    }
    11291}
Note: See TracChangeset for help on using the changeset viewer.