Package org.apache.jackrabbit.oak.util

Examples of org.apache.jackrabbit.oak.util.NodeUtil


    @Override
    public void writeRestrictions(String oakPath, Tree aceTree, Set<Restriction> restrictions) throws RepositoryException {
        // validation of the restrictions is delegated to the commit hook
        // see #validateRestrictions below
        if (!restrictions.isEmpty()) {
            NodeUtil aceNode = new NodeUtil(aceTree);
            NodeUtil rNode = aceNode.getOrAddChild(REP_RESTRICTIONS, NT_REP_RESTRICTIONS);
            for (Restriction restriction : restrictions) {
                rNode.getTree().setProperty(restriction.getProperty());
            }
        }
    }
View Full Code Here


        }
    }

    @Test
    public void testReadRestrictions() throws Exception {
        NodeUtil aceNode = new NodeUtil(root.getTree("/")).addChild("test", NT_REP_GRANT_ACE);
        aceNode.setBoolean("boolean", true);
        aceNode.setValues("longs", new Value[] {vf.createValue(10), vf.createValue(290)});
        aceNode.setString(REP_GLOB, "*");
        aceNode.setNames(REP_NT_NAMES); // empty array
        aceNode.setString("invalid", "val");
        aceNode.setStrings("invalid2", "val1", "val2", "val3");

        Set<Restriction> restrictions = provider.readRestrictions("/test", aceNode.getTree());
        assertEquals(4, restrictions.size());
        for (Restriction r : restrictions) {
            String name = r.getDefinition().getName();
            if (!supported.contains(name)) {
                fail("read unsupported restriction");
View Full Code Here

        }
    }

    @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);
    }
View Full Code Here

        provider.writeRestrictions("/test", aceNode.getTree(), restrictions);
    }

    @Test
    public void testWriteUnsupportedRestrictions() throws Exception {
        NodeUtil aceNode = new NodeUtil(root.getTree("/")).addChild("test", NT_REP_GRANT_ACE);
        Restriction invalid = new RestrictionImpl(PropertyStates.createProperty("invalid", vf.createValue(true)), false);
        try {
            provider.writeRestrictions("/test", aceNode.getTree(), ImmutableSet.<Restriction>of(invalid));
            fail("AccessControlException expected");
        } catch (AccessControlException e) {
            // success
        }
    }
View Full Code Here

        }
    }

    @Test
    public void testValidateRestrictions() throws Exception {
        NodeUtil aceNode = new NodeUtil(root.getTree("/")).addChild("test", NT_REP_GRANT_ACE);
        NodeUtil rNode = aceNode.addChild(REP_RESTRICTIONS, NT_REP_RESTRICTIONS);
        rNode.setBoolean("boolean", true);
        rNode.setValues("longs", new Value[] {vf.createValue(10), vf.createValue(290)});
        rNode.setString(REP_GLOB, "*");
        rNode.setNames(REP_NT_NAMES); // empty array

        provider.validateRestrictions("/test", aceNode.getTree());

        // remove mandatory restriction
        rNode.removeProperty("boolean");
        try {
            provider.validateRestrictions("/test", aceNode.getTree());
            fail("validation should detect missing mandatory restrictions");
        } catch (AccessControlException e) {
            // success
        }

        // set with wrong type
        rNode.setName("boolean", "nt:base");
        try {
            provider.validateRestrictions("/test", aceNode.getTree());
            fail("validation should detect wrong restriction type");
        } catch (AccessControlException e) {
            // success
        } finally {
            rNode.setBoolean("boolean", true);
        }

        rNode.setStrings(REP_GLOB, "*", "/jcr:content");
        try {
            provider.validateRestrictions("/test", aceNode.getTree());
            fail("validation should detect wrong restriction type (multi vs single valued)");
        } catch (AccessControlException e) {
            // success
View Full Code Here

        }
    }

    @Test
    public void testGetRestrictionPattern() throws Exception {
        NodeUtil aceNode = new NodeUtil(root.getTree("/")).addChild("test", NT_REP_GRANT_ACE);
        NodeUtil rNode = aceNode.addChild(REP_RESTRICTIONS, NT_REP_RESTRICTIONS);
        rNode.setString(REP_GLOB, "*");

        assertFalse(provider.getPattern("/test", aceNode.getTree()) instanceof CompositePattern);

        rNode.setBoolean("boolean", true);
        rNode.setValues("longs", new Value[]{vf.createValue(10), vf.createValue(290)});

        assertTrue(provider.getPattern("/test", rNode.getTree()) instanceof CompositePattern);
    }
View Full Code Here

            if (targetTree != null) {
                if (!Text.isDescendantOrEqual(userPath, targetTree.getPath())) {
                    throw new RepositoryException("Relative path " + relPath + " outside of scope of " + this);
                }
            } else {
                targetTree = new NodeUtil(userTree).getOrAddTree(relPath, JcrConstants.NT_UNSTRUCTURED).getTree();
                if (!Text.isDescendantOrEqual(userPath, targetTree.getPath())) {
                    throw new RepositoryException("Relative path " + relPath + " outside of scope of " + this);
                }
            }
        } else {
View Full Code Here

    @Before
    public void before() throws Exception {
        super.before();

        Principal testPrincipal = getTestPrincipal();
        NodeUtil rootNode = new NodeUtil(root.getTree("/"), namePathMapper);
        NodeUtil testNode = rootNode.addChild("testPath", JcrConstants.NT_UNSTRUCTURED);
        testNode.addChild("childNode", JcrConstants.NT_UNSTRUCTURED);

        AccessControlManager acMgr = getAccessControlManager(root);
        JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, testPath);
        acl.addAccessControlEntry(testPrincipal, privilegesFromNames(JCR_ADD_CHILD_NODES));
        acl.addAccessControlEntry(EveryonePrincipal.getInstance(), privilegesFromNames(JCR_READ));
View Full Code Here

    public void testModifyRestrictions() throws Exception {
        Tree testAce = root.getTree(testPath + "/rep:policy").getChildren().iterator().next();
        assertEquals(testPrincipalName, testAce.getProperty(REP_PRINCIPAL_NAME).getValue(Type.STRING));

        // add a new restriction node through the OAK API instead of access control manager
        NodeUtil node = new NodeUtil(testAce);
        NodeUtil restrictions = node.addChild(REP_RESTRICTIONS, NT_REP_RESTRICTIONS);
        restrictions.setString(REP_GLOB, "*");
        String restrictionsPath = restrictions.getTree().getPath();
        root.commit();

        Tree principalRoot = getPrincipalRoot(testPrincipalName);
        assertEquals(1, cntEntries(principalRoot));
        assertEquals("*", principalRoot.getChildren().iterator().next().getProperty(REP_GLOB).getValue(Type.STRING));
View Full Code Here

        Tree aclTree = root.getTree(testPath + "/rep:policy");
        // reorder
        aclTree.getChildren().iterator().next().orderBefore(null);

        // add a new entry
        NodeUtil ace = new NodeUtil(aclTree).addChild("denyEveryoneLockMgt", NT_REP_DENY_ACE);
        ace.setString(REP_PRINCIPAL_NAME, EveryonePrincipal.NAME);
        ace.setStrings(AccessControlConstants.REP_PRIVILEGES, JCR_LOCK_MANAGEMENT);
        root.commit();

        entry = getEntry(testPrincipalName, testPath, 1);
        assertEquals(1, entry.getProperty(REP_INDEX).getValue(Type.LONG).longValue());
    }
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.oak.util.NodeUtil

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.