Search in sources :

Example 96 with NodeRef

use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.

the class UnlockMethod method attemptUnlock.

/**
 * The main unlock implementation.
 *
 * @throws WebDAVServerException
 */
protected void attemptUnlock() throws WebDAVServerException {
    if (logger.isDebugEnabled()) {
        logger.debug("Unlock node; path=" + getPath() + ", token=" + getLockToken());
    }
    FileInfo lockNodeInfo = null;
    try {
        lockNodeInfo = getNodeForPath(getRootNodeRef(), getPath());
    } catch (FileNotFoundException e) {
        throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND);
    }
    // Parse the lock token
    String[] lockInfoFromRequest = WebDAV.parseLockToken(getLockToken());
    if (lockInfoFromRequest == null) {
        // Bad lock token
        throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED);
    }
    NodeRef nodeRef = lockNodeInfo.getNodeRef();
    LockInfo lockInfo = getDAVLockService().getLockInfo(nodeRef);
    if (lockInfo == null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Unlock token=" + getLockToken() + " Not locked - no info in lock store.");
        }
        // Node is not locked
        throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED);
    }
    if (!lockInfo.isLocked()) {
        if (logger.isDebugEnabled()) {
            logger.debug("Unlock token=" + getLockToken() + " Not locked");
        }
        // Node is not locked
        throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED);
    } else if (lockInfo.isExpired()) {
        if (logger.isDebugEnabled()) {
            logger.debug("Unlock token=" + getLockToken() + " Lock expired");
        }
        // Return a success status
        m_response.setStatus(HttpServletResponse.SC_NO_CONTENT);
        removeNoContentAspect(nodeRef);
    } else if (lockInfo.isExclusive()) {
        String currentUser = getAuthenticationService().getCurrentUserName();
        if (currentUser.equals(lockInfo.getOwner())) {
            try {
                getDAVLockService().unlock(nodeRef);
            } catch (UnableToReleaseLockException e) {
                throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED, e);
            }
            // Indicate that the unlock was successful
            m_response.setStatus(HttpServletResponse.SC_NO_CONTENT);
            removeNoContentAspect(nodeRef);
            if (logger.isDebugEnabled()) {
                logger.debug("Unlock token=" + getLockToken() + " Successful");
            }
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("Unlock token=" + getLockToken() + " Not lock owner");
            }
            // Node is not locked
            throw new WebDAVServerException(HttpServletResponse.SC_PRECONDITION_FAILED);
        }
    } else if (lockInfo.isShared()) {
        Set<String> sharedLocks = lockInfo.getSharedLockTokens();
        if (sharedLocks.contains(m_strLockToken)) {
            sharedLocks.remove(m_strLockToken);
            // Indicate that the unlock was successful
            m_response.setStatus(HttpServletResponse.SC_NO_CONTENT);
            removeNoContentAspect(nodeRef);
            // DEBUG
            if (logger.isDebugEnabled()) {
                logger.debug("Unlock token=" + getLockToken() + " Successful");
            }
        }
    } else {
        throw new IllegalStateException("Invalid LockInfo state: " + lockInfo);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Set(java.util.Set) FileInfo(org.alfresco.service.cmr.model.FileInfo) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) UnableToReleaseLockException(org.alfresco.service.cmr.lock.UnableToReleaseLockException)

Example 97 with NodeRef

use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.

the class WebDAVLockServiceImpl method lock.

