Search in sources :

Example 6 with CollectionResource

use of io.milton.resource.CollectionResource in project lobcder by skoulouzis.

the class DeleteHelperImpl method isLockedOut.

@Override
public boolean isLockedOut(Request req, Resource r) throws NotAuthorizedException, BadRequestException {
    if (r instanceof DeletableCollectionResource) {
        DeletableCollectionResource dcr = (DeletableCollectionResource) r;
        boolean locked = dcr.isLockedOutRecursive(req);
        if (locked && log.isInfoEnabled()) {
            log.info("isLocked, as reported by DeletableCollectionResource: " + dcr.getName());
        }
        return locked;
    } else if (r instanceof CollectionResource) {
        CollectionResource col = (CollectionResource) r;
        List<Resource> list = new ArrayList<Resource>();
        list.addAll(col.getChildren());
        for (Resource rChild : list) {
            if (rChild instanceof DeletableResource) {
                DeletableResource rChildDel = (DeletableResource) rChild;
                if (isLockedOut(req, rChildDel)) {
                    if (log.isInfoEnabled()) {
                        log.info("isLocked: " + rChild.getName() + " type:" + rChild.getClass());
                    }
                    return true;
                }
            } else {
                if (log.isInfoEnabled()) {
                    log.info("a child resource is not deletable: " + rChild.getName() + " type: " + rChild.getClass());
                }
                return true;
            }
        }
        return false;
    } else {
        boolean locked = handlerHelper.isLockedOut(req, r);
        if (locked && log.isInfoEnabled()) {
            log.info("isLocked, as reported by handlerHelper on resource: " + r.getName());
        }
        return locked;
    }
}
Also used : CollectionResource(io.milton.resource.CollectionResource) DeletableCollectionResource(io.milton.resource.DeletableCollectionResource) DeletableCollectionResource(io.milton.resource.DeletableCollectionResource) DeletableResource(io.milton.resource.DeletableResource) CollectionResource(io.milton.resource.CollectionResource) Resource(io.milton.resource.Resource) DeletableCollectionResource(io.milton.resource.DeletableCollectionResource) ArrayList(java.util.ArrayList) List(java.util.List) DeletableResource(io.milton.resource.DeletableResource)

Example 7 with CollectionResource

use of io.milton.resource.CollectionResource in project lobcder by skoulouzis.

the class MiltonFsView method changeWorkingDirectory.

@Override
public boolean changeWorkingDirectory(String dir) throws FtpException {
    try {
        log.debug("cd: " + dir + " from " + currentPath);
        Path p = Path.path(dir);
        ResourceAndPath rp = getResource(p);
        if (rp.resource == null) {
            log.debug("not found: " + p);
            return false;
        } else if (rp.resource instanceof CollectionResource) {
            current = (CollectionResource) rp.resource;
            currentPath = rp.path;
            log.debug("currentPath is now: " + currentPath);
            return true;
        } else {
            log.debug("not a collection: " + rp.resource.getName());
            return false;
        }
    } catch (NotAuthorizedException ex) {
        throw new FtpException(ex);
    } catch (BadRequestException ex) {
        throw new FtpException(ex);
    }
}
Also used : Path(io.milton.common.Path) CollectionResource(io.milton.resource.CollectionResource) BadRequestException(io.milton.http.exceptions.BadRequestException) FtpException(org.apache.ftpserver.ftplet.FtpException) NotAuthorizedException(io.milton.http.exceptions.NotAuthorizedException)

Example 8 with CollectionResource

use of io.milton.resource.CollectionResource in project lobcder by skoulouzis.

the class MkColHandler method processMakeCol.

