use of org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree in project jackrabbit-oak by apache.
the class CompositePermissionProvider method getPrivileges.
@Nonnull
@Override
public Set<String> getPrivileges(@Nullable Tree tree) {
Tree immutableTree = PermissionUtil.getImmutableTree(tree, immutableRoot);
PrivilegeBits result = PrivilegeBits.getInstance();
PrivilegeBits denied = PrivilegeBits.getInstance();
for (AggregatedPermissionProvider aggregatedPermissionProvider : pps) {
PrivilegeBits supported = aggregatedPermissionProvider.supportedPrivileges(immutableTree, null).modifiable();
if (doEvaluate(supported)) {
PrivilegeBits granted = privilegeBitsProvider.getBits(aggregatedPermissionProvider.getPrivileges(immutableTree));
// add the granted privileges to the result
if (!granted.isEmpty()) {
result.add(granted);
}
// update the set of denied privs by comparing the granted privs
// with the complete set of supported privileges
denied.add(supported.diff(granted));
}
}
// subtract all denied privileges from the result
if (!denied.isEmpty()) {
result.diff(denied);
}
return privilegeBitsProvider.getPrivilegeNames(result);
}
use of org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree in project jackrabbit-oak by apache.
the class CompositeTreePermission method create.
private static TreePermission create(@Nonnull LazyTree lazyTree, @Nonnull String childName, @Nonnull NodeState childState, @Nonnull CompositeTreePermission parentPermission) {
switch(parentPermission.childSize) {
case 0:
return TreePermission.EMPTY;
case 1:
TreePermission parent = null;
for (TreePermission tp : parentPermission.treePermissions) {
if (isValid(tp)) {
parent = tp;
break;
}
}
return (parent == null) ? TreePermission.EMPTY : parent.getChildPermission(childName, childState);
default:
ImmutableTree tree = lazyTree.get();
TreeType type = getType(tree, parentPermission);
AggregatedPermissionProvider[] pvds = new AggregatedPermissionProvider[parentPermission.childSize];
TreePermission[] tps = new TreePermission[parentPermission.childSize];
int cnt = 0;
for (int i = 0, j = 0; i < parentPermission.providers.length; i++) {
parent = parentPermission.treePermissions[i];
if (isValid(parent)) {
AggregatedPermissionProvider provider = parentPermission.providers[i];
TreePermission tp = provider.getTreePermission(tree, type, parent);
if (!isValid(tp)) {
cnt++;
}
tps[j] = tp;
pvds[j] = provider;
j++;
}
}
return new CompositeTreePermission(tree, type, parentPermission.typeProvider, pvds, tps, cnt);
}
}
use of org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree in project jackrabbit-oak by apache.
the class ImmutableRoot method getTree.
//---------------------------------------------------------------< Root >---
@Nonnull
@Override
public ImmutableTree getTree(@Nonnull String path) {
checkArgument(PathUtils.isAbsolute(path));
ImmutableTree child = rootTree;
for (String name : elements(path)) {
child = child.getChild(name);
}
return child;
}
use of org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree in project jackrabbit-oak by apache.
the class MoveAwarePermissionValidator method visibleValidator.
private Validator visibleValidator(@Nonnull Tree source, @Nonnull Tree dest) {
// TODO improve: avoid calculating the 'before' permissions in case the current parent permissions already point to the correct tree.
ImmutableTree immutableTree = (ImmutableTree) moveCtx.rootBefore.getTree("/");
TreePermission tp = getPermissionProvider().getTreePermission(immutableTree, TreePermission.EMPTY);
for (String n : PathUtils.elements(source.getPath())) {
immutableTree = immutableTree.getChild(n);
tp = tp.getChildPermission(n, immutableTree.getNodeState());
}
Validator validator = createValidator(source, dest, tp, this);
return new VisibleValidator(validator, true, false);
}
use of org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree in project jackrabbit-oak by apache.
the class VersionableState method getOPV.
private int getOPV(NodeBuilder parent, NodeBuilder child, String childName) throws RepositoryException {
// ignore hidden tree
if (childName.startsWith(":")) {
return IGNORE;
}
ImmutableTree parentTree = new ImmutableTree(parent.getNodeState());
NodeState childState;
if (NT_FROZENNODE.equals(child.getName(JCR_PRIMARYTYPE))) {
// need to translate into a regular node to get proper OPV value
NodeBuilder builder = new MemoryNodeBuilder(EmptyNodeState.EMPTY_NODE);
builder.setProperty(JCR_PRIMARYTYPE, child.getName(JCR_FROZENPRIMARYTYPE), Type.NAME);
builder.setProperty(JCR_MIXINTYPES, child.getNames(JCR_MIXINTYPES), Type.NAMES);
childState = builder.getNodeState();
} else {
childState = child.getNodeState();
}
ImmutableTree childTree = new ImmutableTree(parentTree, childName, childState);
return ntMgr.getDefinition(parentTree, childTree).getOnParentVersion();
}
Aggregations