SharedResource { @GET @Path("{uuid}/documents") @ApiOperation(value = "Get shared document from resource token", response = DocumentRevisionDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of DocumentRevisionDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) public Response getDocumentWithSharedEntity( @ApiParam(required = false, value = "Password for resource") @HeaderParam("password") String password, @ApiParam(required = true, value = "Resource token") @PathParam("uuid") String uuid) throws SharedEntityNotFoundException { SharedEntity sharedEntity = shareManager.findSharedEntityForGivenUUID(uuid); if (sharedEntity.getExpireDate() != null && sharedEntity.getExpireDate().getTime() < new Date().getTime()) { shareManager.deleteSharedEntityIfExpired(sharedEntity); return createExpiredEntityResponse(); } if (!checkPasswordAccess(sharedEntity.getPassword(), password)) { return createPasswordProtectedResponse(); } String sharedEntityToken = JWTokenFactory.createSharedEntityToken(authConfig.getJWTKey(), sharedEntity); DocumentRevision documentRevision = ((SharedDocument) sharedEntity).getDocumentRevision(); return Response.ok().header("shared-entity-token", sharedEntityToken).entity(mapper.map(documentRevision, DocumentRevisionDTO.class)).build(); } SharedResource(); @PostConstruct void init(); @GET @Path("{workspaceId}/documents/{documentId}-{documentVersion}") @ApiOperation(value = "Get shared document revision", response = DocumentRevisionDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of DocumentRevisionDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) Response getPublicSharedDocumentRevision(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Document master id") @PathParam("documentId") String documentId,
            @ApiParam(required = true, value = "Document version") @PathParam("documentVersion") String documentVersion); @GET @Path("{workspaceId}/parts/{partNumber}-{partVersion}") @ApiOperation(value = "Get shared part revision", response = PartRevisionDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of DocumentRevisionDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) Response getPublicSharedPartRevision(
            @ApiParam(required = true, value = "Workspace id") @PathParam("workspaceId") String workspaceId,
            @ApiParam(required = true, value = "Part number") @PathParam("partNumber") String partNumber,
            @ApiParam(required = true, value = "Part version") @PathParam("partVersion") String partVersion); @GET @Path("{uuid}/documents") @ApiOperation(value = "Get shared document from resource token", response = DocumentRevisionDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of DocumentRevisionDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) Response getDocumentWithSharedEntity(
            @ApiParam(required = false, value = "Password for resource") @HeaderParam("password") String password,
            @ApiParam(required = true, value = "Resource token") @PathParam("uuid") String uuid); @GET @Path("{uuid}/parts") @ApiOperation(value = "Get shared part from resource token", response = PartRevisionDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Successful retrieval of PartRevisionDTO"), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 500, message = "Internal server error") }) @Produces(MediaType.APPLICATION_JSON) Response getPartWithSharedEntity(
            @ApiParam(required = false, value = "Password for resource") @HeaderParam("password") String password,
            @ApiParam(required = true, value = "Resource token") @PathParam("uuid") String uuid);  }
@Test public void getDocumentWithSharedEntityTest() throws ApplicationException, UnsupportedEncodingException, NoSuchAlgorithmException { String uuid = "uuid"; Workspace workspace = new Workspace(workspaceId); User user = new User(); DocumentRevision document = new DocumentRevision(); SharedEntity sharedEntity = new SharedDocument(workspace, user, document); sharedEntity.setUuid(uuid); Mockito.when(shareManager.findSharedEntityForGivenUUID(uuid)) .thenReturn(sharedEntity); Response response = sharedResource.getDocumentWithSharedEntity(null, uuid); Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); Calendar c = Calendar.getInstance(); c.setTime(new Date()); c.add(Calendar.HOUR, -2); sharedEntity.setExpireDate(c.getTime()); response = sharedResource.getDocumentWithSharedEntity(null, uuid); Assert.assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); Assert.assertEquals("{\"forbidden\":\"entity-expired\"}", response.getEntity()); c.setTime(new Date()); c.add(Calendar.HOUR, 4); sharedEntity.setExpireDate(c.getTime()); response = sharedResource.getDocumentWithSharedEntity(null, uuid); Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); Assert.assertNotNull(response.getEntity()); sharedEntity.setPassword(HashUtils.md5Sum("foo")); response = sharedResource.getDocumentWithSharedEntity(null, uuid); Assert.assertEquals(Response.Status.FORBIDDEN.getStatusCode(), response.getStatus()); response = sharedResource.getDocumentWithSharedEntity("foo", uuid); Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); Assert.assertNotNull(response.getEntity()); }