private void processMakeCol(HttpManager manager, Request request, Response response, CollectionResource resource, String newName, CollectionResourceCreator creator) throws ConflictException, NotAuthorizedException, BadRequestException, IOException {
    if (!handlerHelper.checkAuthorisation(manager, resource, request)) {
        log.info("not authorised");
        responseHandler.respondUnauthorised(resource, response, request);
        return;
    }
    handlerHelper.checkExpects(responseHandler, request, response);
    MakeCollectionableResource existingCol = (MakeCollectionableResource) resource;
    if (!isCompatible(existingCol)) {
        log.info("not compatible");
        responseHandler.respondMethodNotImplemented(existingCol, response, request);
        return;
    }
    Resource existingChild = existingCol.child(newName);
    if (existingChild != null) {
        log.warn("found already existing item: " + newName + " of type: " + existingChild.getClass() + " with actual name: " + existingChild.getName());
        // throw new ConflictException( existingChild );
        // See http://www.ettrema.com:8080/browse/MIL-86
        // 405 (Method Not Allowed) - MKCOL can only be executed on a deleted/non-existent resource.
        responseHandler.respondMethodNotAllowed(existingChild, response, request);
        return;
    }
    CollectionResource made = creator.createResource(existingCol, newName, request);
    if (made == null) {
        log.warn("createCollection returned null. In resource class: " + existingCol.getClass());
        response.setStatus(Response.Status.SC_METHOD_NOT_ALLOWED);
    } else {
        log.info("created item ok: " + made.getClass());
        manager.getEventManager().fireEvent(new NewFolderEvent(resource));
        response.setStatus(Response.Status.SC_CREATED);
    }
}
Also used : CollectionResource(io.milton.resource.CollectionResource) NewFolderEvent(io.milton.event.NewFolderEvent) MakeCollectionableResource(io.milton.resource.MakeCollectionableResource) CollectionResource(io.milton.resource.CollectionResource) Resource(io.milton.resource.Resource) MakeCollectionableResource(io.milton.resource.MakeCollectionableResource)

Example 9 with CollectionResource

use of io.milton.resource.CollectionResource in project lobcder by skoulouzis.

the class MkColHandler method process.

public void process(HttpManager manager, Request request, Response response, CollectionResourceCreator creator) throws ConflictException, NotAuthorizedException, BadRequestException, IOException {
    if (!handlerHelper.checkExpects(responseHandler, request, response)) {
        return;
    }
    String host = request.getHostHeader();
    String finalurl = HttpManager.decodeUrl(request.getAbsolutePath());
    String name;
    if (log.isDebugEnabled()) {
        log.debug("process request: host: " + host + " url: " + finalurl);
    }
    // this is the parent collection it goes in
    Path finalpath = Path.path(finalurl);
    name = finalpath.getName();
    Path parent = finalpath.getParent();
    String parenturl = parent.toString();
    Resource parentcol = manager.getResourceFactory().getResource(host, parenturl);
    if (parentcol != null) {
        log.debug("process: resource: " + parentcol.getClass().getName());
        if (handlerHelper.isNotCompatible(parentcol, request.getMethod())) {
            log.debug("resource not compatible. Resource class: " + parentcol.getClass() + " handler: " + getClass());
            responseHandler.respondMethodNotImplemented(parentcol, response, request);
            return;
        }
        if (handlerHelper.isLockedOut(request, parentcol)) {
            log.warn("isLockedOut");
            response.setStatus(Status.SC_LOCKED);
            return;
        }
        Resource dest = manager.getResourceFactory().getResource(host, finalpath.toString());
        if (dest != null && handlerHelper.isLockedOut(request, dest)) {
            log.info("destination exists and is locked");
            responseHandler.respondLocked(request, response, dest);
            return;
        } else if (handlerHelper.missingLock(request, parentcol)) {
            log.info("precondition failed");
            // notowner_modify wants this code here
            response.setStatus(Status.SC_PRECONDITION_FAILED);
            return;
        }
        if (parentcol instanceof CollectionResource) {
            CollectionResource col = (CollectionResource) parentcol;
            if (log.isTraceEnabled()) {
                log.trace("process mkcol on parent: " + parentcol.getClass() + " with creator: " + creator.getClass());
            }
            processMakeCol(manager, request, response, col, name, creator);
        } else {
            log.warn("parent collection is no a CollectionResource: " + parentcol.getName());
            responseHandler.respondConflict(parentcol, response, request, "not a collection");
        }
    } else {
        log.warn("parent does not exist: host=" + host + " path=" + parenturl);
        manager.getResponseHandler().respondConflict(parentcol, response, request, name);
    }
}
Also used : Path(io.milton.common.Path) CollectionResource(io.milton.resource.CollectionResource) MakeCollectionableResource(io.milton.resource.MakeCollectionableResource) CollectionResource(io.milton.resource.CollectionResource) Resource(io.milton.resource.Resource)

Example 10 with CollectionResource

use of io.milton.resource.CollectionResource in project lobcder by skoulouzis.

the class CopyHandler method processExistingResource.

