use of fi.otavanopisto.security.rest.RESTPermit.Handling in project muikku by otavanopisto.
the class TranscriptofRecordsRESTService method getFileContent.
@GET
@Path("/files/{ID}/content")
@RESTPermit(handling = Handling.INLINE)
@Produces("*/*")
public Response getFileContent(@PathParam("ID") Long fileId) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.FORBIDDEN).entity("Must be logged in").build();
}
UserEntity loggedUserEntity = sessionController.getLoggedUserEntity();
TranscriptOfRecordsFile file = transcriptOfRecordsFileController.findFileById(fileId);
if (file == null) {
return Response.status(Status.NOT_FOUND).entity("File not found").build();
}
boolean isLoggedUser = Objects.equals(file.getUserEntityId(), loggedUserEntity.getId());
if (!isLoggedUser) {
return Response.status(Status.FORBIDDEN).entity("Not your file").build();
}
StreamingOutput output = s -> transcriptOfRecordsFileController.outputFileToStream(file, s);
String contentType = file.getContentType();
return Response.ok().type(contentType).entity(output).build();
}
use of fi.otavanopisto.security.rest.RESTPermit.Handling in project muikku by otavanopisto.
the class WorkspaceRESTService method getWorkspaceFileContent.
@GET
@Path("/workspaces/{WORKSPACEID}/workspacefile/{FILEIDENTIFIER}")
@RESTPermit(handling = Handling.INLINE)
public Response getWorkspaceFileContent(@PathParam("WORKSPACEID") Long workspaceId, @PathParam("FILEIDENTIFIER") String fileIdentifier, @Context Request request) {
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceId);
if (workspaceEntity == null)
return Response.status(Status.BAD_REQUEST).build();
WorkspaceEntityFile imageFile = workspaceEntityFileController.findWorkspaceEntityFile(workspaceEntity, fileIdentifier);
if (imageFile == null)
return Response.status(Status.NOT_FOUND).build();
StreamingOutput output = s -> fileController.outputFileToStream("workspace", imageFile.getDiskName(), s);
String contentType = imageFile.getContentType();
String tagIdentifier = String.format("%d-%s-%d", imageFile.getWorkspaceEntity(), imageFile.getDiskName(), imageFile.getLastModified().getTime());
EntityTag tag = new EntityTag(DigestUtils.md5Hex(String.valueOf(tagIdentifier)));
ResponseBuilder builder = request.evaluatePreconditions(tag);
if (builder != null) {
return builder.build();
}
CacheControl cacheControl = new CacheControl();
cacheControl.setMustRevalidate(true);
return Response.ok().cacheControl(cacheControl).tag(tag).type(contentType).entity(output).build();
}
Aggregations