use of org.apache.jackrabbit.webdav.DavResource in project jackrabbit by apache.
the class AbstractWebdavServlet method service.
/**
* Service the given request.
*
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
WebdavRequest webdavRequest = new WebdavRequestImpl(request, getLocatorFactory(), isCreateAbsoluteURI());
// DeltaV requires 'Cache-Control' header for all methods except 'VERSION-CONTROL' and 'REPORT'.
int methodCode = DavMethods.getMethodCode(request.getMethod());
boolean noCache = DavMethods.isDeltaVMethod(webdavRequest) && !(DavMethods.DAV_VERSION_CONTROL == methodCode || DavMethods.DAV_REPORT == methodCode);
WebdavResponse webdavResponse = new WebdavResponseImpl(response, noCache);
try {
// make sure there is a authenticated user
if (!getDavSessionProvider().attachSession(webdavRequest)) {
return;
}
// perform referrer host checks if CSRF protection is enabled
if (!csrfUtil.isValidRequest(webdavRequest)) {
webdavResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
// check matching if=header for lock-token relevant operations
DavResource resource = getResourceFactory().createResource(webdavRequest.getRequestLocator(), webdavRequest, webdavResponse);
if (!isPreconditionValid(webdavRequest, resource)) {
webdavResponse.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
return;
}
if (!execute(webdavRequest, webdavResponse, methodCode, resource)) {
super.service(request, response);
}
} catch (DavException e) {
if (e.getErrorCode() == HttpServletResponse.SC_UNAUTHORIZED) {
sendUnauthorized(webdavRequest, webdavResponse, e);
} else {
webdavResponse.sendError(e);
}
} finally {
getDavSessionProvider().releaseSession(webdavRequest);
}
}
use of org.apache.jackrabbit.webdav.DavResource in project jackrabbit by apache.
the class AbstractWebdavServlet method doMove.
/**
* The MOVE method
*
* @param request
* @param response
* @param resource
* @throws IOException
* @throws DavException
*/
protected void doMove(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException {
DavResource destResource = getResourceFactory().createResource(request.getDestinationLocator(), request, response);
int status = validateDestination(destResource, request, true);
if (status > DavServletResponse.SC_NO_CONTENT) {
response.sendError(status);
return;
}
resource.move(destResource);
response.setStatus(status);
}
use of org.apache.jackrabbit.webdav.DavResource in project jackrabbit by apache.
the class AbstractWebdavServlet method doCopy.
/**
* The COPY method
*
* @param request
* @param response
* @param resource
* @throws IOException
* @throws DavException
*/
protected void doCopy(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException {
// only depth 0 and infinity is allowed
int depth = request.getDepth(DEPTH_INFINITY);
if (!(depth == DEPTH_0 || depth == DEPTH_INFINITY)) {
response.sendError(DavServletResponse.SC_BAD_REQUEST);
return;
}
DavResource destResource = getResourceFactory().createResource(request.getDestinationLocator(), request, response);
int status = validateDestination(destResource, request, true);
if (status > DavServletResponse.SC_NO_CONTENT) {
response.sendError(status);
return;
}
resource.copy(destResource, depth == DEPTH_0);
response.setStatus(status);
}
use of org.apache.jackrabbit.webdav.DavResource in project jackrabbit by apache.
the class AbstractWebdavServlet method doDelete.
/**
* The DELETE method
*
* @param request
* @param response
* @param resource
* @throws IOException
* @throws DavException
*/
protected void doDelete(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException {
DavResource parent = resource.getCollection();
if (parent != null) {
parent.removeMember(resource);
response.setStatus(DavServletResponse.SC_NO_CONTENT);
} else {
response.sendError(DavServletResponse.SC_FORBIDDEN, "Cannot remove the root resource.");
}
}
use of org.apache.jackrabbit.webdav.DavResource in project jackrabbit by apache.
the class AbstractWebdavServlet method validateDestination.
/**
* Validate the given destination resource and return the proper status
* code: Any return value greater/equal than {@link DavServletResponse#SC_NO_CONTENT}
* indicates an error.
*
* @param destResource destination resource to be validated.
* @param request
* @param checkHeader flag indicating if the destination header must be present.
* @return status code indicating whether the destination is valid.
*/
protected int validateDestination(DavResource destResource, WebdavRequest request, boolean checkHeader) throws DavException {
if (checkHeader) {
String destHeader = request.getHeader(HEADER_DESTINATION);
if (destHeader == null || "".equals(destHeader)) {
return DavServletResponse.SC_BAD_REQUEST;
}
}
if (destResource.getLocator().equals(request.getRequestLocator())) {
return DavServletResponse.SC_FORBIDDEN;
}
int status;
if (destResource.exists()) {
if (request.isOverwrite()) {
// matching if-header required for existing resources
if (!request.matchesIfHeader(destResource)) {
return DavServletResponse.SC_PRECONDITION_FAILED;
} else {
// overwrite existing resource
DavResource col;
try {
col = destResource.getCollection();
} catch (IllegalArgumentException ex) {
return DavServletResponse.SC_BAD_GATEWAY;
}
col.removeMember(destResource);
status = DavServletResponse.SC_NO_CONTENT;
}
} else {
// cannot copy/move to an existing item, if overwrite is not forced
return DavServletResponse.SC_PRECONDITION_FAILED;
}
} else {
// destination does not exist >> copy/move can be performed
status = DavServletResponse.SC_CREATED;
}
return status;
}
Aggregations