Search in sources :

Example 1 with ItemDelegate

use of org.apache.jackrabbit.oak.jcr.delegate.ItemDelegate in project jackrabbit-oak by apache.

the class SessionImpl method getItemInternal.

@CheckForNull
private ItemImpl<?> getItemInternal(@Nonnull String oakPath) throws RepositoryException {
    checkAlive();
    ItemDelegate item = sd.getItem(oakPath);
    if (item instanceof NodeDelegate) {
        return NodeImpl.createNode((NodeDelegate) item, sessionContext);
    } else if (item instanceof PropertyDelegate) {
        return new PropertyImpl((PropertyDelegate) item, sessionContext);
    } else {
        return null;
    }
}
Also used : NodeDelegate(org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate) ItemDelegate(org.apache.jackrabbit.oak.jcr.delegate.ItemDelegate) PropertyDelegate(org.apache.jackrabbit.oak.jcr.delegate.PropertyDelegate) CheckForNull(javax.annotation.CheckForNull)

Example 2 with ItemDelegate

use of org.apache.jackrabbit.oak.jcr.delegate.ItemDelegate in project jackrabbit-oak by apache.

the class SessionImpl method removeItem.

@Override
public void removeItem(final String absPath) throws RepositoryException {
    checkAlive();
    final String oakPath = getOakPathOrThrowNotFound(checkNotNull(absPath));
    sd.performVoid(new WriteOperation<Void>("removeItem") {

        @Override
        public void performVoid() throws RepositoryException {
            ItemDelegate item = sd.getItem(oakPath);
            if (item == null) {
                throw new PathNotFoundException(absPath);
            } else if (item.isProtected()) {
                throw new ConstraintViolationException(item.getPath() + " is protected");
            } else if (!item.remove()) {
                throw new RepositoryException(item.getPath() + " could not be removed");
            }
        }
    });
}
Also used : ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) ItemDelegate(org.apache.jackrabbit.oak.jcr.delegate.ItemDelegate)

Example 3 with ItemDelegate

use of org.apache.jackrabbit.oak.jcr.delegate.ItemDelegate in project jackrabbit-oak by apache.

the class SessionImpl method hasCapability.

@Override
public boolean hasCapability(String methodName, Object target, Object[] arguments) throws RepositoryException {
    checkNotNull(methodName);
    checkNotNull(target);
    checkAlive();
    if (target instanceof ItemImpl) {
        ItemDelegate dlg = ((ItemImpl<?>) target).dlg;
        if (dlg.isProtected()) {
            return false;
        }
        boolean isNode = ((ItemImpl<?>) target).isNode();
        Node parent = (isNode) ? (Node) target : ((ItemImpl<?>) target).getParent();
        if (!parent.isCheckedOut()) {
            return false;
        }
        if (parent.isLocked()) {
            return false;
        }
        AccessManager accessMgr = sessionContext.getAccessManager();
        long permission = Permissions.NO_PERMISSION;
        if (isNode) {
            Tree tree = ((NodeDelegate) dlg).getTree();
            if ("addNode".equals(methodName)) {
                if (arguments != null && arguments.length > 0) {
                    // add-node needs to be checked on the (path of) the
                    // new node that has/will be added
                    String path = PathUtils.concat(tree.getPath(), sessionContext.getOakName(arguments[0].toString()));
                    return accessMgr.hasPermissions(path, Session.ACTION_ADD_NODE) && !isMountedReadOnly(path);
                }
            } else if ("setPrimaryType".equals(methodName) || "addMixin".equals(methodName) || "removeMixin".equals(methodName)) {
                permission = Permissions.NODE_TYPE_MANAGEMENT;
            } else if ("orderBefore".equals(methodName)) {
                if (tree.isRoot()) {
                    return false;
                } else {
                    permission = Permissions.MODIFY_CHILD_NODE_COLLECTION;
                    tree = tree.getParent();
                }
            } else if ("setProperty".equals(methodName)) {
                permission = Permissions.ADD_PROPERTY;
            } else if ("remove".equals(methodName)) {
                permission = Permissions.REMOVE_NODE;
            }
            return accessMgr.hasPermissions(tree, null, permission) && !isMountedReadOnly(tree.getPath());
        } else {
            if ("setValue".equals(methodName)) {
                permission = Permissions.MODIFY_PROPERTY;
            } else if ("remove".equals(methodName)) {
                permission = Permissions.REMOVE_PROPERTY;
            }
            NodeDelegate parentDelegate = dlg.getParent();
            if (parentDelegate != null) {
                return accessMgr.hasPermissions(parentDelegate.getTree(), ((PropertyDelegate) dlg).getPropertyState(), permission) && !isMountedReadOnly(parentDelegate.getPath());
            } else {
                return accessMgr.hasPermissions(dlg.getPath(), (permission == Permissions.MODIFY_PROPERTY) ? Session.ACTION_SET_PROPERTY : Session.ACTION_REMOVE) && !isMountedReadOnly(dlg.getPath());
            }
        }
    }
    // TODO: add more best-effort checks
    return true;
}
Also used : AccessManager(org.apache.jackrabbit.oak.jcr.security.AccessManager) Node(javax.jcr.Node) Tree(org.apache.jackrabbit.oak.api.Tree) NodeDelegate(org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate) ItemDelegate(org.apache.jackrabbit.oak.jcr.delegate.ItemDelegate) PropertyDelegate(org.apache.jackrabbit.oak.jcr.delegate.PropertyDelegate)

Aggregations

ItemDelegate (org.apache.jackrabbit.oak.jcr.delegate.ItemDelegate)3 NodeDelegate (org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate)2 PropertyDelegate (org.apache.jackrabbit.oak.jcr.delegate.PropertyDelegate)2 CheckForNull (javax.annotation.CheckForNull)1 Node (javax.jcr.Node)1 PathNotFoundException (javax.jcr.PathNotFoundException)1 RepositoryException (javax.jcr.RepositoryException)1 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)1 Tree (org.apache.jackrabbit.oak.api.Tree)1 AccessManager (org.apache.jackrabbit.oak.jcr.security.AccessManager)1