DBBroker broker = null;
final Session session = getSession(sessionId);
Collection collection = null;
DocumentImpl doc = null;
final TransactionManager transact = pool.getTransactionManager();
final Txn transaction = transact.beginTransaction();
try {
broker = pool.get(session.getUser());
final org.exist.security.SecurityManager manager = pool.getSecurityManager();
collection = broker.openCollection(resource, Lock.WRITE_LOCK);
if (collection == null) {
// TODO check XML/Binary resource
doc = broker.getXMLResource(resource, Lock.WRITE_LOCK);
if (doc == null)
{throw new RemoteException("document or collection "
+ resource + " not found");}
LOG.debug("changing permissions on document " + resource);
final Permission perm = doc.getPermissions();
if (perm.getOwner().equals(session.getUser())
|| manager.hasAdminPrivileges(session.getUser())) {
if (owner != null) {
perm.setOwner(owner);
perm.setGroup(ownerGroup);
}
perm.setMode(permissions);
// TODO check XML/Binary resource
// broker.storeDocument(transaction, doc);
broker.storeXMLResource(transaction, doc);
transact.commit(transaction);
broker.flush();
return;
// return true;
}
transact.abort(transaction);
throw new PermissionDeniedException("not allowed to change permissions");
}
LOG.debug("changing permissions on collection " + resource);
final Permission perm = collection.getPermissionsNoLock();
if (perm.getOwner().equals(session.getUser())
|| manager.hasAdminPrivileges(session.getUser())) {
perm.setMode(permissions);
if (owner != null) {
perm.setOwner(owner);
perm.setGroup(ownerGroup);
}
transaction.registerLock(collection.getLock(), Lock.WRITE_LOCK);
broker.saveCollection(transaction, collection);
transact.commit(transaction);
broker.flush();
return;
}