public void lock(NodeRef nodeRef, LockInfo lockInfo) {
    boolean performSessionBehavior = false;
    long timeout;
    timeout = lockInfo.getRemainingTimeoutSeconds();
    // ALF-11777 fix, do not lock node for more than 24 hours (webdav and vti)
    if (timeout >= WebDAV.TIMEOUT_24_HOURS || timeout == WebDAV.TIMEOUT_INFINITY) {
        timeout = WebDAV.TIMEOUT_24_HOURS;
        lockInfo.setTimeoutSeconds((int) timeout);
        performSessionBehavior = true;
    }
    // TODO: lock children according to depth? lock type?
    final String additionalInfo = lockInfo.toJSON();
    lockService.lock(nodeRef, LockType.WRITE_LOCK, (int) timeout, Lifetime.EPHEMERAL, additionalInfo);
    if (logger.isDebugEnabled()) {
        logger.debug(nodeRef + " was locked for " + timeout + " seconds.");
    }
    if (performSessionBehavior) {
        HttpSession session = currentSession.get();
        if (session == null) {
            if (logger.isDebugEnabled()) {
                logger.debug("Couldn't find current session.");
            }
            return;
        }
        storeObjectInSessionList(session, LOCKED_RESOURCES, new Pair<String, NodeRef>(AuthenticationUtil.getRunAsUser(), nodeRef));
        if (logger.isDebugEnabled()) {
            logger.debug(nodeRef + " was added to the session " + session.getId() + " for post expiration processing.");
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) HttpSession(javax.servlet.http.HttpSession)

Example 98 with NodeRef

use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.

the class WebDAVLockServiceImpl method unlock.

/**
 * Shared method for webdav/vti to unlock node. Unlocked node is automatically removed from
 * current sessions's locked resources list.
 *
 * @param nodeRef the node to lock
 */
@Override
public void unlock(NodeRef nodeRef) {
    lockService.unlock(nodeRef);
    if (logger.isDebugEnabled()) {
        logger.debug(nodeRef + " was unlocked.");
    }
    HttpSession session = currentSession.get();
    if (session == null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Couldn't find current session.");
        }
        return;
    }
    boolean removed = removeObjectFromSessionList(session, LOCKED_RESOURCES, new Pair<String, NodeRef>(AuthenticationUtil.getRunAsUser(), nodeRef));
    if (removed && logger.isDebugEnabled()) {
        logger.debug(nodeRef + " was removed from the session " + session.getId());
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) HttpSession(javax.servlet.http.HttpSession)

Example 99 with NodeRef

use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.

the class WebDAVMethod method getWorkingCopy.

/**
 * Returns a working copy of node for current user.
 *
 * @param nodeRef node reference
 * @return Returns the working copy's file information
 */
protected FileInfo getWorkingCopy(NodeRef nodeRef) {
    FileInfo result = null;
    NodeRef workingCopy = getServiceRegistry().getCheckOutCheckInService().getWorkingCopy(nodeRef);
    if (workingCopy != null) {
        String workingCopyOwner = getNodeService().getProperty(workingCopy, ContentModel.PROP_WORKING_COPY_OWNER).toString();
        if (workingCopyOwner.equals(getAuthenticationService().getCurrentUserName())) {
            result = getFileFolderService().getFileInfo(workingCopy);
        }
    }
    return result;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo)

Example 100 with NodeRef

use of org.alfresco.service.cmr.repository.NodeRef in project alfresco-remote-api by Alfresco.

the class WebDAVMethod method checkNode.

/**
 * Checks if write operation can be performed on node.
 *
 * @param fileInfo          - node's file info
 * @param ignoreShared      - if true ignores shared locks
 * @param lockMethod        - must be true if used from lock method
 * @return node's lock info
 * @throws WebDAVServerException if node has shared or exclusive lock
 *                               or If header preconditions failed
 */
protected LockInfo checkNode(FileInfo fileInfo, boolean ignoreShared, boolean lockMethod) throws WebDAVServerException {
    LockInfo nodeLockInfo = getNodeLockInfo(fileInfo);
    NodeRef nodeRef = fileInfo.getNodeRef();
    // Regardless of WebDAV locks, if we can't write to this node, then it's locked!
    if (getDAVHelper().isLockedAndReadOnly(nodeRef)) {
        throw new WebDAVServerException(WebDAV.WEBDAV_SC_LOCKED);
    }
    String nodeETag = getDAVHelper().makeQuotedETag(fileInfo);
    // Handle the case where there are no conditions and no lock token stored on the node. Node just needs to be writable with no shared locks
    if (m_conditions == null) {
        // ALF-3681 fix. WebDrive 10 client doesn't send If header when locked resource is updated so check the node by lockOwner.
        if (!nodeLockInfo.isExclusive() || (m_userAgent != null && m_userAgent.equals(WebDAV.AGENT_MICROSOFT_DATA_ACCESS_INTERNET_PUBLISHING_PROVIDER_DAV))) {
            if (!ignoreShared && nodeLockInfo.isShared() && !nodeLockInfo.getSharedLockTokens().isEmpty()) {
                throw new WebDAVServerException(WebDAV.WEBDAV_SC_LOCKED);
            }
            return nodeLockInfo;
        }
    }
    // Checking of the If tag consists of two checks:
    // 1. Check the appropriate lock token for the node has been supplied (if the node is locked)
    // 2. If there are conditions, check at least one condition (corresponding to this node) is satisfied.
    checkLockToken(nodeLockInfo, ignoreShared, lockMethod);
    checkConditions(nodeLockInfo.getExclusiveLockToken(), nodeETag);
    return nodeLockInfo;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef)

Aggregations

NodeRef (org.alfresco.service.cmr.repository.NodeRef)1239 HashMap (java.util.HashMap)244 QName (org.alfresco.service.namespace.QName)242 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)209 Test (org.junit.Test)195 ArrayList (java.util.ArrayList)159 Serializable (java.io.Serializable)136 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)104 BaseUnitTest (org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest)101 FileInfo (org.alfresco.service.cmr.model.FileInfo)82 Map (java.util.Map)81 Node (org.alfresco.web.bean.repository.Node)81 JSONObject (org.json.JSONObject)80 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)74 FacesContext (javax.faces.context.FacesContext)61 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)59 List (java.util.List)58 IOException (java.io.IOException)55 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)52 Date (java.util.Date)51