Search in sources :

Example 16 with NodeUtil

use of org.apache.jackrabbit.oak.util.NodeUtil in project jackrabbit-oak by apache.

the class IndexSelectionTest method uuidIndexNotNullQuery.

@Test
public void uuidIndexNotNullQuery() throws Exception {
    NodeUtil node = new NodeUtil(root.getTree("/"));
    String uuid = UUID.randomUUID().toString();
    node.setString(JcrConstants.JCR_UUID, uuid);
    root.commit();
    assertQuery("SELECT * FROM [nt:base] WHERE [jcr:uuid] is not null", ImmutableList.of("/"));
    assertEquals("Test index plan should be invoked", 1, testIndexProvider.index.invocationCount);
}
Also used : NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test) AbstractQueryTest(org.apache.jackrabbit.oak.query.AbstractQueryTest)

Example 17 with NodeUtil

use of org.apache.jackrabbit.oak.util.NodeUtil in project jackrabbit-oak by apache.

the class CompositeRestrictionProviderTest method testWriteRestrictions.

@Test
public void testWriteRestrictions() throws Exception {
    NodeUtil aceNode = new NodeUtil(root.getTree("/")).addChild("test", NT_REP_GRANT_ACE);
    Set<Restriction> restrictions = ImmutableSet.of(provider.createRestriction("/test", "boolean", vf.createValue(true)), provider.createRestriction("/test", "longs"), provider.createRestriction("/test", REP_GLOB, vf.createValue("*")), provider.createRestriction("/test", REP_NT_NAMES, vf.createValue("nt:base", PropertyType.NAME), vf.createValue("nt:version", PropertyType.NAME)));
    provider.writeRestrictions("/test", aceNode.getTree(), restrictions);
}
Also used : Restriction(org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 18 with NodeUtil

use of org.apache.jackrabbit.oak.util.NodeUtil in project jackrabbit-oak by apache.

the class CustomRestrictionProviderTest method before.

@Before
@Override
public void before() throws Exception {
    super.before();
    NodeUtil rootNode = new NodeUtil(root.getTree("/"));
    NodeUtil testRootNode = rootNode.addChild("testRoot", NT_UNSTRUCTURED);
    NodeUtil a = testRootNode.addChild("a", NT_UNSTRUCTURED);
    NodeUtil b = a.addChild("b", NT_UNSTRUCTURED);
    NodeUtil c = b.addChild("c", NT_UNSTRUCTURED);
    c.setBoolean(PROP_NAME_PROTECT_ME, true);
    NodeUtil d = c.addChild("d", NT_UNSTRUCTURED);
    d.addChild("e", NT_UNSTRUCTURED);
    root.commit();
    testPrincipal = getTestUser().getPrincipal();
}
Also used : NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Before(org.junit.Before)

Example 19 with NodeUtil

use of org.apache.jackrabbit.oak.util.NodeUtil in project jackrabbit-oak by apache.

the class ItemNamePatternTest method testMatchesItem.

@Test
public void testMatchesItem() throws Exception {
    NodeUtil rootTree = new NodeUtil(root.getTree("/"));
    List<String> matching = ImmutableList.of("a", "b", "c", "d/e/a", "a/b/c/d/b", "test/c");
    for (String relPath : matching) {
        Tree testTree = rootTree.getOrAddTree(relPath, NodeTypeConstants.NT_OAK_UNSTRUCTURED).getTree();
        assertTrue(pattern.matches(testTree, null));
        assertTrue(pattern.matches(testTree, PropertyStates.createProperty("a", Boolean.FALSE)));
        assertFalse(pattern.matches(testTree, PropertyStates.createProperty("f", "anyval")));
        testTree.remove();
    }
    List<String> notMatching = ImmutableList.of("d", "b/d", "d/e/f", "c/b/abc");
    for (String relPath : notMatching) {
        Tree testTree = rootTree.getOrAddTree(relPath, NodeTypeConstants.NT_OAK_UNSTRUCTURED).getTree();
        assertFalse(pattern.matches(testTree, null));
        assertTrue(pattern.matches(testTree, PropertyStates.createProperty("a", Boolean.FALSE)));
        assertFalse(pattern.matches(testTree, PropertyStates.createProperty("f", "anyval")));
        testTree.remove();
    }
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 20 with NodeUtil

use of org.apache.jackrabbit.oak.util.NodeUtil in project jackrabbit-oak by apache.

the class PrefixPatternTest method testMatchesItem.

@Test
public void testMatchesItem() throws Exception {
    NodeUtil rootTree = new NodeUtil(root.getTree("/"));
    for (String prefix : prefixes) {
        Tree testTree = rootTree.addChild(prefix + ":name", NodeTypeConstants.NT_OAK_UNSTRUCTURED).getTree();
        assertTrue(pattern.matches(testTree, null));
        assertTrue(pattern.matches(testTree, PropertyStates.createProperty(prefix + ":f", "anyval")));
        assertFalse(pattern.matches(testTree, PropertyStates.createProperty("a", Boolean.FALSE)));
        testTree.remove();
    }
    List<String> notMatching = ImmutableList.of(NamespaceRegistry.PREFIX_EMPTY, NamespaceRegistry.PREFIX_MIX, "any");
    for (String prefix : notMatching) {
        String name = (prefix.isEmpty()) ? "name" : prefix + ":name";
        Tree testTree = rootTree.addChild(name, NodeTypeConstants.NT_OAK_UNSTRUCTURED).getTree();
        assertFalse(pattern.matches(testTree, null));
        assertFalse(pattern.matches(testTree, PropertyStates.createProperty("f", "anyval")));
        assertTrue(pattern.matches(testTree, PropertyStates.createProperty("jcr:a", Boolean.FALSE)));
        testTree.remove();
    }
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

NodeUtil (org.apache.jackrabbit.oak.util.NodeUtil)183 Test (org.junit.Test)149 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)74 Tree (org.apache.jackrabbit.oak.api.Tree)67 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)59 Root (org.apache.jackrabbit.oak.api.Root)28 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)14 Before (org.junit.Before)14 JackrabbitAccessControlPolicy (org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy)13 TokenInfo (org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo)13 AccessControlManager (javax.jcr.security.AccessControlManager)12 Principal (java.security.Principal)10 EveryonePrincipal (org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal)8 AccessControlException (javax.jcr.security.AccessControlException)7 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)7 JackrabbitAccessControlManager (org.apache.jackrabbit.api.security.JackrabbitAccessControlManager)6 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)6 Privilege (javax.jcr.security.Privilege)5 Restriction (org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction)5 AccessControlList (javax.jcr.security.AccessControlList)4