Search in sources :

Example 1 with ActiveLock

use of org.apache.jackrabbit.webdav.lock.ActiveLock in project jackrabbit by apache.

the class AbstractWebdavServlet method doLock.

/**
     * The LOCK method
     *
     * @param request
     * @param response
     * @param resource
     * @throws IOException
     * @throws DavException
     */
protected void doLock(WebdavRequest request, WebdavResponse response, DavResource resource) throws IOException, DavException {
    LockInfo lockInfo = request.getLockInfo();
    if (lockInfo.isRefreshLock()) {
        // refresh any matching existing locks
        ActiveLock[] activeLocks = resource.getLocks();
        List<ActiveLock> lList = new ArrayList<ActiveLock>();
        for (ActiveLock activeLock : activeLocks) {
            // adjust lockinfo with type/scope retrieved from the lock.
            lockInfo.setType(activeLock.getType());
            lockInfo.setScope(activeLock.getScope());
            DavProperty<?> etagProp = resource.getProperty(DavPropertyName.GETETAG);
            String etag = etagProp != null ? String.valueOf(etagProp.getValue()) : "";
            if (request.matchesIfHeader(resource.getHref(), activeLock.getToken(), etag)) {
                lList.add(resource.refreshLock(lockInfo, activeLock.getToken()));
            }
        }
        if (lList.isEmpty()) {
            throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED);
        }
        ActiveLock[] refreshedLocks = lList.toArray(new ActiveLock[lList.size()]);
        response.sendRefreshLockResponse(refreshedLocks);
    } else {
        int status = HttpServletResponse.SC_OK;
        if (!resource.exists()) {
            // lock-empty requires status code 201 (Created)
            status = HttpServletResponse.SC_CREATED;
        }
        // create a new lock
        ActiveLock lock = resource.lock(lockInfo);
        CodedUrlHeader header = new CodedUrlHeader(DavConstants.HEADER_LOCK_TOKEN, lock.getToken());
        response.setHeader(header.getHeaderName(), header.getHeaderValue());
        DavPropertySet propSet = new DavPropertySet();
        propSet.add(new LockDiscovery(lock));
        response.sendXmlResponse(propSet, status);
    }
}
Also used : CodedUrlHeader(org.apache.jackrabbit.webdav.header.CodedUrlHeader) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) ActiveLock(org.apache.jackrabbit.webdav.lock.ActiveLock) DavException(org.apache.jackrabbit.webdav.DavException) ArrayList(java.util.ArrayList) LockInfo(org.apache.jackrabbit.webdav.lock.LockInfo) LockDiscovery(org.apache.jackrabbit.webdav.lock.LockDiscovery)

Example 2 with ActiveLock

use of org.apache.jackrabbit.webdav.lock.ActiveLock in project jackrabbit by apache.

the class RepositoryServiceImpl method retrieveLockInfo.

private LockInfo retrieveLockInfo(LockDiscovery lockDiscovery, SessionInfo sessionInfo, NodeId nodeId, NodeId parentId) throws RepositoryException {
    checkSessionInfo(sessionInfo);
    List<ActiveLock> activeLocks = lockDiscovery.getValue();
    ActiveLock activeLock = null;
    for (ActiveLock l : activeLocks) {
        Scope sc = l.getScope();
        if (l.getType() == Type.WRITE && (Scope.EXCLUSIVE.equals(sc) || sc == ItemResourceConstants.EXCLUSIVE_SESSION)) {
            if (activeLock != null) {
                throw new RepositoryException("Node " + saveGetIdString(nodeId, sessionInfo) + " contains multiple exclusive write locks.");
            } else {
                activeLock = l;
            }
        }
    }
    if (activeLock == null) {
        log.debug("No lock present on node " + saveGetIdString(nodeId, sessionInfo));
        return null;
    }
    NodeId holder = null;
    String lockroot = activeLock.getLockroot();
    if (activeLock.getLockroot() != null) {
        holder = uriResolver.getNodeId(lockroot, sessionInfo);
    }
    if (activeLock.isDeep() && holder == null && parentId != null) {
        // deep lock, parent known, but holder is not
        LockInfo pLockInfo = getLockInfo(sessionInfo, parentId);
        if (pLockInfo != null) {
            return pLockInfo;
        }
    }
    return new LockInfoImpl(activeLock, holder == null ? nodeId : holder, ((SessionInfoImpl) sessionInfo).getAllLockTokens());
}
Also used : ActiveLock(org.apache.jackrabbit.webdav.lock.ActiveLock) Scope(org.apache.jackrabbit.webdav.lock.Scope) NodeId(org.apache.jackrabbit.spi.NodeId) RepositoryException(javax.jcr.RepositoryException) LockInfo(org.apache.jackrabbit.spi.LockInfo)

Example 3 with ActiveLock

use of org.apache.jackrabbit.webdav.lock.ActiveLock in project jackrabbit by apache.

the class DavResourceImpl method getLock.

/**
     * @see DavResource#getLock(Type, Scope)
     */
