use of io.milton.http.exceptions.NotAuthorizedException 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.NotAuthorizedException 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.NotAuthorizedException 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.NotAuthorizedException in project lobcder by skoulouzis.
the class JsonPropPatchHandler method process.
public PropFindResponse process(Resource wrappedResource, String encodedUrl, Map<String, String> params) throws NotAuthorizedException, ConflictException, BadRequestException {
log.trace("process");
Map<QName, String> fields = new HashMap<QName, String>();
for (String fieldName : params.keySet()) {
String sFieldValue = params.get(fieldName);
QName qn;
if (fieldName.contains(":")) {
// name is of form uri:local E.g. MyDav:authorName
String[] parts = fieldName.split(":");
String nsUri = parts[0];
String localName = parts[1];
qn = new QName(nsUri, localName);
} else {
// name is simple form E.g. displayname, default nsUri to DAV
qn = new QName(WebDavProtocol.NS_DAV.getPrefix(), fieldName);
}
log.debug("field: " + qn);
fields.put(qn, sFieldValue);
}
ParseResult parseResult = new ParseResult(fields, null);
if (log.isTraceEnabled()) {
log.trace("check permissions with: " + permissionService.getClass());
}
Set<PropertyAuthoriser.CheckResult> errorFields = permissionService.checkPermissions(HttpManager.request(), Method.PROPPATCH, PropertyAuthoriser.PropertyPermission.WRITE, fields.keySet(), wrappedResource);
if (errorFields != null && errorFields.size() > 0) {
log.info("authorisation errors: " + errorFields.size() + " from permissionService: " + permissionService.getClass());
if (log.isTraceEnabled()) {
for (CheckResult e : errorFields) {
LogUtils.trace(log, " - field error: ", e.getField(), e.getStatus(), e.getDescription());
}
}
throw new NotAuthorizedException(wrappedResource);
} else {
LogUtils.trace(log, "setting properties with", patchSetter.getClass());
PropFindResponse resp = patchSetter.setProperties(encodedUrl, parseResult, wrappedResource);
if (eventManager != null) {
log.trace("fire event");
eventManager.fireEvent(new PropPatchEvent(wrappedResource, resp));
} else {
log.trace("no event manager");
}
if (resp.getErrorProperties().size() > 0) {
LogUtils.warn(log, "Encountered errors setting fields with patch setter", patchSetter.getClass());
}
if (log.isTraceEnabled()) {
if (resp.getErrorProperties().size() > 0) {
for (List<NameAndError> e : resp.getErrorProperties().values()) {
for (NameAndError ne : e) {
LogUtils.trace(log, " - field error setting properties: ", ne.getName(), ne.getError());
}
}
}
}
return resp;
}
}
use of io.milton.http.exceptions.NotAuthorizedException in project lobcder by skoulouzis.
the class PropPatchHandler method doPropPatch.
public PropFindResponse doPropPatch(Request request, Resource resource) throws NotAuthorizedException, IOException, BadRequestException {
InputStream in = request.getInputStream();
ParseResult parseResult = requestParser.getRequestedFields(in);
// Check that the current user has permission to write requested fields
Set<QName> allFields = getAllFields(parseResult);
if (log.isTraceEnabled()) {
log.trace("check permissions with: " + permissionService.getClass().getCanonicalName());
}
Set<PropertyAuthoriser.CheckResult> errorFields = permissionService.checkPermissions(request, request.getMethod(), PropertyAuthoriser.PropertyPermission.WRITE, allFields, resource);
if (errorFields != null && errorFields.size() > 0) {
throw new NotAuthorizedException(resource);
}
String href = request.getAbsoluteUrl();
href = DefaultPropFindPropertyBuilder.fixUrlForWindows(href);
PropFindResponse resp = patchSetter.setProperties(href, parseResult, resource);
return resp;
}
Aggregations