Package javax.jcr.security

Examples of javax.jcr.security.AccessControlManager


        givePrivileges(childNPath, testGroup.getPrincipal(), privileges, getRestrictions(superuser, path));
        assertFalse(testAcMgr.hasPrivileges(childNPath, privilegesFromName(Privilege.JCR_MODIFY_PROPERTIES)));
    }

    public void testNewNodes() throws RepositoryException, NotExecutableException {
        AccessControlManager testAcMgr = getTestACManager();
        /*
         precondition:
         testuser must have READ-only permission on test-node and below
        */
        checkReadOnly(path);

        /* create some new nodes below 'path' */
        Node n = superuser.getNode(path);
        for (int i = 0; i < 5; i++) {
            n = n.addNode(nodeName2, testNodeType);
        }
        superuser.save();

        /* make sure the same privileges/permissions are granted as at path. */
        String childPath = n.getPath();
        Privilege[] privs = testAcMgr.getPrivileges(childPath);
        assertEquals(PrivilegeRegistry.getBits(privilegesFromName(Privilege.JCR_READ)),
                PrivilegeRegistry.getBits(privs));
        getTestSession().checkPermission(childPath, javax.jcr.Session.ACTION_READ);
    }
View Full Code Here


        testUser = null;

        // try to retrieve the acl again
        Session s = getHelper().getSuperuserSession();
        try {
            AccessControlManager acMgr = getAccessControlManager(s);
            acMgr.getPolicies(acPath);
        } finally {
            s.logout();
        }
    }
View Full Code Here

        /* test permissions. expected result:
           - testSession cannot lock at 'path'
           - testSession doesn't have ALL privilege at path
         */
        Session testSession = getTestSession();
        AccessControlManager acMgr = testSession.getAccessControlManager();

        assertFalse(acMgr.hasPrivileges(path, allPrivileges));
        assertFalse(acMgr.hasPrivileges(path, lockPrivileges));

        List<Privilege> remainingprivs = new ArrayList<Privilege>(Arrays.asList(allPrivileges[0].getAggregatePrivileges()));
        remainingprivs.remove(lockPrivileges[0]);
        assertTrue(acMgr.hasPrivileges(path, remainingprivs.toArray(new Privilege[remainingprivs.size()])));
    }
View Full Code Here

        givePrivileges(path, testUser.getPrincipal(), allPriv, getRestrictions(superuser, path));
        /* grant ALL privilege for testUser at 'childNPath' */
        givePrivileges(childNPath, testUser.getPrincipal(), allPriv, getRestrictions(superuser, childNPath));

        Session testSession = getTestSession();
        AccessControlManager acMgr = testSession.getAccessControlManager();

        assertTrue(acMgr.hasPrivileges(path, allPriv));
        assertTrue(acMgr.hasPrivileges(childNPath, allPriv));

        assertTrue(testSession.hasPermission(childNPath, Session.ACTION_REMOVE));

        Node child = testSession.getNode(childNPath);
        child.remove();
View Full Code Here

     *
     * @throws Exception
     */
    public void testGlobRestriction() throws Exception {
        Session testSession = getTestSession();
        AccessControlManager testAcMgr = getTestACManager();
        ValueFactory vf = superuser.getValueFactory();
        /*
          precondition:
          testuser must have READ-only permission on test-node and below
        */
        checkReadOnly(path);
        checkReadOnly(childNPath);

        Node child = superuser.getNode(childNPath).addNode(nodeName3);
        superuser.save();
        String childchildPath = child.getPath();

        Privilege[] write = privilegesFromName(PrivilegeRegistry.REP_WRITE);
        String writeActions = Session.ACTION_ADD_NODE +","+Session.ACTION_REMOVE +","+ Session.ACTION_SET_PROPERTY;


        // permissions defined @ path
        // restriction: grants write priv to all nodeName3 children
        Map<String, Value> restrictions = new HashMap<String, Value>(getRestrictions(superuser, path));
        restrictions.put(AccessControlConstants.P_GLOB.toString(), vf.createValue("/*"+nodeName3));
        givePrivileges(path, write, restrictions);

        assertFalse(testAcMgr.hasPrivileges(path, write));
        assertFalse(testSession.hasPermission(path, javax.jcr.Session.ACTION_SET_PROPERTY));

        assertFalse(testAcMgr.hasPrivileges(childNPath, write));
        assertFalse(testSession.hasPermission(childNPath, javax.jcr.Session.ACTION_SET_PROPERTY));

        assertTrue(testAcMgr.hasPrivileges(childNPath2, write));
        assertTrue(testSession.hasPermission(childNPath2, Session.ACTION_SET_PROPERTY));
        assertFalse(testSession.hasPermission(childNPath2, writeActions)); // removal req. rmchildnode privilege on parent.

        assertTrue(testAcMgr.hasPrivileges(childchildPath, write));
    }
