@SneakyThrows @Test void listDocumentsTest() { Uri location = new Uri("s3: PrivateResource privateResource = new BasePrivateResource(location).resolve(new Uri("/path/to/file.txt"), new Uri("/path/to/file.txt")); AbsoluteLocation<ResolvedResource> resolvedPrivate = new AbsoluteLocation<>(new BaseResolvedResource(privateResource, Instant.now())); when(dataSafeService.privateService().list(any())).thenReturn(new PasswordClearingStream<>(Stream.of(resolvedPrivate), null)); RestDocumentationResultHandler document = document("document-list-success", pathParameters( parameterWithName("path").description("path to the file") ), requestHeaders( headerWithName("token").description(TOKEN_DESCRIPTION), headerWithName("user").description(USER_DESCRIPTION), headerWithName("password").description(PASSWORD_DESCRIPTION) ) ); String path = ""; mvc.perform(get("/documents/{path}", path) .header("user", TEST_USER) .header("password", TEST_PASS) .header("token", token) ).andExpect(status().isOk()) .andDo(document); verify(privateSpaceService).list(any()); }
@GetMapping("/documents/{path:.*}") @ApiOperation("List documents in user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "List command successfully completed"), @ApiResponse(code = 401, message = "Unauthorised") }) public List<String> listDocuments(@RequestHeader String user, @RequestHeader String password, @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId, @ApiParam(defaultValue = ".") @PathVariable(required = false) String path) { UserIDAuth userIDAuth = new UserIDAuth(new UserID(user), ReadKeyPasswordHelper.getForString(password)); path = Optional.ofNullable(path) .map(it -> it.replaceAll("^\\.$", "")) .orElse("./"); try { List<String> documentList = datasafeService.privateService().list( ListRequest.forPrivate(userIDAuth, new StorageIdentifier(storageId), path)) .map(e -> e.getResource().asPrivate().decryptedPath().asString()) .collect(Collectors.toList()); log.debug("List for path {} returned {} items", path, documentList.size()); return documentList; } catch (AmazonS3Exception e) { throw new UnauthorizedException("Unauthorized", e); } }
DocumentController { @GetMapping("/documents/{path:.*}") @ApiOperation("List documents in user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "List command successfully completed"), @ApiResponse(code = 401, message = "Unauthorised") }) public List<String> listDocuments(@RequestHeader String user, @RequestHeader String password, @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId, @ApiParam(defaultValue = ".") @PathVariable(required = false) String path) { UserIDAuth userIDAuth = new UserIDAuth(new UserID(user), ReadKeyPasswordHelper.getForString(password)); path = Optional.ofNullable(path) .map(it -> it.replaceAll("^\\.$", "")) .orElse("./"); try { List<String> documentList = datasafeService.privateService().list( ListRequest.forPrivate(userIDAuth, new StorageIdentifier(storageId), path)) .map(e -> e.getResource().asPrivate().decryptedPath().asString()) .collect(Collectors.toList()); log.debug("List for path {} returned {} items", path, documentList.size()); return documentList; } catch (AmazonS3Exception e) { throw new UnauthorizedException("Unauthorized", e); } } }
DocumentController { @GetMapping("/documents/{path:.*}") @ApiOperation("List documents in user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "List command successfully completed"), @ApiResponse(code = 401, message = "Unauthorised") }) public List<String> listDocuments(@RequestHeader String user, @RequestHeader String password, @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId, @ApiParam(defaultValue = ".") @PathVariable(required = false) String path) { UserIDAuth userIDAuth = new UserIDAuth(new UserID(user), ReadKeyPasswordHelper.getForString(password)); path = Optional.ofNullable(path) .map(it -> it.replaceAll("^\\.$", "")) .orElse("./"); try { List<String> documentList = datasafeService.privateService().list( ListRequest.forPrivate(userIDAuth, new StorageIdentifier(storageId), path)) .map(e -> e.getResource().asPrivate().decryptedPath().asString()) .collect(Collectors.toList()); log.debug("List for path {} returned {} items", path, documentList.size()); return documentList; } catch (AmazonS3Exception e) { throw new UnauthorizedException("Unauthorized", e); } }  }
DocumentController { @GetMapping("/documents/{path:.*}") @ApiOperation("List documents in user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "List command successfully completed"), @ApiResponse(code = 401, message = "Unauthorised") }) public List<String> listDocuments(@RequestHeader String user, @RequestHeader String password, @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId, @ApiParam(defaultValue = ".") @PathVariable(required = false) String path) { UserIDAuth userIDAuth = new UserIDAuth(new UserID(user), ReadKeyPasswordHelper.getForString(password)); path = Optional.ofNullable(path) .map(it -> it.replaceAll("^\\.$", "")) .orElse("./"); try { List<String> documentList = datasafeService.privateService().list( ListRequest.forPrivate(userIDAuth, new StorageIdentifier(storageId), path)) .map(e -> e.getResource().asPrivate().decryptedPath().asString()) .collect(Collectors.toList()); log.debug("List for path {} returned {} items", path, documentList.size()); return documentList; } catch (AmazonS3Exception e) { throw new UnauthorizedException("Unauthorized", e); } }  @SneakyThrows @GetMapping(value = "/document/{path:.*}", produces = APPLICATION_OCTET_STREAM_VALUE) @ApiOperation("Read document from user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document was successfully read"), @ApiResponse(code = 401, message = "Document not found") }) void readDocument(@RequestHeader String user,
                             @RequestHeader String password,
                             @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId,
                             @PathVariable String path,
                             HttpServletResponse response); @SneakyThrows @PutMapping(value = "/document/{path:.*}", consumes = MULTIPART_FORM_DATA_VALUE) @ApiOperation("Write document to user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document was successfully written") }) void writeDocument(@RequestHeader String user,
                              @RequestHeader String password,
                              @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId,
                              @PathVariable String path,
                              @RequestParam("file") MultipartFile file); @GetMapping("/documents/{path:.*}") @ApiOperation("List documents in user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "List command successfully completed"), @ApiResponse(code = 401, message = "Unauthorised") }) List<String> listDocuments(@RequestHeader String user,
                                      @RequestHeader String password,
                                      @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId,
                                      @ApiParam(defaultValue = ".")
                                      @PathVariable(required = false) String path); @DeleteMapping("/document/{path:.*}") @ApiOperation("Delete document from user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document successfully deleted") }) void removeDocument(@RequestHeader String user,
                               @RequestHeader String password,
                               @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId,
                               @PathVariable String path); }
DocumentController { @GetMapping("/documents/{path:.*}") @ApiOperation("List documents in user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "List command successfully completed"), @ApiResponse(code = 401, message = "Unauthorised") }) public List<String> listDocuments(@RequestHeader String user, @RequestHeader String password, @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId, @ApiParam(defaultValue = ".") @PathVariable(required = false) String path) { UserIDAuth userIDAuth = new UserIDAuth(new UserID(user), ReadKeyPasswordHelper.getForString(password)); path = Optional.ofNullable(path) .map(it -> it.replaceAll("^\\.$", "")) .orElse("./"); try { List<String> documentList = datasafeService.privateService().list( ListRequest.forPrivate(userIDAuth, new StorageIdentifier(storageId), path)) .map(e -> e.getResource().asPrivate().decryptedPath().asString()) .collect(Collectors.toList()); log.debug("List for path {} returned {} items", path, documentList.size()); return documentList; } catch (AmazonS3Exception e) { throw new UnauthorizedException("Unauthorized", e); } }  @SneakyThrows @GetMapping(value = "/document/{path:.*}", produces = APPLICATION_OCTET_STREAM_VALUE) @ApiOperation("Read document from user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document was successfully read"), @ApiResponse(code = 401, message = "Document not found") }) void readDocument(@RequestHeader String user,
                             @RequestHeader String password,
                             @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId,
                             @PathVariable String path,
                             HttpServletResponse response); @SneakyThrows @PutMapping(value = "/document/{path:.*}", consumes = MULTIPART_FORM_DATA_VALUE) @ApiOperation("Write document to user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document was successfully written") }) void writeDocument(@RequestHeader String user,
                              @RequestHeader String password,
                              @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId,
                              @PathVariable String path,
                              @RequestParam("file") MultipartFile file); @GetMapping("/documents/{path:.*}") @ApiOperation("List documents in user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "List command successfully completed"), @ApiResponse(code = 401, message = "Unauthorised") }) List<String> listDocuments(@RequestHeader String user,
                                      @RequestHeader String password,
                                      @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId,
                                      @ApiParam(defaultValue = ".")
                                      @PathVariable(required = false) String path); @DeleteMapping("/document/{path:.*}") @ApiOperation("Delete document from user's private space") @ApiResponses(value = { @ApiResponse(code = 200, message = "Document successfully deleted") }) void removeDocument(@RequestHeader String user,
                               @RequestHeader String password,
                               @RequestHeader(defaultValue = StorageIdentifier.DEFAULT_ID) String storageId,
                               @PathVariable String path);  }