Search in sources :

Example 6 with Resource

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

the class ResourceList method _exclude.

public ResourceList _exclude(String... s) {
    ResourceList newList = new ResourceList(this);
    Iterator<CommonResource> it = newList.iterator();
    while (it.hasNext()) {
        Resource ct = it.next();
        if (contains(s, ct.getName())) {
            it.remove();
        }
    }
    return newList;
}
Also used : CollectionResource(io.milton.resource.CollectionResource) Resource(io.milton.resource.Resource)

Example 7 with Resource

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

the class ResourceList method remove.

@Override
public boolean remove(Object o) {
    if (o instanceof Resource) {
        Resource e = (Resource) o;
        map.remove(e.getName());
    }
    return super.remove(o);
}
Also used : CollectionResource(io.milton.resource.CollectionResource) Resource(io.milton.resource.Resource)

Example 8 with Resource

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

the class UsersAnnotationHandler method findUser.

public AnnoPrincipalResource findUser(AnnoCollectionResource root, String name) {
    try {
        // a @Authenticate annotation on their ChildOf or ChildrenOf methods
        for (CommonResource col : root.getChildren()) {
            if (col instanceof AnnoCollectionResource) {
                AnnoCollectionResource acr = (AnnoCollectionResource) col;
                List<ControllerMethod> availMethods = getMethods(acr.getSource().getClass());
                if (!availMethods.isEmpty()) {
                    Resource r = acr.child(name);
                    if (r instanceof AnnoPrincipalResource) {
                        AnnoPrincipalResource apr = (AnnoPrincipalResource) r;
                        return apr;
                    }
                }
            }
        }
    } catch (NotAuthorizedException e) {
        throw new RuntimeException(e);
    } catch (BadRequestException e) {
        throw new RuntimeException(e);
    }
    return null;
}
Also used : Resource(io.milton.resource.Resource) BadRequestException(io.milton.http.exceptions.BadRequestException) NotAuthorizedException(io.milton.http.exceptions.NotAuthorizedException)

Example 9 with Resource

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

the class FckQuickUploaderResource method processFileUpload.