View Full Code Here

     *
     * @throws Exception
     */
    public void testGlobRestriction2() throws Exception {
        Session testSession = getTestSession();
        AccessControlManager testAcMgr = getTestACManager();
        ValueFactory vf = superuser.getValueFactory();
        /*
          precondition:
          testuser must have READ-only permission on test-node and below
        */
        checkReadOnly(path);
        checkReadOnly(childNPath);

        Node child = superuser.getNode(childNPath).addNode(nodeName3);
        superuser.save();
        String childchildPath = child.getPath();

        Privilege[] write = privilegesFromName(PrivilegeRegistry.REP_WRITE);
        Privilege[] addNode = privilegesFromName(Privilege.JCR_ADD_CHILD_NODES);
        Privilege[] rmNode = privilegesFromName(Privilege.JCR_REMOVE_NODE);

        Map<String, Value> restrictions = new HashMap<String, Value>(getRestrictions(superuser, path));

        // permissions defined @ path
        // restriction: grants write-priv to nodeName3 grand-children but not direct nodeName3 children.
        restrictions.put(AccessControlConstants.P_GLOB.toString(), vf.createValue("/*/"+nodeName3));
        givePrivileges(path, write, restrictions);

        assertFalse(testAcMgr.hasPrivileges(path, write));
        assertFalse(testAcMgr.hasPrivileges(path, rmNode));

        assertFalse(testAcMgr.hasPrivileges(childNPath, addNode));

        assertFalse(testAcMgr.hasPrivileges(childNPath2, write));

        assertTrue(testAcMgr.hasPrivileges(childchildPath, write));
    }
View Full Code Here

     *
     * @throws Exception
     */
    public void testGlobRestriction3() throws Exception {
        Session testSession = getTestSession();
        AccessControlManager testAcMgr = getTestACManager();
        ValueFactory vf = superuser.getValueFactory();
        /*
          precondition:
          testuser must have READ-only permission on test-node and below
        */
        checkReadOnly(path);
        checkReadOnly(childNPath);

        Node child = superuser.getNode(childNPath).addNode(nodeName3);
        superuser.save();
        String childchildPath = child.getPath();

        Privilege[] write = privilegesFromName(PrivilegeRegistry.REP_WRITE);
        Privilege[] addNode = privilegesFromName(Privilege.JCR_ADD_CHILD_NODES);
        String writeActions = Session.ACTION_ADD_NODE +","+Session.ACTION_REMOVE +","+ Session.ACTION_SET_PROPERTY;

        Map<String, Value> restrictions = new HashMap<String, Value>(getRestrictions(superuser, path));

        // permissions defined @ path
        // restriction: allows write to nodeName3 children
        restrictions.put(AccessControlConstants.P_GLOB.toString(), vf.createValue("/*/"+nodeName3));
        givePrivileges(path, write, restrictions);
        // and grant add-node only at path (no glob restriction)
        givePrivileges(path, addNode, getRestrictions(superuser, path));

        assertFalse(testAcMgr.hasPrivileges(path, write));
        assertTrue(testAcMgr.hasPrivileges(path, addNode));

        assertFalse(testAcMgr.hasPrivileges(childNPath, write));
        assertTrue(testAcMgr.hasPrivileges(childNPath, addNode));

        assertFalse(testAcMgr.hasPrivileges(childNPath2, write));
        assertTrue(testAcMgr.hasPrivileges(childchildPath, write));
    }
