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);
}
}
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());
}
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;
}
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
}
}
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();
}
Aggregations