Search in sources :

Example 16 with BadRequestException

use of io.milton.http.exceptions.BadRequestException 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)

Example 17 with BadRequestException

use of io.milton.http.exceptions.BadRequestException 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 18 with BadRequestException

use of io.milton.http.exceptions.BadRequestException in project lobcder by skoulouzis.

the class MiltonFsView method getFile.

@Override
public FtpFile getFile(String path) throws FtpException {
    try {
        log.debug("getFile: " + path);
        if (path.startsWith(".")) {
            path = currentPath.toString() + path.substring(1);
            log.debug("getFile2: " + path);
        }
        Path p = Path.path(path);
        ResourceAndPath rp = getResource(p);
        if (rp.resource == null) {
            log.debug("returning new file");
            return new MiltonFtpFile(this, rp.path, this.current, null, user);
        } else {
            return new MiltonFtpFile(this, rp.path, rp.resource, user);
        }
    } catch (NotAuthorizedException ex) {
        throw new FtpException(ex);
    } catch (BadRequestException ex) {
        throw new FtpException(ex);
    }
}
Also used : Path(io.milton.common.Path) BadRequestException(io.milton.http.exceptions.BadRequestException) FtpException(org.apache.ftpserver.ftplet.FtpException) NotAuthorizedException(io.milton.http.exceptions.NotAuthorizedException)

Example 19 with BadRequestException

use of io.milton.http.exceptions.BadRequestException in project polymap4-core by Polymap4.

the class WebDavFolderResource method sendContent.

public void sendContent(OutputStream out, Range range, Map<String, String> params, String contentType) throws IOException, NotAuthorizedException, BadRequestException {
    try {
        org.polymap.service.fs.spi.Range fsRange = range != null ? new org.polymap.service.fs.spi.Range(range.getStart(), range.getFinish()) : null;
        ((IContentFolder) node).sendDescription(out, fsRange, params, contentType);
    // if (contentType.toLowerCase().contains( "html" )) {
    // new OutputStreamWriter( out, Charset.forName( "UTF-8" ) )
    // .append( "<hr><em>Generated by POLYMAP3 WebDAV</hr></em>" ).flush();
    // }
    } catch (IOException e) {
        throw e;
    } catch (org.polymap.service.fs.spi.BadRequestException e) {
        throw new BadRequestException(this, e.getMessage());
    }
}
Also used : BadRequestException(io.milton.http.exceptions.BadRequestException) IOException(java.io.IOException) IContentFolder(org.polymap.service.fs.spi.IContentFolder)

Example 20 with BadRequestException

use of io.milton.http.exceptions.BadRequestException in project polymap4-core by Polymap4.

the class WebDavMoveableResource method moveTo.

@Override
public void moveTo(CollectionResource dest, String newName) throws ConflictException, NotAuthorizedException, BadRequestException {
    try {
        IPath destPath = ((ContentNodeResource) dest).getNode().getPath();
        ((IContentMoveable) node).moveTo(destPath, newName);
    } catch (IOException e) {
        log.warn("", e);
        throw new BadRequestException(this, e.getMessage());
    } catch (org.polymap.service.fs.spi.BadRequestException e) {
        throw new BadRequestException(this, e.getMessage());
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) IContentMoveable(org.polymap.service.fs.spi.IContentMoveable) BadRequestException(io.milton.http.exceptions.BadRequestException) IOException(java.io.IOException)

Aggregations

BadRequestException (io.milton.http.exceptions.BadRequestException)37 NotAuthorizedException (io.milton.http.exceptions.NotAuthorizedException)25 IOException (java.io.IOException)15 Resource (io.milton.resource.Resource)11 ConflictException (io.milton.http.exceptions.ConflictException)10 SQLException (java.sql.SQLException)10 Connection (java.sql.Connection)9 Path (io.milton.common.Path)6 NotFoundException (io.milton.http.exceptions.NotFoundException)6 Permissions (nl.uva.cs.lobcder.auth.Permissions)6 CollectionResource (io.milton.resource.CollectionResource)5 URISyntaxException (java.net.URISyntaxException)5 LogicalData (nl.uva.cs.lobcder.resources.LogicalData)5 ReplaceableResource (io.milton.resource.ReplaceableResource)4 BufferingOutputStream (io.milton.common.BufferingOutputStream)3 Range (io.milton.http.Range)3 PreConditionFailedException (io.milton.http.exceptions.PreConditionFailedException)3 GetableResource (io.milton.resource.GetableResource)3 PostableResource (io.milton.resource.PostableResource)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3