Search in sources :

Example 6 with ImmutableTree

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);
}
Also used : AggregatedPermissionProvider(org.apache.jackrabbit.oak.spi.security.authorization.permission.AggregatedPermissionProvider) Tree(org.apache.jackrabbit.oak.api.Tree) ImmutableTree(org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree) PrivilegeBits(org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBits) Nonnull(javax.annotation.Nonnull)

Example 7 with ImmutableTree

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);
    }
}
Also used : TreeType(org.apache.jackrabbit.oak.plugins.tree.TreeType) AggregatedPermissionProvider(org.apache.jackrabbit.oak.spi.security.authorization.permission.AggregatedPermissionProvider) TreePermission(org.apache.jackrabbit.oak.spi.security.authorization.permission.TreePermission) ImmutableTree(org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree)

Example 8 with ImmutableTree

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;
}
Also used : ImmutableTree(org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree) Nonnull(javax.annotation.Nonnull)

Example 9 with ImmutableTree

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);
}
Also used : VisibleValidator(org.apache.jackrabbit.oak.spi.commit.VisibleValidator) ImmutableTree(org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree) TreePermission(org.apache.jackrabbit.oak.spi.security.authorization.permission.TreePermission) Validator(org.apache.jackrabbit.oak.spi.commit.Validator) VisibleValidator(org.apache.jackrabbit.oak.spi.commit.VisibleValidator)

Example 10 with ImmutableTree

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();
}
Also used : EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) MemoryNodeBuilder(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder) ImmutableTree(org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree) MemoryNodeBuilder(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Aggregations

ImmutableTree (org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree)18 Test (org.junit.Test)10 Tree (org.apache.jackrabbit.oak.api.Tree)8 TreePermission (org.apache.jackrabbit.oak.spi.security.authorization.permission.TreePermission)7 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)6 AggregatedPermissionProvider (org.apache.jackrabbit.oak.spi.security.authorization.permission.AggregatedPermissionProvider)3 Nonnull (javax.annotation.Nonnull)2 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)2 PrivilegeBits (org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeBits)2 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)2 Field (java.lang.reflect.Field)1 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)1 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)1 MemoryNodeBuilder (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder)1 TreeType (org.apache.jackrabbit.oak.plugins.tree.TreeType)1 Validator (org.apache.jackrabbit.oak.spi.commit.Validator)1 VisibleValidator (org.apache.jackrabbit.oak.spi.commit.VisibleValidator)1 Before (org.junit.Before)1