Search in sources :

Example 1 with LockableResource

use of io.milton.resource.LockableResource in project lobcder by skoulouzis.

the class HandlerHelper method isLockedOut.

/**
 * TODO: move to webdav
 *
 * @param inRequest
 * @param inResource
 * @return
 */
public boolean isLockedOut(Request inRequest, Resource inResource) {
    if (inResource == null || !(inResource instanceof LockableResource)) {
        return false;
    }
    LockableResource lr = (LockableResource) inResource;
    LockToken token = lr.getCurrentLock();
    if (token != null) {
        Auth auth = inRequest.getAuthorization();
        Object sUser = null;
        if (auth != null) {
            sUser = auth.getUser();
        }
        String lockedByUser = token.info.lockedByUser;
        if (lockedByUser == null) {
            log.warn("Resource is locked with a null user. Ignoring the lock");
            return false;
        } else if (lockedByUser.equals(sUser)) {
            // if (log.isInfoEnabled()) {
            // if (auth == null) {
            // log.trace("lock owned by: " + lockedByUser);
            // } else {
            // log.trace("lock owned by: " + lockedByUser + " not by " + auth.getUser());
            // }
            // }
            String value = inRequest.getIfHeader();
            if (value != null) {
                if (value.contains("opaquelocktoken:" + token.tokenId + ">")) {
                    log.trace("Request contains valid token so operation is permitted");
                    return false;
                }
            }
            return true;
        }
    }
    return false;
}
Also used : LockableResource(io.milton.resource.LockableResource)

Example 2 with LockableResource

use of io.milton.resource.LockableResource in project lobcder by skoulouzis.

the class LockHandler method processExistingResource.

private void processExistingResource(HttpManager manager, Request request, Response response, Resource resource) throws NotAuthorizedException, IOException, SAXException, LockedException, PreConditionFailedException {
    if (handlerHelper.isNotCompatible(resource, request.getMethod()) || !isCompatible(resource)) {
        responseHandler.respondMethodNotImplemented(resource, response, request);
        return;
    }
    if (!handlerHelper.checkAuthorisation(manager, resource, request)) {
        responseHandler.respondUnauthorised(resource, response, request);
        return;
    }
    handlerHelper.checkExpects(responseHandler, request, response);
    LockableResource r = (LockableResource) resource;
    LockTimeout timeout = LockTimeout.parseTimeout(request);
    String ifHeader = request.getIfHeader();
    response.setContentTypeHeader(Response.XML);
    if (ifHeader == null || ifHeader.length() == 0) {
        processNewLock(manager, request, response, r, timeout);
    } else {
    // processRefresh(manager, request, response, r, timeout, ifHeader);
    }
}
Also used : LockableResource(io.milton.resource.LockableResource) LockTimeout(io.milton.http.LockTimeout)

Example 3 with LockableResource

use of io.milton.resource.LockableResource in project lobcder by skoulouzis.

the class UnlockHandler method processExistingResource.

private void processExistingResource(HttpManager manager, Request request, Response response, Resource resource) throws NotAuthorizedException, BadRequestException, ConflictException {
    LockableResource r = (LockableResource) resource;
    String sToken = request.getLockTokenHeader();
    sToken = parseToken(sToken);
    // }
    try {
        r.unlock(sToken);
        responseHandler.respondNoContent(resource, response, request);
    } catch (PreConditionFailedException ex) {
        responseHandler.respondPreconditionFailed(request, response, resource);
    }
}
Also used : LockableResource(io.milton.resource.LockableResource) PreConditionFailedException(io.milton.http.exceptions.PreConditionFailedException)

Aggregations

LockableResource (io.milton.resource.LockableResource)3 LockTimeout (io.milton.http.LockTimeout)1 PreConditionFailedException (io.milton.http.exceptions.PreConditionFailedException)1