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