Search in sources :

Example 6 with DavResource

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);
    }
}
Also used : WebdavRequest(org.apache.jackrabbit.webdav.WebdavRequest) DavResource(org.apache.jackrabbit.webdav.DavResource) WebdavResponseImpl(org.apache.jackrabbit.webdav.WebdavResponseImpl) DavException(org.apache.jackrabbit.webdav.DavException) WebdavRequestImpl(org.apache.jackrabbit.webdav.WebdavRequestImpl) WebdavResponse(org.apache.jackrabbit.webdav.WebdavResponse)

Example 7 with DavResource

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);
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource)

Example 8 with DavResource

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);
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource)

Example 9 with DavResource

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.");
    }
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource)

Example 10 with DavResource

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;
}
Also used : DavResource(org.apache.jackrabbit.webdav.DavResource)

Aggregations

DavResource (org.apache.jackrabbit.webdav.DavResource)40 DavException (org.apache.jackrabbit.webdav.DavException)21 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)19 RepositoryException (javax.jcr.RepositoryException)16 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)7 ArrayList (java.util.ArrayList)6 Node (javax.jcr.Node)6 VersionHistory (javax.jcr.version.VersionHistory)6 DavResourceIteratorImpl (org.apache.jackrabbit.webdav.DavResourceIteratorImpl)5 Version (javax.jcr.version.Version)4 DavResourceIterator (org.apache.jackrabbit.webdav.DavResourceIterator)4 OutputStreamWriter (java.io.OutputStreamWriter)3 PrintWriter (java.io.PrintWriter)3 Item (javax.jcr.Item)3 NodeIterator (javax.jcr.NodeIterator)3 Repository (javax.jcr.Repository)3 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)3 Session (javax.jcr.Session)2 VersionIterator (javax.jcr.version.VersionIterator)2 MultiStatus (org.apache.jackrabbit.webdav.MultiStatus)2