use of io.milton.resource.Resource in project lobcder by skoulouzis.
the class DeleteHelperImpl method isLockedOut.
@Override
public boolean isLockedOut(Request req, Resource r) throws NotAuthorizedException, BadRequestException {
if (r instanceof DeletableCollectionResource) {
DeletableCollectionResource dcr = (DeletableCollectionResource) r;
boolean locked = dcr.isLockedOutRecursive(req);
if (locked && log.isInfoEnabled()) {
log.info("isLocked, as reported by DeletableCollectionResource: " + dcr.getName());
}
return locked;
} else if (r instanceof CollectionResource) {
CollectionResource col = (CollectionResource) r;
List<Resource> list = new ArrayList<Resource>();
list.addAll(col.getChildren());
for (Resource rChild : list) {
if (rChild instanceof DeletableResource) {
DeletableResource rChildDel = (DeletableResource) rChild;
if (isLockedOut(req, rChildDel)) {
if (log.isInfoEnabled()) {
log.info("isLocked: " + rChild.getName() + " type:" + rChild.getClass());
}
return true;
}
} else {
if (log.isInfoEnabled()) {
log.info("a child resource is not deletable: " + rChild.getName() + " type: " + rChild.getClass());
}
return true;
}
}
return false;
} else {
boolean locked = handlerHelper.isLockedOut(req, r);
if (locked && log.isInfoEnabled()) {
log.info("isLocked, as reported by handlerHelper on resource: " + r.getName());
}
return locked;
}
}
use of io.milton.resource.Resource in project lobcder by skoulouzis.
the class MultipleResourceFactory method getResource.
@Override
public Resource getResource(String host, String url) throws NotAuthorizedException, BadRequestException {
if (log.isTraceEnabled()) {
log.trace("getResource: " + url);
}
ResourceFactory hostRf = null;
if (mapOfFactoriesByHost != null) {
hostRf = mapOfFactoriesByHost.get(host);
}
Resource theResource;
if (hostRf != null) {
theResource = hostRf.getResource(host, url);
} else {
theResource = findFromFactories(host, url);
}
if (theResource == null) {
log.debug("no resource factory supplied a resouce");
} else {
}
return theResource;
}
use of io.milton.resource.Resource in project lobcder by skoulouzis.
the class ResourceHandlerHelper method process.
public void process(HttpManager manager, Request request, Response response, ResourceHandler handler) throws NotAuthorizedException, ConflictException, BadRequestException {
// need a linked hash map to preserve ordering of params
Map<String, String> params = new LinkedHashMap<String, String>();
Map<String, FileItem> files = new HashMap<String, FileItem>();
try {
request.parseRequestParameters(params, files);
} catch (RequestParseException ex) {
log.warn("exception parsing request. probably interrupted upload", ex);
return;
}
request.getAttributes().put(ATT_NAME_PARAMS, params);
request.getAttributes().put(ATT_NAME_FILES, files);
if (!handlerHelper.checkExpects(responseHandler, request, response)) {
return;
}
String host = request.getHostHeader();
String url = urlAdapter.getUrl(request);
// log.debug( "find resource: path: " + url + " host: " + host );
Resource r = manager.getResourceFactory().getResource(host, url);
if (r == null) {
// But dont check on OPTIONS, because some clients need unauthenticated OPTIONS (i think)
if (!request.getMethod().equals(Method.OPTIONS)) {
if (!authenticationService.authenticateDetailsPresent(request)) {
// Find first existing parent, and test if it allows read access
Resource parent = findClosestParent(manager, host, url);
if (parent != null) {
// If its a write operation then definitely challenge, otherwise test if HEAD is permitted
if (request.getMethod().isWrite) {
// throw new NotAuthorizedException("Authentication is required for write access", parent);
log.debug("r= " + parent + " parent = " + parent);
responseHandler.respondUnauthorised(parent, response, request);
} else {
boolean allowsHead = parent.authorise(request, Method.HEAD, null);
if (!allowsHead) {
// throw new NotAuthorizedException("Authentication is required for read access", parent);
responseHandler.respondUnauthorised(parent, response, request);
}
}
}
}
}
responseHandler.respondNotFound(response, request);
return;
}
handler.processResource(manager, request, response, r);
}
use of io.milton.resource.Resource in project lobcder by skoulouzis.
the class MkColHandler method processMakeCol.
private void processMakeCol(HttpManager manager, Request request, Response response, CollectionResource resource, String newName, CollectionResourceCreator creator) throws ConflictException, NotAuthorizedException, BadRequestException, IOException {
if (!handlerHelper.checkAuthorisation(manager, resource, request)) {
log.info("not authorised");
responseHandler.respondUnauthorised(resource, response, request);
return;
}
handlerHelper.checkExpects(responseHandler, request, response);
MakeCollectionableResource existingCol = (MakeCollectionableResource) resource;
if (!isCompatible(existingCol)) {
log.info("not compatible");
responseHandler.respondMethodNotImplemented(existingCol, response, request);
return;
}
Resource existingChild = existingCol.child(newName);
if (existingChild != null) {
log.warn("found already existing item: " + newName + " of type: " + existingChild.getClass() + " with actual name: " + existingChild.getName());
// throw new ConflictException( existingChild );
// See http://www.ettrema.com:8080/browse/MIL-86
// 405 (Method Not Allowed) - MKCOL can only be executed on a deleted/non-existent resource.
responseHandler.respondMethodNotAllowed(existingChild, response, request);
return;
}
CollectionResource made = creator.createResource(existingCol, newName, request);
if (made == null) {
log.warn("createCollection returned null. In resource class: " + existingCol.getClass());
response.setStatus(Response.Status.SC_METHOD_NOT_ALLOWED);
} else {
log.info("created item ok: " + made.getClass());
manager.getEventManager().fireEvent(new NewFolderEvent(resource));
response.setStatus(Response.Status.SC_CREATED);
}
}
use of io.milton.resource.Resource in project lobcder by skoulouzis.
the class MkColHandler method process.
public void process(HttpManager manager, Request request, Response response, CollectionResourceCreator creator) throws ConflictException, NotAuthorizedException, BadRequestException, IOException {
if (!handlerHelper.checkExpects(responseHandler, request, response)) {
return;
}
String host = request.getHostHeader();
String finalurl = HttpManager.decodeUrl(request.getAbsolutePath());
String name;
if (log.isDebugEnabled()) {
log.debug("process request: host: " + host + " url: " + finalurl);
}
// this is the parent collection it goes in
Path finalpath = Path.path(finalurl);
name = finalpath.getName();
Path parent = finalpath.getParent();
String parenturl = parent.toString();
Resource parentcol = manager.getResourceFactory().getResource(host, parenturl);
if (parentcol != null) {
log.debug("process: resource: " + parentcol.getClass().getName());
if (handlerHelper.isNotCompatible(parentcol, request.getMethod())) {
log.debug("resource not compatible. Resource class: " + parentcol.getClass() + " handler: " + getClass());
responseHandler.respondMethodNotImplemented(parentcol, response, request);
return;
}
if (handlerHelper.isLockedOut(request, parentcol)) {
log.warn("isLockedOut");
response.setStatus(Status.SC_LOCKED);
return;
}
Resource dest = manager.getResourceFactory().getResource(host, finalpath.toString());
if (dest != null && handlerHelper.isLockedOut(request, dest)) {
log.info("destination exists and is locked");
responseHandler.respondLocked(request, response, dest);
return;
} else if (handlerHelper.missingLock(request, parentcol)) {
log.info("precondition failed");
// notowner_modify wants this code here
response.setStatus(Status.SC_PRECONDITION_FAILED);
return;
}
if (parentcol instanceof CollectionResource) {
CollectionResource col = (CollectionResource) parentcol;
if (log.isTraceEnabled()) {
log.trace("process mkcol on parent: " + parentcol.getClass() + " with creator: " + creator.getClass());
}
processMakeCol(manager, request, response, col, name, creator);
} else {
log.warn("parent collection is no a CollectionResource: " + parentcol.getName());
responseHandler.respondConflict(parentcol, response, request, "not a collection");
}
} else {
log.warn("parent does not exist: host=" + host + " path=" + parenturl);
manager.getResponseHandler().respondConflict(parentcol, response, request, name);
}
}
Aggregations