public ActiveLock getLock(Type type, Scope scope) {
    ActiveLock lock = null;
    if (exists() && Type.WRITE.equals(type) && Scope.EXCLUSIVE.equals(scope)) {
        // try to retrieve the repository lock information first
        try {
            if (node.isLocked()) {
                Lock jcrLock = node.getLock();
                if (jcrLock != null && jcrLock.isLive()) {
                    lock = new JcrActiveLock(jcrLock);
                    String lockroot = locator.getFactory().createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), jcrLock.getNode().getPath(), false).getHref(false);
                    lock.setLockroot(lockroot);
                }
            }
        } catch (RepositoryException e) {
        // LockException (no lock applies) >> should never occur
        // RepositoryException, AccessDeniedException or another error >> ignore
        }
        // could not retrieve a jcr-lock. test if a simple webdav lock is present.
        if (lock == null) {
            lock = lockManager.getLock(type, scope, this);
        }
    }
    return lock;
}
Also used : ActiveLock(org.apache.jackrabbit.webdav.lock.ActiveLock) JcrActiveLock(org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock) JcrActiveLock(org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock) RepositoryException(javax.jcr.RepositoryException) ActiveLock(org.apache.jackrabbit.webdav.lock.ActiveLock) Lock(javax.jcr.lock.Lock) JcrActiveLock(org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock) SupportedLock(org.apache.jackrabbit.webdav.lock.SupportedLock)

Example 4 with ActiveLock

use of org.apache.jackrabbit.webdav.lock.ActiveLock in project jackrabbit by apache.

the class DavResourceImpl method removeMember.

/**
     * @see DavResource#removeMember(DavResource)
     */
public void removeMember(DavResource member) throws DavException {
    if (!exists() || !member.exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }
    if (isLocked(this) || isLocked(member)) {
        throw new DavException(DavServletResponse.SC_LOCKED);
    }
    // don't allow removal of nodes, that would be filtered out
    if (isFilteredResource(member)) {
        log.debug("Avoid removal of filtered resource: " + member.getDisplayName());
        throw new DavException(DavServletResponse.SC_FORBIDDEN);
    }
    DeleteManager dm = config.getDeleteManager();
    dm.delete(new DeleteContextImpl(getJcrSession()), member);
    // make sure, non-jcr locks are removed, once the removal is completed
    try {
        if (!isJcrLockable()) {
            ActiveLock lock = getLock(Type.WRITE, Scope.EXCLUSIVE);
            if (lock != null) {
                lockManager.releaseLock(lock.getToken(), member);
            }
        }
    } catch (DavException e) {
    // since check for 'locked' exception has been performed before
    // ignore any error here
    }
}
Also used : DeleteManager(org.apache.jackrabbit.server.io.DeleteManager) DeleteContextImpl(org.apache.jackrabbit.server.io.DeleteContextImpl) ActiveLock(org.apache.jackrabbit.webdav.lock.ActiveLock) JcrActiveLock(org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) DavException(org.apache.jackrabbit.webdav.DavException)

Example 5 with ActiveLock

use of org.apache.jackrabbit.webdav.lock.ActiveLock in project jackrabbit by apache.

the class TxLockManagerImpl method createLock.

/**
     * Create a new lock.
     *
     * @param lockInfo
     * @param resource
     * @return the lock
     * @throws DavException if the request lock has the wrong lock type or if
     *                      the lock could not be obtained for any reason.
     */
private synchronized ActiveLock createLock(LockInfo lockInfo, TransactionResource resource) throws DavException {
    if (!lockInfo.isDeep() || !TransactionConstants.TRANSACTION.equals(lockInfo.getType())) {
        throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED);
    }
    ActiveLock existing = getLock(lockInfo.getType(), lockInfo.getScope(), resource);
    if (existing != null) {
        throw new DavException(DavServletResponse.SC_LOCKED);
    }
    // TODO: check for locks on member resources is required as well for lock is always deep!
    Transaction tx = createTransaction(resource.getLocator(), lockInfo);
    tx.start(resource);
    // keep references to this lock
    addReferences(tx, getMap(resource), resource);
    return tx.getLock();
}
Also used : ActiveLock(org.apache.jackrabbit.webdav.lock.ActiveLock) TxActiveLock(org.apache.jackrabbit.webdav.transaction.TxActiveLock) DavException(org.apache.jackrabbit.webdav.DavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException)

Aggregations

ActiveLock (org.apache.jackrabbit.webdav.lock.ActiveLock)12 RepositoryException (javax.jcr.RepositoryException)6 DavException (org.apache.jackrabbit.webdav.DavException)6 JcrActiveLock (org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock)6 Lock (javax.jcr.lock.Lock)4 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)3 TxActiveLock (org.apache.jackrabbit.webdav.transaction.TxActiveLock)3 ArrayList (java.util.ArrayList)2 Node (javax.jcr.Node)2 SupportedLock (org.apache.jackrabbit.webdav.lock.SupportedLock)2 DeleteContextImpl (org.apache.jackrabbit.server.io.DeleteContextImpl)1 DeleteManager (org.apache.jackrabbit.server.io.DeleteManager)1 LockInfo (org.apache.jackrabbit.spi.LockInfo)1 NodeId (org.apache.jackrabbit.spi.NodeId)1 CodedUrlHeader (org.apache.jackrabbit.webdav.header.CodedUrlHeader)1 LockDiscovery (org.apache.jackrabbit.webdav.lock.LockDiscovery)1 LockInfo (org.apache.jackrabbit.webdav.lock.LockInfo)1 Scope (org.apache.jackrabbit.webdav.lock.Scope)1 DavPropertySet (org.apache.jackrabbit.webdav.property.DavPropertySet)1 TransactionResource (org.apache.jackrabbit.webdav.transaction.TransactionResource)1