/** * Generates a lock token out of the lock and some information out of the * request to make it unique.<p> * * @param req the servlet request we are processing * @param lock the lock with the information for the lock token * * @return the generated lock token */ private String generateLockToken(HttpServletRequest req, CmsRepositoryLockInfo lock) { String lockTokenStr = req.getServletPath() + "-" + req.getUserPrincipal() + "-" + lock.getOwner() + "-" + lock.getPath() + "-" + m_secret; return MD5_ENCODER.encode(m_md5Helper.digest(lockTokenStr.getBytes())); }
/** * Check to see if a resource is currently write locked.<p> * * @param path the path where to find the resource to check the lock * * @return true if the resource is locked otherwise false */ private boolean isLocked(String path) { // get lock for path CmsRepositoryLockInfo lock = m_session.getLock(path); if (lock == null) { return false; } // check if found lock fits to the lock token from request // String currentToken = "<opaquelocktoken:" + generateLockToken(req, lock) + ">"; // if (currentToken.equals(parseLockTokenHeader(req))) { // return false; // } if (lock.getUsername().equals(m_username)) { return false; } return true; }
CmsRepositoryLockInfo lock = new CmsRepositoryLockInfo(); lock.setDepth(CmsRepositoryLockInfo.DEPTH_INFINITY_VALUE); } else { if (depthStr.equals("0")) { lock.setDepth(0); } else { lock.setDepth(CmsRepositoryLockInfo.DEPTH_INFINITY_VALUE); lock.setExpiresAt(System.currentTimeMillis() + (lockDuration * 1000)); String tempScope = currentElem.getName(); if (tempScope.indexOf(':') != -1) { lock.setScope(tempScope.substring(tempScope.indexOf(':') + 1)); } else { lock.setScope(tempScope); if (lock.getScope() == null) { String tempType = currentElem.getName(); if (tempType.indexOf(':') != -1) { lock.setType(tempType.substring(tempType.indexOf(':') + 1)); } else { lock.setType(tempType); if (lock.getType() == null) { switch (currentElem.getNodeType()) { case Node.TEXT_NODE:
/** * Generate a dom element from the given information with all needed subelements to * add to the parent.<p> * * @param lock the lock with the information to create the subelements * @param parent the parent element where to add the created element * @param lockToken the lock token to use */ private void addLockElement(CmsRepositoryLockInfo lock, Element parent, String lockToken) { Element activeLockElem = addElement(parent, TAG_ACTIVELOCK); addElement(addElement(activeLockElem, TAG_LOCKTYPE), lock.getType()); addElement(addElement(activeLockElem, TAG_LOCKSCOPE), lock.getScope()); if (lock.getDepth() == CmsRepositoryLockInfo.DEPTH_INFINITY_VALUE) { addElement(activeLockElem, TAG_DEPTH).addText(DEPTH_INFINITY); } else { addElement(activeLockElem, TAG_DEPTH).addText("0"); } Element ownerElem = addElement(activeLockElem, TAG_OWNER); addElement(ownerElem, TAG_HREF).addText(lock.getOwner()); if (lock.getExpiresAt() == CmsRepositoryLockInfo.TIMEOUT_INFINITE_VALUE) { addElement(activeLockElem, TAG_TIMEOUT).addText(TIMEOUT_INFINITE); } else { long timeout = (lock.getExpiresAt() - System.currentTimeMillis()) / 1000; addElement(activeLockElem, TAG_TIMEOUT).addText("Second-" + timeout); } Element lockTokenElem = addElement(activeLockElem, TAG_LOCKTOKEN); addElement(lockTokenElem, TAG_HREF).addText("opaquelocktoken:" + lockToken); }
/** * @see org.opencms.repository.I_CmsRepositorySession#getLock(java.lang.String) */ public CmsRepositoryLockInfo getLock(String path) { try { CmsRepositoryLockInfo lockInfo = new CmsRepositoryLockInfo(); path = validatePath(path); CmsResource res = m_cms.readResource(path, CmsResourceFilter.DEFAULT); // check user locks CmsLock cmsLock = m_cms.getLock(res); if (!cmsLock.isUnlocked()) { lockInfo.setPath(path); CmsUser owner = m_cms.readUser(cmsLock.getUserId()); if (owner != null) { lockInfo.setUsername(owner.getName()); lockInfo.setOwner(owner.getName() + "||" + owner.getEmail()); } return lockInfo; } return null; } catch (CmsException ex) { // error occurred while finding locks // return null (no lock found) return null; } }
CmsRepositoryLockInfo lock = new CmsRepositoryLockInfo(); lock.setDepth(CmsRepositoryLockInfo.DEPTH_INFINITY_VALUE); } else { if (depthStr.equals("0")) { lock.setDepth(0); } else { lock.setDepth(CmsRepositoryLockInfo.DEPTH_INFINITY_VALUE); lock.setExpiresAt(System.currentTimeMillis() + (lockDuration * 1000)); String tempScope = currentElem.getName(); if (tempScope.indexOf(':') != -1) { lock.setScope(tempScope.substring(tempScope.indexOf(':') + 1)); } else { lock.setScope(tempScope); if (lock.getScope() == null) { String tempType = currentElem.getName(); if (tempType.indexOf(':') != -1) { lock.setType(tempType.substring(tempType.indexOf(':') + 1)); } else { lock.setType(tempType); if (lock.getType() == null) { switch (currentElem.getNodeType()) { case Node.TEXT_NODE:
/** * Generate a dom element from the given information with all needed subelements to * add to the parent.<p> * * @param lock the lock with the information to create the subelements * @param parent the parent element where to add the created element * @param lockToken the lock token to use */ private void addLockElement(CmsRepositoryLockInfo lock, Element parent, String lockToken) { Element activeLockElem = addElement(parent, TAG_ACTIVELOCK); addElement(addElement(activeLockElem, TAG_LOCKTYPE), lock.getType()); addElement(addElement(activeLockElem, TAG_LOCKSCOPE), lock.getScope()); if (lock.getDepth() == CmsRepositoryLockInfo.DEPTH_INFINITY_VALUE) { addElement(activeLockElem, TAG_DEPTH).addText(DEPTH_INFINITY); } else { addElement(activeLockElem, TAG_DEPTH).addText("0"); } Element ownerElem = addElement(activeLockElem, TAG_OWNER); addElement(ownerElem, TAG_HREF).addText(lock.getOwner()); if (lock.getExpiresAt() == CmsRepositoryLockInfo.TIMEOUT_INFINITE_VALUE) { addElement(activeLockElem, TAG_TIMEOUT).addText(TIMEOUT_INFINITE); } else { long timeout = (lock.getExpiresAt() - System.currentTimeMillis()) / 1000; addElement(activeLockElem, TAG_TIMEOUT).addText("Second-" + timeout); } Element lockTokenElem = addElement(activeLockElem, TAG_LOCKTOKEN); addElement(lockTokenElem, TAG_HREF).addText("opaquelocktoken:" + lockToken); }
/** * @see org.opencms.repository.I_CmsRepositorySession#getLock(java.lang.String) */ public CmsRepositoryLockInfo getLock(String path) { try { CmsRepositoryLockInfo lockInfo = new CmsRepositoryLockInfo(); path = validatePath(path); CmsResource res = m_cms.readResource(path, CmsResourceFilter.DEFAULT); // check user locks CmsLock cmsLock = m_cms.getLock(res); if (!cmsLock.isUnlocked()) { lockInfo.setPath(path); CmsUser owner = m_cms.readUser(cmsLock.getUserId()); if (owner != null) { lockInfo.setUsername(owner.getName()); lockInfo.setOwner(owner.getName() + "||" + owner.getEmail()); } return lockInfo; } return null; } catch (CmsException ex) { // error occurred while finding locks // return null (no lock found) return null; } }
/** * Generates a lock token out of the lock and some information out of the * request to make it unique.<p> * * @param req the servlet request we are processing * @param lock the lock with the information for the lock token * * @return the generated lock token */ private String generateLockToken(HttpServletRequest req, CmsRepositoryLockInfo lock) { String lockTokenStr = req.getServletPath() + "-" + req.getUserPrincipal() + "-" + lock.getOwner() + "-" + lock.getPath() + "-" + m_secret; return MD5_ENCODER.encode(m_md5Helper.digest(lockTokenStr.getBytes())); }
/** * Check to see if a resource is currently write locked.<p> * * @param path the path where to find the resource to check the lock * * @return true if the resource is locked otherwise false */ private boolean isLocked(String path) { // get lock for path CmsRepositoryLockInfo lock = m_session.getLock(path); if (lock == null) { return false; } // check if found lock fits to the lock token from request // String currentToken = "<opaquelocktoken:" + generateLockToken(req, lock) + ">"; // if (currentToken.equals(parseLockTokenHeader(req))) { // return false; // } if (lock.getUsername().equals(m_username)) { return false; } return true; }