private void processFileUpload(FileItem f, Map<String, String> params) throws BadRequestException, NotAuthorizedException {
    CollectionResource target = null;
    if (wrappedResource == null) {
        throw new BadRequestException(this, "collection not found");
    }
    target = (CollectionResource) wrappedResource.child("uploads");
    if (target == null) {
        try {
            if (wrappedResource instanceof MakeCollectionableResource) {
                MakeCollectionableResource mk = (MakeCollectionableResource) wrappedResource;
                target = mk.createCollection("uploads");
            } else {
                throw new BadRequestException(target, "Cant create subfolder");
            }
        } catch (ConflictException ex) {
            throw new RuntimeException(ex);
        } catch (NotAuthorizedException ex) {
            throw new RuntimeException(ex);
        } catch (BadRequestException ex) {
            throw new RuntimeException(ex);
        }
    }
    String name = FileUtils.sanitiseName(f.getName());
    log.debug("processFileUpload: " + name);
    boolean isFirst = true;
    String newName = null;
    while (target.child(name) != null) {
        name = FileUtils.incrementFileName(name, isFirst);
        newName = name;
        isFirst = false;
    }
    long size = f.getSize();
    try {
        if (target instanceof PutableResource) {
            PutableResource putable = (PutableResource) target;
            Resource newRes = putable.createNew(name, f.getInputStream(), size, null);
            if (newRes != null) {
                log.trace("created: " + newRes.getName() + " of type: " + newRes.getClass());
            } else {
                log.trace("createNew returned null");
            }
        } else {
            throw new BadRequestException(target, "Does not implement PutableResource");
        }
    } catch (ConflictException ex) {
        throw new RuntimeException(ex);
    } catch (NotAuthorizedException ex) {
        throw new RuntimeException(ex);
    } catch (BadRequestException ex) {
        throw new RuntimeException(ex);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
    try {
        if (newName != null) {
            // we renamed the file
            uploadResponseOk(name);
        } else {
            uploadResponseOk();
        }
    } catch (Throwable ex) {
        log.error("Exception saving new file", ex);
        uploadResponseFailed(ex.getMessage());
    }
}
Also used : CollectionResource(io.milton.resource.CollectionResource) ConflictException(io.milton.http.exceptions.ConflictException) PutableResource(io.milton.resource.PutableResource) MakeCollectionableResource(io.milton.resource.MakeCollectionableResource) Resource(io.milton.resource.Resource) CollectionResource(io.milton.resource.CollectionResource) NotAuthorizedException(io.milton.http.exceptions.NotAuthorizedException) IOException(java.io.IOException) BadRequestException(io.milton.http.exceptions.BadRequestException) MakeCollectionableResource(io.milton.resource.MakeCollectionableResource) PutableResource(io.milton.resource.PutableResource)

Example 10 with Resource

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

the class UserManagerAdapter method authenticate.

@Override
public User authenticate(Authentication authentication) throws AuthenticationFailedException {
    if (authentication instanceof UsernamePasswordAuthentication) {
        UsernamePasswordAuthentication upa = (UsernamePasswordAuthentication) authentication;
        String user = upa.getUsername();
        String password = upa.getPassword();
        log.debug("authenticate: " + user);
        NameAndAuthority naa = NameAndAuthority.parse(user);
        if (naa.domain == null) {
            log.warn("invalid login. no domain specified. use form: user#domain");
            return null;
        }
        Resource hostRoot;
        try {
            hostRoot = resourceFactory.getResource(naa.domain, "/");
        } catch (NotAuthorizedException ex) {
            throw new RuntimeException(ex);
        } catch (BadRequestException ex) {
            throw new RuntimeException(ex);
        }
        if (hostRoot == null) {
            log.warn("failed to find root for domain: " + naa.domain);
            return null;
        }
        Object oUser = hostRoot.authenticate(naa.toMilton(), password);
        if (oUser != null) {
            return new MiltonUser(oUser, naa.toMilton(), naa.domain);
        } else {
            log.debug("authentication failed: " + user);
            return null;
        }
    } else if (authentication instanceof AnonymousAuthentication) {
        log.debug("anonymous login not supported");
        return null;
    } else {
        log.warn("unknown authentication type: " + authentication.getClass());
        return null;
    }
}
Also used : AnonymousAuthentication(org.apache.ftpserver.usermanager.AnonymousAuthentication) UsernamePasswordAuthentication(org.apache.ftpserver.usermanager.UsernamePasswordAuthentication) Resource(io.milton.resource.Resource) BadRequestException(io.milton.http.exceptions.BadRequestException) NotAuthorizedException(io.milton.http.exceptions.NotAuthorizedException)

Aggregations

Resource (io.milton.resource.Resource)37 CollectionResource (io.milton.resource.CollectionResource)23 BadRequestException (io.milton.http.exceptions.BadRequestException)11 NotAuthorizedException (io.milton.http.exceptions.NotAuthorizedException)10 Path (io.milton.common.Path)9 MakeCollectionableResource (io.milton.resource.MakeCollectionableResource)8 PutableResource (io.milton.resource.PutableResource)8 GetableResource (io.milton.resource.GetableResource)7 ConflictException (io.milton.http.exceptions.ConflictException)6 ReplaceableResource (io.milton.resource.ReplaceableResource)6 DeletableResource (io.milton.resource.DeletableResource)5 PostableResource (io.milton.resource.PostableResource)4 IOException (java.io.IOException)4 PutEvent (io.milton.event.PutEvent)3 LockableResource (io.milton.resource.LockableResource)3 PropFindableResource (io.milton.resource.PropFindableResource)3 NewFolderEvent (io.milton.event.NewFolderEvent)2 CopyableResource (io.milton.resource.CopyableResource)2 LockingCollectionResource (io.milton.resource.LockingCollectionResource)2 MoveableResource (io.milton.resource.MoveableResource)2