From 34e720f9176a3ea68942d48bf79b1f80cc9aa8bb Mon Sep 17 00:00:00 2001 From: Brian Van Klaveren Date: Wed, 29 Mar 2017 13:23:11 -0700 Subject: [PATCH] Control message for AccessDeniedException --- .../org/srs/datacat/rest/resources/ContainerResource.java | 8 ++++---- .../org/srs/datacat/rest/resources/DatasetsResource.java | 6 +++--- .../java/org/srs/datacat/rest/resources/PathResource.java | 8 ++++---- .../srs/datacat/rest/resources/PermissionsResource.java | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/rest/src/main/java/org/srs/datacat/rest/resources/ContainerResource.java b/rest/src/main/java/org/srs/datacat/rest/resources/ContainerResource.java index 9582338f..986a7390 100644 --- a/rest/src/main/java/org/srs/datacat/rest/resources/ContainerResource.java +++ b/rest/src/main/java/org/srs/datacat/rest/resources/ContainerResource.java @@ -110,7 +110,7 @@ public Response getChildren( @DefaultValue("100000") @QueryParam("max") int max, } catch (NoSuchFileException ex){ throw new RestException(ex,404, "File doesn't exist", ex.getMessage()); } catch (AccessDeniedException ex){ - throw new RestException(ex, 403); + throw new RestException(ex, 403, ex.getMessage()); } catch (NotDirectoryException ex){ throw new RestException(ex,404,"File exists, but Path is not a container"); } catch (IOException ex){ @@ -152,7 +152,7 @@ public Response createContainer(MultivaluedMap formParams) throw } catch (NoSuchFileException ex){ throw new RestException(ex ,404, "Parent file doesn't exist", ex.getMessage()); } catch (AccessDeniedException ex){ - throw new RestException(ex, 403); + throw new RestException(ex, 403, ex.getMessage()); } catch (NotDirectoryException ex){ throw new RestException(ex, 404, "File exists, but Path is not a container"); } catch (IOException ex){ @@ -186,7 +186,7 @@ public Response createContainerJson(DatasetContainer container) throws IOExcepti } catch (NoSuchFileException ex){ throw new RestException(ex ,404, "Parent file doesn't exist", ex.getMessage()); } catch (AccessDeniedException ex){ - throw new RestException(ex, 403); + throw new RestException(ex, 403, ex.getMessage()); } catch (NotDirectoryException ex){ throw new RestException(ex, 404, "File exists, but Path is not a container"); } catch (IOException ex){ @@ -232,7 +232,7 @@ public Response deleteContainer() throws IOException{ } catch (NoSuchFileException ex){ throw new RestException(ex, 404, "Directory doesn't exist", ex.getMessage()); } catch (AccessDeniedException ex){ - throw new RestException(ex, 403); + throw new RestException(ex, 403, ex.getMessage()); } catch (IOException ex){ Logger.getLogger(PermissionsResource.class.getName()).log(Level.WARNING, "Unknown exception", ex); throw new RestException(ex, 500); diff --git a/rest/src/main/java/org/srs/datacat/rest/resources/DatasetsResource.java b/rest/src/main/java/org/srs/datacat/rest/resources/DatasetsResource.java index 9792dbb6..766cc1fc 100644 --- a/rest/src/main/java/org/srs/datacat/rest/resources/DatasetsResource.java +++ b/rest/src/main/java/org/srs/datacat/rest/resources/DatasetsResource.java @@ -106,7 +106,7 @@ public Response getDataset(@PathParam("id") String path, // TODO: Check exception throw new RestException(ex, 400 , "The target is not a dataset", ex.getMessage()); } catch (AccessDeniedException ex){ - throw new RestException(ex, 403); + throw new RestException(ex, 403, ex.getMessage()); } catch (IOException ex){ Logger.getLogger(PermissionsResource.class.getName()).log(Level.WARNING, "Unknown exception", ex); throw new RestException(ex, 500); @@ -199,7 +199,7 @@ public Response createDataset(java.nio.file.Path datasetPath, DatasetModel reqDs } catch (NoSuchFileException ex){ throw new RestException(ex, 404, "Parent file doesn't exist", ex.getMessage()); } catch (AccessDeniedException ex){ - throw new RestException(ex, 403); + throw new RestException(ex, 403, ex.getMessage()); } catch (NotDirectoryException ex){ throw new RestException(ex, 404, "File exists, but Path is not a container"); } catch (IOException ex){ @@ -294,7 +294,7 @@ private Response handleFileAlreadyExists(FileAlreadyExistsException ex, java.nio locationHeader.put("Location", newUriBuilder.build()); throw new RestException(ex, 409, "A Location Already exists for that site", null, locationHeader); } - throw new RestException(ex, 409); + throw new RestException(ex, 409, ex.getMessage(), ex.getCause().getMessage()); } @PATCH diff --git a/rest/src/main/java/org/srs/datacat/rest/resources/PathResource.java b/rest/src/main/java/org/srs/datacat/rest/resources/PathResource.java index af4c7de4..37d3063a 100644 --- a/rest/src/main/java/org/srs/datacat/rest/resources/PathResource.java +++ b/rest/src/main/java/org/srs/datacat/rest/resources/PathResource.java @@ -110,9 +110,9 @@ public Response getHead(@DefaultValue("false") @QueryParam("refresh") boolean re } catch (IllegalArgumentException ex){ throw new RestException(ex, 400 , "Unable to correctly process view", ex.getMessage()); } catch (NoSuchFileException ex){ - throw new RestException(ex,404 , "File doesn't exist", ex.getMessage()); + throw new RestException(ex, 404 , "File doesn't exist", ex.getMessage()); } catch (AccessDeniedException ex){ - throw new RestException(ex, 403); + throw new RestException(ex, 403, ex.getMessage()); } catch (IOException ex){ Logger.getLogger(PermissionsResource.class.getName()).log(Level.WARNING, "Unknown exception", ex); throw new RestException(ex, 500); @@ -177,9 +177,9 @@ public Response getBean(String path, HashMap> matrixParams, } catch (NoSuchFileException ex){ throw new RestException(ex,404 , "File doesn't exist", ex.getMessage()); } catch (AccessDeniedException ex){ - throw new RestException(ex, 403); + throw new RestException(ex, 403, ex.getMessage()); } catch (IOException ex){ - Logger.getLogger(PermissionsResource.class.getName()).log(Level.WARNING, "Unknown exception", ex); + Logger.getLogger(PermissionsResource.class.getName()).log(Level.WARNING, "Unknown exception", ex); throw new RestException(ex, 500); } } diff --git a/rest/src/main/java/org/srs/datacat/rest/resources/PermissionsResource.java b/rest/src/main/java/org/srs/datacat/rest/resources/PermissionsResource.java index ed120c12..e446d10c 100644 --- a/rest/src/main/java/org/srs/datacat/rest/resources/PermissionsResource.java +++ b/rest/src/main/java/org/srs/datacat/rest/resources/PermissionsResource.java @@ -80,7 +80,7 @@ public Response getAclOrPermissions(@DefaultValue("") @QueryParam("subject") Str } catch (NoSuchFileException ex){ throw new RestException(ex,404 , "File doesn't exist", ex.getMessage()); } catch (AccessDeniedException ex){ - throw new RestException(ex, 403); + throw new RestException(ex, 403, ex.getMessage()); } catch (IOException ex){ Logger.getLogger(PermissionsResource.class.getName()).log(Level.WARNING, "Unknown exception", ex); throw new RestException(ex, 500); @@ -104,7 +104,7 @@ public Response setAcl(List proxyAcl){ } catch (NoSuchFileException ex){ throw new RestException(ex,404 , "File doesn't exist", ex.getMessage()); } catch (AccessDeniedException ex){ - throw new RestException(ex, 403); + throw new RestException(ex, 403, ex.getMessage()); } catch (IOException ex){ Logger.getLogger(PermissionsResource.class.getName()).log(Level.WARNING, "Unknown exception", ex); throw new RestException(ex, 500); @@ -135,7 +135,7 @@ public Response mergeAcl(List proxyAcl){ } catch (NoSuchFileException ex){ throw new RestException(ex,404 , "File doesn't exist", ex.getMessage()); } catch (AccessDeniedException ex){ - throw new RestException(ex, 403); + throw new RestException(ex, 403, ex.getMessage()); } catch (IOException ex){ Logger.getLogger(PermissionsResource.class.getName()).log(Level.WARNING, "Unknown exception", ex); throw new RestException(ex, 500);