DocumentImpl doc = (DocumentImpl) broker.getDocument(user, resource);
DocumentImpl doc = (DocumentImpl) broker.getDocument(resource);
	public boolean setPermissions(		User user,		String resource,		String owner,		String ownerGroup,		String permissions)		throws EXistException, PermissionDeniedException {		DBBroker broker = null;		try {			broker = brokerPool.get();			org.exist.security.SecurityManager manager =				brokerPool.getSecurityManager();			Collection collection = broker.getCollection(resource);			if (collection == null) {				DocumentImpl doc =					(DocumentImpl) broker.getDocument(user, resource);				if (doc == null)					throw new EXistException(						"document or collection " + resource + " not found");				LOG.debug("changing permissions on document " + resource);				Permission perm = doc.getPermissions();				if (perm.getOwner().equals(user.getName())					|| manager.hasAdminPrivileges(user)) {					if (owner != null) {						perm.setOwner(owner);						perm.setGroup(ownerGroup);					}					if (permissions != null && permissions.length() > 0)						perm.setPermissions(permissions);					broker.saveCollection(doc.getCollection());					broker.flush();					return true;				} else					throw new PermissionDeniedException("not allowed to change permissions");			} else {				LOG.debug("changing permissions on collection " + resource);				Permission perm = collection.getPermissions();				if (perm.getOwner().equals(user.getName())					|| manager.hasAdminPrivileges(user)) {					if (permissions != null)						perm.setPermissions(permissions);					if (owner != null) {						perm.setOwner(owner);						perm.setGroup(ownerGroup);					}					broker.saveCollection(collection);					broker.flush();					return true;				} else					throw new PermissionDeniedException("not allowed to change permissions");			}		} catch (SyntaxException e) {			throw new EXistException(e.getMessage());		} catch (PermissionDeniedException e) {			throw new EXistException(e.getMessage());		} finally {			brokerPool.release(broker);		}	}