Package org.apache.jackrabbit.oak.api

Examples of org.apache.jackrabbit.oak.api.ContentSession


        }
    }

    @Test
    public void testGetPrivilegesForReadPaths() throws Exception {
        ContentSession testSession = createTestSession();
        try {
            PermissionProvider pp = createPermissionProvider(testSession) ;
            for (String path : READ_PATHS) {
                Tree tree = root.getTree(path);
                assertEquals(Collections.singleton(PrivilegeConstants.JCR_READ), pp.getPrivileges(tree));
            }
            assertEquals(Collections.<String>emptySet(), pp.getPrivileges(null));
        } finally {
            testSession.close();
        }
    }
View Full Code Here


        }
    }

    @Test
    public void testHasPrivilegesForReadPaths() throws Exception {
        ContentSession testSession = createTestSession();
        try {
            PermissionProvider pp = createPermissionProvider(testSession) ;
            for (String path : READ_PATHS) {
                Tree tree = root.getTree(path);
                assertTrue(pp.hasPrivileges(tree, PrivilegeConstants.JCR_READ));
                assertTrue(pp.hasPrivileges(tree, PrivilegeConstants.REP_READ_NODES));
                assertTrue(pp.hasPrivileges(tree, PrivilegeConstants.REP_READ_PROPERTIES));
                assertFalse(pp.hasPrivileges(tree, PrivilegeConstants.JCR_READ_ACCESS_CONTROL));
            }
            assertFalse(pp.hasPrivileges(null, PrivilegeConstants.JCR_READ));
        } finally {
            testSession.close();
        }
    }
View Full Code Here

    @Test
    public void testAdministatorConfig() throws Exception {
        adminstrators.addMember(getTestUser());
        root.commit();

        ContentSession testSession = createTestSession();
        try {
            Root r = testSession.getLatestRoot();
            Root immutableRoot = new ImmutableRoot(r, TreeTypeProvider.EMPTY);

            PermissionProvider pp = createPermissionProvider(testSession) ;
            assertTrue(r.getTree("/").exists());
            TreePermission tp = pp.getTreePermission(immutableRoot.getTree("/"), TreePermission.EMPTY);
            assertSame(TreePermission.ALL, tp);

            for (String path : READ_PATHS) {
                Tree tree = r.getTree(path);
                assertTrue(tree.exists());
                assertSame(TreePermission.ALL, pp.getTreePermission(tree, TreePermission.EMPTY));
            }
        } finally {
            testSession.close();
        }
    }
View Full Code Here

        Thread.sleep(100);
        root2.refresh();

        // login with testUser1 and testUser2 (on cluster node 2)
        ContentSession session1 = contentRepository2.login(new SimpleCredentials("testUser1", "testUser1".toCharArray()), null);
        ContentSession session2 = contentRepository2.login(new SimpleCredentials("testUser2", "testUser2".toCharArray()), null);

        // testUser1 can read /testNode
        assertTrue(session1.getLatestRoot().getTree("/testNode").exists());

        // testUser2 cannot read /testNode
        assertFalse(session2.getLatestRoot().getTree("/testNode").exists());

        // now, allow jcr:read also for 'everyone' (on cluster node 1)
        acl1 = AccessControlUtils.getAccessControlList(aclMgr1, "/testNode");
        acl1.addEntry(EveryonePrincipal.getInstance(), AccessControlUtils.privilegesFromNames(aclMgr1, "jcr:read"), true);
        aclMgr1.setPolicy("/testNode", acl1);
        root1.commit();

        Thread.sleep(100);
        root2.refresh();

        // testUser1 can read /testNode
        assertTrue(session1.getLatestRoot().getTree("/testNode").exists());

        // testUser2 can also read /testNode
        assertTrue(session2.getLatestRoot().getTree("/testNode").exists());
    }
View Full Code Here

        assertFalse(rootTree1.hasChild("a"));
        assertTrue(rootTree2.hasChild("a"));

        String uid = testPrincipal.getName();
        ContentSession session3 = login(new SimpleCredentials(uid, uid.toCharArray()));
        Tree rootTree3 = session3.getLatestRoot().getTree("/");
        assertFalse(rootTree3.hasChild("a"));

    }
View Full Code Here

        assertTrue(root.getTree(childPath + "/rep:policy").exists());

        Tree principalRoot = getPrincipalRoot(EveryonePrincipal.NAME);
        assertEquals(4, cntEntries(principalRoot));

        ContentSession testSession = createTestSession();
        Root testRoot = testSession.getLatestRoot();

        assertTrue(testRoot.getTree(childPath).exists());
        assertFalse(testRoot.getTree(childPath + "/rep:policy").exists());

        testRoot.getTree(childPath).remove();
        testRoot.commit();
        testSession.close();

        root.refresh();
        assertFalse(root.getTree(testPath).hasChild("childNode"));
        assertFalse(root.getTree(childPath + "/rep:policy").exists());
        // aces must be removed in the permission store even if the editing
View Full Code Here

    }

    @Test
    public void testLoginFailed() throws Exception {
        try {
            ContentSession cs = login(new SimpleCredentials("unknown", new char[0]));
            cs.close();
            fail("login failure expected");
        } catch (LoginException e) {
            // success
        } finally {
            assertNull(userManager.getAuthorizable(userId));
View Full Code Here

    @Test
    public void testSyncCreateUser() throws Exception {
        options.put(ExternalLoginModule.PARAM_SYNC_MODE, SyncMode.CREATE_USER);

        ContentSession cs = null;
        try {
            cs = login(new SimpleCredentials(userId, new char[0]));

            root.refresh();
            for (String id : ids) {
                if (id.equals(userId)) {
                    Authorizable a = userManager.getAuthorizable(id);
                    assertNotNull(a);
                    for (String prop : TestLoginModule.externalUser.getProperties().keySet()) {
                        assertTrue(a.hasProperty(prop));
                    }
                } else {
                    assertNull(userManager.getAuthorizable(id));
                }
            }
        } finally {
            if (cs != null) {
                cs.close();
            }
            options.clear();
        }
    }
View Full Code Here

    @Test
    public void testSyncCreateGroup() throws Exception {
        options.put(ExternalLoginModule.PARAM_SYNC_MODE, SyncMode.CREATE_GROUP);

        ContentSession cs = null;
        try {
            cs = login(new SimpleCredentials(userId, new char[0]));

            root.refresh();
            for (String id : ids) {
                assertNull(userManager.getAuthorizable(id));
            }
        } finally {
            if (cs != null) {
                cs.close();
            }
            options.clear();
        }
    }
View Full Code Here

    @Test
    public void testSyncCreateUserAndGroups() throws Exception {
        options.put(ExternalLoginModule.PARAM_SYNC_MODE, new String[]{SyncMode.CREATE_USER, SyncMode.CREATE_GROUP});

        ContentSession cs = null;
        try {
            cs = login(new SimpleCredentials(userId, new char[0]));

            root.refresh();
            for (String id : ids) {
                if (id.equals(userId)) {
                    Authorizable a = userManager.getAuthorizable(id);
                    assertNotNull(a);
                    for (String prop : TestLoginModule.externalUser.getProperties().keySet()) {
                        assertTrue(a.hasProperty(prop));
                    }
                } else {
                    assertNotNull(userManager.getAuthorizable(id));
                }
            }
        } finally {
            if (cs != null) {
                cs.close();
            }
            options.clear();
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.oak.api.ContentSession

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.