use of io.milton.http.exceptions.NotAuthorizedException in project lobcder by skoulouzis.
the class PropPatchHandler method processExistingResource.
@Override
public void processExistingResource(HttpManager manager, Request request, Response response, Resource resource) throws NotAuthorizedException, BadRequestException, ConflictException {
// todo: check if token header
try {
PropFindResponse resp = doPropPatch(request, resource);
manager.getEventManager().fireEvent(new PropPatchEvent(resource, resp));
List<PropFindResponse> responses = new ArrayList<PropFindResponse>();
responses.add(resp);
responseHandler.respondPropFind(responses, response, request, resource);
} catch (NotAuthorizedException e) {
responseHandler.respondUnauthorised(resource, response, request);
} catch (WritingException ex) {
throw new RuntimeException(ex);
} catch (ReadingException ex) {
throw new RuntimeException(ex);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
use of io.milton.http.exceptions.NotAuthorizedException in project lobcder by skoulouzis.
the class AnnoPrincipalResource method getCalendarHomeSet.
@Override
public HrefList getCalendarHomeSet() {
try {
HrefList list = new HrefList();
for (Resource r : getChildren()) {
if (r instanceof AnnoCollectionResource) {
AnnoCollectionResource col = (AnnoCollectionResource) r;
if (annoFactory.calendarsAnnotationHandler.hasCalendars(col.getSource())) {
list.add(col.getHref());
}
}
}
if (list.isEmpty()) {
ResourceList topDirs = getChildren().getDirs();
if (topDirs.isEmpty()) {
log.warn("Could not find any calendar home directories for user type: " + getSource().getClass() + ". In fact there are no child diretories at all!");
} else {
log.warn("Could not find any calendar home directories for user type: " + getSource().getClass() + " You should have a @" + Calendars.class + " annotation on one of the following methods");
for (Resource r : topDirs) {
if (r instanceof AnnoCollectionResource) {
AnnoCollectionResource col = (AnnoCollectionResource) r;
List<ControllerMethod> candMethods = annoFactory.calendarsAnnotationHandler.getMethods(col.getSource().getClass());
if (candMethods.isEmpty()) {
log.info(" - inspecting: " + col.getName() + " for source: " + col.getSource().getClass() + " - has NO child methods");
} else {
log.info(" - inspecting: " + col.getName() + " for source: " + col.getSource().getClass());
for (ControllerMethod cm : candMethods) {
log.warn(" - candidate method: " + cm.controller.getClass() + "::" + cm.method.getName());
}
}
} else {
log.warn(" - found a directory which is not a AnnoCollectionResource: " + r.getClass() + " which cannot be inspected");
}
}
}
}
return list;
} catch (NotAuthorizedException e) {
throw new RuntimeException(e);
} catch (BadRequestException e) {
throw new RuntimeException(e);
}
}
use of io.milton.http.exceptions.NotAuthorizedException in project lobcder by skoulouzis.
the class MiltonFtpFile method isWritable.
/**
* Check file write permission.
*/
@Override
public boolean isWritable() {
try {
log.debug("isWritable: " + getAbsolutePath());
if (path.isRoot())
return false;
Auth auth = new Auth(user.getName(), user.getUser());
FtpRequest request = new FtpRequest(Method.DELETE, auth, path.toString());
if (r != null) {
if (r instanceof ReplaceableResource) {
return r.authorise(request, Method.PUT, auth);
}
}
if (getParent() instanceof PutableResource) {
return getParent().authorise(request, Method.PUT, auth);
} else {
return false;
}
} catch (NotAuthorizedException ex) {
throw new RuntimeException(ex);
} catch (BadRequestException ex) {
throw new RuntimeException(ex);
}
}
use of io.milton.http.exceptions.NotAuthorizedException in project lobcder by skoulouzis.
the class MiltonFtpFile method createOutputStream.
@Override
public OutputStream createOutputStream(long offset) throws IOException {
log.debug("createOutputStream: " + offset);
final BufferingOutputStream out = new BufferingOutputStream(50000);
if (r instanceof ReplaceableResource) {
log.debug("resource is replaceable");
final ReplaceableResource rr = (ReplaceableResource) r;
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
rr.replaceContent(out.getInputStream(), out.getSize());
} catch (BadRequestException ex) {
throw new RuntimeException(ex);
} catch (ConflictException ex) {
throw new RuntimeException(ex);
} catch (NotAuthorizedException ex) {
throw new RuntimeException(ex);
}
}
};
out.setOnClose(runnable);
return out;
} else {
CollectionResource col;
try {
col = getParent();
} catch (NotAuthorizedException ex) {
throw new RuntimeException(ex);
} catch (BadRequestException ex) {
throw new RuntimeException(ex);
}
if (col == null) {
throw new IOException("parent not found");
} else if (col instanceof PutableResource) {
final PutableResource putableResource = (PutableResource) col;
final String newName = path.getName();
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
putableResource.createNew(newName, out.getInputStream(), out.getSize(), null);
} catch (BadRequestException ex) {
throw new RuntimeException(ex);
} catch (NotAuthorizedException ex) {
throw new RuntimeException(ex);
} catch (ConflictException ex) {
throw new RuntimeException(ex);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
};
out.setOnClose(runnable);
return out;
} else {
throw new IOException("folder doesnt support PUT, and the resource is not replaceable");
}
}
}
use of io.milton.http.exceptions.NotAuthorizedException in project lobcder by skoulouzis.
the class MiltonFtpFile method createInputStream.
@Override
public InputStream createInputStream(long offset) throws IOException {
if (r instanceof GetableResource) {
GetableResource gr = (GetableResource) r;
String ct = gr.getContentType(null);
BufferingOutputStream out = new BufferingOutputStream(50000);
try {
gr.sendContent(out, null, null, ct);
out.close();
return out.getInputStream();
} catch (NotFoundException ex) {
log.warn("Not found exception", ex);
return null;
} catch (BadRequestException ex) {
log.warn("bad request", ex);
return null;
} catch (NotAuthorizedException ex) {
log.warn("not authorising", ex);
return null;
}
} else {
return null;
}
}
Aggregations