public abstract class AbstractViewFileServlet
extends javax.servlet.http.HttpServlet
Modifier and Type | Class and Description |
---|---|
static class |
AbstractViewFileServlet.JwtAttachmentPermissionException |
Modifier and Type | Field and Description |
---|---|
static String |
IMAGE_ATTACHMENT_JWT_TOKEN_QUERY_PARAM_NAME |
static String |
IMAGE_DISPLAYING_CANNOT_DISPLAY_IMAGE_PATH |
Constructor and Description |
---|
AbstractViewFileServlet() |
Modifier and Type | Method and Description |
---|---|
protected String |
attachmentQuery(javax.servlet.http.HttpServletRequest request)
Validates that path is valid attachment path.
|
protected void |
checkRequesterIsPermittedToViewTheAttachment(Attachment attachment,
javax.servlet.http.HttpServletRequest request,
String exceptionMessage) |
protected void |
copyRange(InputStream is,
OutputStream out,
RangeResponse rangeResponse) |
protected void |
doGet(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
protected Attachment |
getAttachment(String queryWithIdAndFilenameToIgnore)
Looks up the attachment by reading the id from the queryWithIdAndFilenameToIgnore string.
|
protected AttachmentManager |
getAttachmentManager() |
protected abstract int |
getContentLength(String attachmentPath) |
protected abstract void |
getInputStream(javax.servlet.http.HttpServletRequest request,
String attachmentPath,
InputStreamConsumer<io.atlassian.fugue.Unit> consumer)
Gets the attachment file (not the file name) that corresponds to the requested attachment.
|
protected ApplicationUser |
getLoggedInUser() |
protected boolean |
isAnonymousUserPermittedToViewAttachment(Attachment attachment) |
protected boolean |
isImageAttachmentJwtTokenPresent(javax.servlet.http.HttpServletRequest request) |
protected boolean |
isJwtTokenUserPermittedToViewAttachment_andSendAnalyticsEvent(javax.servlet.http.HttpServletRequest request,
Attachment attachment) |
protected boolean |
isLoggedInUserPermittedToViewAttachment(Attachment attachment) |
protected boolean |
isUserLoggedIn() |
protected boolean |
isUserPermittedToViewAttachment(ApplicationUser user,
Attachment attachment) |
protected abstract void |
setResponseContentHeaders(javax.servlet.http.HttpServletRequest request,
Optional<RangeResponse> rangeResponse,
javax.servlet.http.HttpServletResponse response)
Sets the content type, content length and "Content-Disposition" header
of the response based on the values of the attachment found.
|
protected abstract boolean |
supportsRangeRequests()
Returns true if this implementation supports RFC 7233 "Range Requests".
|
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
public static String IMAGE_DISPLAYING_CANNOT_DISPLAY_IMAGE_PATH
public static final String IMAGE_ATTACHMENT_JWT_TOKEN_QUERY_PARAM_NAME
protected AttachmentManager getAttachmentManager()
protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
doGet
in class javax.servlet.http.HttpServlet
javax.servlet.ServletException
IOException
protected abstract int getContentLength(String attachmentPath)
protected abstract boolean supportsRangeRequests()
Returning true means that you must set the appropriate "Content-Range" and "Content-Length" headers for the
partial range we will return in the #setResponseHeaders
implementation.
setResponseContentHeaders(HttpServletRequest, Optional, HttpServletResponse)
protected void copyRange(InputStream is, OutputStream out, RangeResponse rangeResponse) throws IOException
IOException
protected final String attachmentQuery(javax.servlet.http.HttpServletRequest request)
request
- HTTP requestprotected Attachment getAttachment(String queryWithIdAndFilenameToIgnore)
queryWithIdAndFilenameToIgnore
- eg. '/10000/foo.txt'AttachmentNotFoundException
- if no attachment is found after parsing the queryWithIdAndFilenameToIgnore string
or if the resulting attachment id does not exist.DataAccessException
- if there is a problem accessing the database.protected boolean isLoggedInUserPermittedToViewAttachment(Attachment attachment)
protected boolean isJwtTokenUserPermittedToViewAttachment_andSendAnalyticsEvent(javax.servlet.http.HttpServletRequest request, Attachment attachment)
protected boolean isUserPermittedToViewAttachment(ApplicationUser user, Attachment attachment)
protected void checkRequesterIsPermittedToViewTheAttachment(Attachment attachment, javax.servlet.http.HttpServletRequest request, String exceptionMessage) throws PermissionException
PermissionException
protected abstract void getInputStream(javax.servlet.http.HttpServletRequest request, String attachmentPath, InputStreamConsumer<io.atlassian.fugue.Unit> consumer) throws IOException, PermissionException
attachmentPath
- the attachment pathconsumer
- a procedure that consumes the stream with the attachment data.DataAccessException
- If there is a problem looking up the data to support the attachment.AttachmentNotFoundException
- if the attachment does not exist.IOException
- if there is a problem getting the attachment.NoAttachmentDataException
- if the attachment's contents cannot be found.AttachmentReadException
- if a problem occurs when the consumer processes the attachment's contents.PermissionException
protected abstract void setResponseContentHeaders(javax.servlet.http.HttpServletRequest request, Optional<RangeResponse> rangeResponse, javax.servlet.http.HttpServletResponse response) throws InvalidAttachmentPathException, DataAccessException, IOException
The rangeResponse parameter will only be present if this Concrete class declares it supports Range Requests, and the request actually contains a Range header.
request
- HTTP requestrangeResponse
- If present, the partial byte range we will returnresponse
- HTTP responseInvalidAttachmentPathException
DataAccessException
IOException
supportsRangeRequests()
protected boolean isUserLoggedIn()
protected final ApplicationUser getLoggedInUser()
protected final boolean isAnonymousUserPermittedToViewAttachment(Attachment attachment)
protected boolean isImageAttachmentJwtTokenPresent(javax.servlet.http.HttpServletRequest request)
Copyright © 2002-2022 Atlassian. All Rights Reserved.