Search in sources :

Example 81 with NodeUtil

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

the class CugContextTest method testInvalidCug.

@Test
public void testInvalidCug() throws Exception {
    PropertyState ps = PropertyStates.createProperty(CugConstants.REP_PRINCIPAL_NAMES, ImmutableSet.of(getTestUser().getPrincipal().getName()), Type.STRINGS);
    // cug at unsupported path -> context doesn't take supported paths into account.
    Tree invalidCug = new NodeUtil(root.getTree(UNSUPPORTED_PATH)).addChild(CugConstants.REP_CUG_POLICY, CugConstants.NT_REP_CUG_POLICY).getTree();
    invalidCug.setProperty(ps);
    assertTrue(CugContext.INSTANCE.definesContextRoot(invalidCug));
    assertTrue(CugContext.INSTANCE.definesTree(invalidCug));
    assertTrue(CugContext.INSTANCE.definesProperty(invalidCug, invalidCug.getProperty(CugConstants.REP_PRINCIPAL_NAMES)));
    // 'cug' with wrong node type -> detected as no-cug by context
    invalidCug = new NodeUtil(root.getTree(UNSUPPORTED_PATH)).addChild(CugConstants.REP_CUG_POLICY, NT_OAK_UNSTRUCTURED).getTree();
    invalidCug.setProperty(ps);
    assertFalse(CugContext.INSTANCE.definesContextRoot(invalidCug));
    assertFalse(CugContext.INSTANCE.definesTree(invalidCug));
    assertFalse(CugContext.INSTANCE.definesProperty(invalidCug, invalidCug.getProperty(CugConstants.REP_PRINCIPAL_NAMES)));
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 82 with NodeUtil

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

the class CugTreePermissionTest method testIsInCugSupportedPathWithoutCug.

@Test
public void testIsInCugSupportedPathWithoutCug() throws Exception {
    NodeUtil node = new NodeUtil(root.getTree(SUPPORTED_PATH2));
    Tree c1 = node.addChild("c1", NT_OAK_UNSTRUCTURED).getTree();
    Tree c2 = node.addChild("c2", NT_OAK_UNSTRUCTURED).getTree();
    String cugPath = c2.getPath();
    createCug(cugPath, getTestGroupPrincipal());
    root.commit();
    assertTrue(getCugTreePermission(cugPath).isInCug());
    assertFalse(getCugTreePermission(c1.getPath()).isInCug());
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) AbstractTree(org.apache.jackrabbit.oak.plugins.tree.impl.AbstractTree) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 83 with NodeUtil

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

the class CugAccessControlManagerTest method testSetInvalidCugNode.

@Test(expected = AccessControlException.class)
public void testSetInvalidCugNode() throws Exception {
    Tree supportedTree = root.getTree(SUPPORTED_PATH);
    new NodeUtil(supportedTree).addChild(REP_CUG_POLICY, NodeTypeConstants.NT_OAK_UNSTRUCTURED);
    cugAccessControlManager.setPolicy(SUPPORTED_PATH, new CugPolicyImpl(SUPPORTED_PATH, NamePathMapper.DEFAULT, getPrincipalManager(root), ImportBehavior.BESTEFFORT));
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 84 with NodeUtil

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

the class CompositeTreePermissionTest method before.

@Override
public void before() throws Exception {
    super.before();
    NodeUtil rootNode = new NodeUtil(root.getTree("/"));
    rootNode.addChild("test", NodeTypeConstants.NT_OAK_UNSTRUCTURED);
    root.commit();
    readOnlyRoot = RootFactory.createReadOnlyRoot(root);
    rootTree = (ImmutableTree) readOnlyRoot.getTree("/");
    fullScopeProvider = new FullScopeProvider(readOnlyRoot);
}
Also used : NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil)

Example 85 with NodeUtil

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

the class JcrUUIDTest method before.

@Before
public void before() throws Exception {
    super.before();
    ntMgr = new ReadWriteNodeTypeManager() {

        @Nonnull
        @Override
        protected Root getWriteRoot() {
            return root;
        }

        @Override
        protected Tree getTypes() {
            return root.getTree(NODE_TYPES_PATH);
        }
    };
    if (!ntMgr.hasNodeType(NT_NAME)) {
        NodeTypeTemplate tmpl = ntMgr.createNodeTypeTemplate();
        tmpl.setName(NT_NAME);
        tmpl.setDeclaredSuperTypeNames(new String[] { JcrConstants.MIX_REFERENCEABLE, JcrConstants.NT_UNSTRUCTURED });
        ntMgr.registerNodeType(tmpl, true);
    }
    NodeUtil a = new NodeUtil(root.getTree("/a"));
    NodeUtil test = a.addChild("referenceable", NT_NAME);
    test.setString(JcrConstants.JCR_UUID, IdentifierManager.generateUUID());
    referenceablePath = test.getTree().getPath();
}
Also used : ReadWriteNodeTypeManager(org.apache.jackrabbit.oak.plugins.nodetype.write.ReadWriteNodeTypeManager) Root(org.apache.jackrabbit.oak.api.Root) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) Nonnull(javax.annotation.Nonnull) Tree(org.apache.jackrabbit.oak.api.Tree) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Before(org.junit.Before)

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