}
}
public void lockResource(java.lang.String sessionId, XmldbURI path, java.lang.String userName) throws java.rmi.RemoteException {
DBBroker broker = null;
final Session session = getSession(sessionId);
final Subject user = session.getUser();
DocumentImpl doc = null;
final TransactionManager transact = pool.getTransactionManager();
final Txn transaction = transact.beginTransaction();
try {
broker = pool.get(user);
// TODO check XML/Binary resource
// doc = (DocumentImpl) broker.openDocument(path, Lock.WRITE_LOCK);
doc = broker.getXMLResource(path, Lock.WRITE_LOCK);
if (doc == null) {
throw new EXistException("Resource "
+ path + " not found");
}
if (!doc.getPermissions().validate(user, Permission.WRITE))
{throw new PermissionDeniedException("User is not allowed to lock resource " + path);}
final org.exist.security.SecurityManager manager = pool.getSecurityManager();
if (!(userName.equals(user.getName()) || manager.hasAdminPrivileges(user)))
{throw new PermissionDeniedException("User " + user.getName() + " is not allowed " +
"to lock the resource for user " + userName);}
final Account lockOwner = doc.getUserLock();
if(lockOwner != null && (!lockOwner.equals(user)) && (!manager.hasAdminPrivileges(user)))
{throw new PermissionDeniedException("Resource is already locked by user " +
lockOwner.getName());}