View Full Code Here

     *
     * @throws Exception
     */
    public void testGlobRestriction4() throws Exception {
        Session testSession = getTestSession();
        AccessControlManager testAcMgr = getTestACManager();
        ValueFactory vf = superuser.getValueFactory();
        /*
          precondition:
          testuser must have READ-only permission on test-node and below
        */
        checkReadOnly(path);
        checkReadOnly(childNPath);

        Node child = superuser.getNode(childNPath).addNode(nodeName3);
        superuser.save();
        String childchildPath = child.getPath();

        Privilege[] write = privilegesFromName(PrivilegeRegistry.REP_WRITE);
        Privilege[] addNode = privilegesFromName(Privilege.JCR_ADD_CHILD_NODES);

        Map<String, Value> restrictions = new HashMap<String, Value>(getRestrictions(superuser, path));
        restrictions.put(AccessControlConstants.P_GLOB.toString(), vf.createValue("/*"+nodeName3));
        givePrivileges(path, write, restrictions);

        withdrawPrivileges(childNPath2, addNode, getRestrictions(superuser, childNPath2));

        assertFalse(testAcMgr.hasPrivileges(path, write));
        assertFalse(testSession.hasPermission(path, javax.jcr.Session.ACTION_REMOVE));

        assertFalse(testAcMgr.hasPrivileges(childNPath, write));
        assertFalse(testSession.hasPermission(childNPath, javax.jcr.Session.ACTION_REMOVE));

        assertFalse(testAcMgr.hasPrivileges(childNPath2, write));

        assertTrue(testAcMgr.hasPrivileges(childchildPath, write));
    }
View Full Code Here

     *
     * @throws Exception
     */
    public void testCancelInheritanceRestriction() throws Exception {
        Session testSession = getTestSession();
        AccessControlManager testAcMgr = getTestACManager();
        ValueFactory vf = superuser.getValueFactory();
        /*
          precondition:
          testuser must have READ-only permission on test-node and below
        */
        checkReadOnly(path);
        checkReadOnly(childNPath);

        Privilege[] write = privilegesFromName(PrivilegeRegistry.REP_WRITE);
        Privilege[] addNode = privilegesFromName(Privilege.JCR_ADD_CHILD_NODES);

        Map<String, Value> restrictions = new HashMap<String, Value>(getRestrictions(superuser, path));
        restrictions.put(AccessControlConstants.P_GLOB.toString(), vf.createValue(""));
        givePrivileges(path, write, restrictions);

        assertTrue(testAcMgr.hasPrivileges(path, write));
        assertTrue(testSession.hasPermission(path, Session.ACTION_SET_PROPERTY));

        assertFalse(testAcMgr.hasPrivileges(childNPath, write));
        assertFalse(testSession.hasPermission(childNPath, Session.ACTION_SET_PROPERTY));

        assertFalse(testAcMgr.hasPrivileges(childNPath2, write));
        assertFalse(testSession.hasPermission(childNPath2, Session.ACTION_SET_PROPERTY));
    }
View Full Code Here

    admin = loginWriter();
    userManager = ((JackrabbitSession) admin).getUserManager();
    Principal userPrincipal = userManager.createUser(TEST_USER_ID, TEST_USER_ID).getPrincipal();

    AccessControlManager acm = admin.getAccessControlManager();
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acm, "/");
    acl.addEntry(userPrincipal, AccessControlUtils.privilegesFromNames(acm, PrivilegeConstants.JCR_READ), true);
    acm.setPolicy("/", acl);

    Node a = admin.getRootNode().addNode("a");
    for (int i = 1; i < 10000; i++) {
      a.addNode("node" + i);
      acl = AccessControlUtils.getAccessControlList(acm, "/a/node"+i);
      acl.addEntry(userPrincipal, AccessControlUtils.privilegesFromNames(acm, PrivilegeConstants.JCR_READ), true);
      acm.setPolicy("/a/node"+i, acl);
    }

    admin.save();
    reader = login(new SimpleCredentials(TEST_USER_ID, TEST_USER_ID.toCharArray()));
View Full Code Here

TOP

Related Classes of javax.jcr.security.AccessControlManager

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.