Search in sources :

Example 1 with ImmutableTree

use of org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree in project jackrabbit-oak by apache.

the class GlobbingPathFilterTest method multipleMatches.

/**
     * **&#47r/s/t/u/v should match r/s/t/u/v and r/s/t/u/v/r/s/t/u/v and r/s/t/u/v/r/s/t/u/v/r/s/t/u/v
     */
@Test
public void multipleMatches() {
    EventFilter filter = new GlobbingPathFilter("**/r/s/t/u/v");
    ImmutableTree t = tree;
    for (int c = 0; c < 2; c++) {
        for (String name : elements("r/s/t/u")) {
            t = t.getChild(name);
            assertFalse(filter.includeAdd(name, t.getNodeState()));
            filter = filter.create(name, t.getNodeState(), t.getNodeState());
            assertNotNull(filter);
        }
        t = t.getChild("v");
        assertTrue(filter.includeAdd("v", t.getNodeState()));
        filter = filter.create("v", t.getNodeState(), t.getNodeState());
        assertNotNull(filter);
    }
}
Also used : ImmutableTree(org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree) Test(org.junit.Test)

Example 2 with ImmutableTree

use of org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree in project jackrabbit-oak by apache.

the class GlobbingPathFilterTest method all.

/**
     * ** should match every path
     */
@Test
public void all() {
    EventFilter filter = new GlobbingPathFilter(STAR_STAR);
    ImmutableTree t = tree;
    for (String name : elements("a/b/c/d")) {
        t = t.getChild(name);
        assertTrue(filter.includeAdd(name, t.getNodeState()));
        filter = filter.create(name, t.getNodeState(), t.getNodeState());
        assertNotNull(filter);
    }
}
Also used : ImmutableTree(org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree) Test(org.junit.Test)

Example 3 with ImmutableTree

use of org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree in project jackrabbit-oak by apache.

the class CompositeProviderNoScopeTest method testTreePermissionGetChild.

@Override
@Test
public void testTreePermissionGetChild() throws Exception {
    List<String> childNames = ImmutableList.of("test", "a", "b", "c", "nonexisting");
    Tree rootTree = readOnlyRoot.getTree(ROOT_PATH);
    NodeState ns = ((ImmutableTree) rootTree).getNodeState();
    TreePermission tp = createPermissionProvider().getTreePermission(rootTree, TreePermission.EMPTY);
    assertCompositeTreePermission(tp);
    for (String cName : childNames) {
        ns = ns.getChildNode(cName);
        tp = tp.getChildPermission(cName, ns);
        assertCompositeTreePermission(false, tp);
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Tree(org.apache.jackrabbit.oak.api.Tree) ImmutableTree(org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree) ImmutableTree(org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree) TreePermission(org.apache.jackrabbit.oak.spi.security.authorization.permission.TreePermission) Test(org.junit.Test)

Example 4 with ImmutableTree

use of org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree in project jackrabbit-oak by apache.

the class CompositeProviderNoScopeTest method testTreePermissionSize.

@Test
public void testTreePermissionSize() throws Exception {
    Field tpField = CompositeTreePermission.class.getDeclaredField("treePermissions");
    tpField.setAccessible(true);
    Tree rootTree = readOnlyRoot.getTree(ROOT_PATH);
    NodeState ns = ((ImmutableTree) rootTree).getNodeState();
    TreePermission tp = cppTestUser.getTreePermission(rootTree, TreePermission.EMPTY);
    assertEquals(2, ((TreePermission[]) tpField.get(tp)).length);
    List<String> childNames = ImmutableList.of("test", "a", "b", "c", "nonexisting");
    for (String cName : childNames) {
        ns = ns.getChildNode(cName);
        tp = tp.getChildPermission(cName, ns);
        assertCompositeTreePermission(false, tp);
    }
}
Also used : Field(java.lang.reflect.Field) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Tree(org.apache.jackrabbit.oak.api.Tree) ImmutableTree(org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree) ImmutableTree(org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree) TreePermission(org.apache.jackrabbit.oak.spi.security.authorization.permission.TreePermission) Test(org.junit.Test)

Example 5 with ImmutableTree

use of org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree in project jackrabbit-oak by apache.

the class CompositePermissionProvider method hasPrivileges.

@Override
public boolean hasPrivileges(@Nullable Tree tree, @Nonnull String... privilegeNames) {
    Tree immutableTree = PermissionUtil.getImmutableTree(tree, immutableRoot);
    PrivilegeBits privilegeBits = privilegeBitsProvider.getBits(privilegeNames);
    if (privilegeBits.isEmpty()) {
        return true;
    }
    boolean hasPrivileges = false;
    PrivilegeBits coveredPrivs = PrivilegeBits.getInstance();
    for (AggregatedPermissionProvider aggregatedPermissionProvider : pps) {
        PrivilegeBits supported = aggregatedPermissionProvider.supportedPrivileges(immutableTree, privilegeBits);
        if (doEvaluate(supported)) {
            Set<String> supportedNames = privilegeBitsProvider.getPrivilegeNames(supported);
            hasPrivileges = aggregatedPermissionProvider.hasPrivileges(immutableTree, supportedNames.toArray(new String[supportedNames.size()]));
            coveredPrivs.add(supported);
            if (!hasPrivileges) {
                break;
            }
        }
    }
    return hasPrivileges && coveredPrivs.includes(privilegeBits);
}
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)

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