Search in sources :

Example 11 with ImmutableTree

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

the class PrivilegeValidator method childNodeAdded.

@Override
public Validator childNodeAdded(String name, NodeState after) throws CommitFailedException {
    if (isPrivilegeDefinition(after)) {
        // make sure privileges have been initialized before
        getPrivilegesTree(rootBefore);
        // name may not contain reserved namespace prefix
        if (NamespaceConstants.RESERVED_PREFIXES.contains(Text.getNamespacePrefix(name))) {
            String msg = "Failed to register custom privilege: Definition uses reserved namespace: " + name;
            throw new CommitFailedException("Privilege", 1, msg);
        }
        // validate the definition
        Tree tree = new ImmutableTree(ImmutableTree.ParentProvider.UNSUPPORTED, name, after);
        validateDefinition(tree);
    }
    // that is not handled by this validator anyway).
    return null;
}
Also used : 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) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException)

Example 12 with ImmutableTree

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

the class GlobbingPathFilterTest method matchSuffix.

/**
     * r/s/t&#47** should match r/s/t and all its descendants
     */
@Test
public void matchSuffix() {
    EventFilter filter = new GlobbingPathFilter("a/b/c/d/r/s/t/**");
    ImmutableTree t = tree;
    for (String name : elements("a/b/c/d/r/s")) {
        t = t.getChild(name);
        assertFalse(filter.includeAdd(name, t.getNodeState()));
        filter = filter.create(name, t.getNodeState(), t.getNodeState());
        assertNotNull(filter);
    }
    for (String name : elements("t/u/v/r/s/t/u/v/r/s/t/u/v/w")) {
        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 13 with ImmutableTree

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

the class GlobbingPathFilterTest method matchAtEnd.

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

Example 14 with ImmutableTree

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

the class GlobbingPathFilterTest method setup.

@Before
public void setup() {
    NodeBuilder root = EMPTY_NODE.builder();
    createPath(root, "a/b/c/d");
    createPath(root, "q");
    createPath(root, "x/y/x/y/z");
    createPath(root, "r/s/t/u/v/r/s/t/u/v/r/s/t/u/v/w");
    tree = new ImmutableTree(root.getNodeState());
}
Also used : ImmutableTree(org.apache.jackrabbit.oak.plugins.tree.impl.ImmutableTree) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Before(org.junit.Before)

Example 15 with ImmutableTree

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

the class GlobbingPathFilterTest method inTheMiddle.

/**
     * match ** 'in the middle'
     */
@Test
public void inTheMiddle() {
    EventFilter filter = new GlobbingPathFilter("/foo/" + STAR_STAR + "/bar");
    ImmutableTree t = tree;
    for (String name : elements("foo/a/b/c")) {
        t = t.getChild(name);
        assertFalse(filter.includeAdd(name, t.getNodeState()));
        filter = filter.create(name, t.getNodeState(), t.getNodeState());
        assertNotNull(filter);
    }
    for (String name : elements("bar")) {
        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)

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