@Override
public void processExistingResource(HttpManager manager, Request request, Response response, Resource resource) throws NotAuthorizedException, BadRequestException, ConflictException {
    CopyableResource r = (CopyableResource) resource;
    Dest dest = Utils.getDecodedDestination(request.getDestinationHeader());
    Resource rDest = manager.getResourceFactory().getResource(dest.host, dest.url);
    log.debug("process: copying from: " + r.getName() + " -> " + dest.url + "/" + dest.name);
    if (rDest == null) {
        log.debug("process: destination parent does not exist: " + dest);
        responseHandler.respondConflict(resource, response, request, "Destination does not exist: " + dest);
    } else if (!(rDest instanceof CollectionResource)) {
        log.debug("process: destination exists but is not a collection");
        responseHandler.respondConflict(resource, response, request, "Destination exists but is not a collection: " + dest);
    } else {
        log.debug("process: copy resource to: " + rDest.getName());
        Resource fDest = manager.getResourceFactory().getResource(dest.host, dest.url + "/" + dest.name);
        if (handlerHelper.isLockedOut(request, fDest)) {
            responseHandler.respondLocked(request, response, resource);
            return;
        } else {
            boolean wasDeleted = false;
            CollectionResource colDest = (CollectionResource) rDest;
            Resource rExisting = colDest.child(dest.name);
            if (rExisting != null) {
                if (!canOverwrite(request)) {
                    // Exists, and overwrite = F, disallow - http://www.webdav.org/specs/rfc4918.html#rfc.section.9.8.4
                    log.info("destination resource exists, and overwrite header is not set. dest name: " + dest.name + " dest folder: " + colDest.getName());
                    responseHandler.respondPreconditionFailed(request, response, resource);
                    return;
                } else {
                    // Overwrite is absent or T, so continue
                    if (deleteHelper.isLockedOut(request, rExisting)) {
                        log.info("destination resource exists, and overwrite header IS set, but destination is locked. dest name: " + dest.name + " dest folder: " + colDest.getName());
                        responseHandler.respondPreconditionFailed(request, response, resource);
                        return;
                    } else {
                        if (deleteExistingBeforeCopy) {
                            if (rExisting instanceof DeletableResource) {
                                log.debug("copy destination exists and is deletable, delete it..");
                                DeletableResource dr = (DeletableResource) rExisting;
                                // Check the user can delete
                                if (!handlerHelper.checkAuthorisation(manager, dr, request, Method.DELETE, request.getAuthorization())) {
                                    responseHandler.respondUnauthorised(colDest, response, request);
                                    return;
                                }
                                deleteHelper.delete(dr, manager.getEventManager());
                                wasDeleted = true;
                            } else {
                                log.warn("copy destination exists and is a collection so must be deleted, but does not implement: " + DeletableResource.class);
                                responseHandler.respondConflict(rExisting, response, request, dest.toString());
                                return;
                            }
                        }
                    }
                }
            }
            // the resource identified in the dest header
            if (!handlerHelper.checkAuthorisation(manager, colDest, request, request.getMethod(), request.getAuthorization())) {
                responseHandler.respondUnauthorised(colDest, response, request);
                return;
            }
            r.copyTo(colDest, dest.name);
            // See http://www.ettrema.com:8080/browse/MIL-87
            if (wasDeleted) {
                responseHandler.respondNoContent(resource, response, request);
            } else {
                responseHandler.respondCreated(resource, response, request);
            }
        }
    }
}
Also used : CollectionResource(io.milton.resource.CollectionResource) CopyableResource(io.milton.resource.CopyableResource) DeletableResource(io.milton.resource.DeletableResource) Resource(io.milton.resource.Resource) CollectionResource(io.milton.resource.CollectionResource) CopyableResource(io.milton.resource.CopyableResource) DeletableResource(io.milton.resource.DeletableResource)

Aggregations

CollectionResource (io.milton.resource.CollectionResource)19 Resource (io.milton.resource.Resource)16 MakeCollectionableResource (io.milton.resource.MakeCollectionableResource)7 Path (io.milton.common.Path)6 BadRequestException (io.milton.http.exceptions.BadRequestException)5 NotAuthorizedException (io.milton.http.exceptions.NotAuthorizedException)5 GetableResource (io.milton.resource.GetableResource)5 PutableResource (io.milton.resource.PutableResource)5 ConflictException (io.milton.http.exceptions.ConflictException)4 DeletableResource (io.milton.resource.DeletableResource)3 ReplaceableResource (io.milton.resource.ReplaceableResource)3 QName (javax.xml.namespace.QName)3 NewFolderEvent (io.milton.event.NewFolderEvent)2 CopyableResource (io.milton.resource.CopyableResource)2 MoveableResource (io.milton.resource.MoveableResource)2 PostableResource (io.milton.resource.PostableResource)2 PropFindableResource (io.milton.resource.PropFindableResource)2 ArrayList (java.util.ArrayList)2 FtpException (org.apache.ftpserver.ftplet.FtpException)2 MoveEvent (io.milton.event.MoveEvent)1