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;
}
}
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);
}
}
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);
}
}
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());
}
}
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());
}
}
Aggregations