Package javax.jcr.security

Examples of javax.jcr.security.Privilege


        for (String privilegeName : privilegeNames) {
            if (privilegeName == null || !privileges.containsKey(privilegeName)) {
                throw accessViolation(10, "Invalid privilege " + privilegeName);
            }

            Privilege privilege = privileges.get(privilegeName);
            if (privilege.isAbstract()) {
                throw accessViolation(11, "Abstract privilege " + privilegeName);
            }
        }
    }
View Full Code Here


        for (String name : newCustomPrivs.keySet()) {
            boolean isAbstract = true;
            String[] aggrNames = newCustomPrivs.get(name);

            Privilege registered = privilegeManager.registerPrivilege(name, isAbstract, aggrNames);

            Node privilegeRoot = session.getNode(PrivilegeConstants.PRIVILEGES_PATH);
            assertTrue(privilegeRoot.hasNode(name));
            Node privNode = privilegeRoot.getNode(name);
            assertTrue(privNode.getProperty(PrivilegeConstants.REP_IS_ABSTRACT).getBoolean());
View Full Code Here

        privilegeManager.registerPrivilege(privName, isAbstract, new String[0]);

        Session s2 = getAdminSession();
        try {
            PrivilegeManager pm = getPrivilegeManager(s2);
            Privilege priv = pm.getPrivilege(privName);
            assertEquals(privName, priv.getName());
            assertEquals(isAbstract, priv.isAbstract());
            assertFalse(priv.isAggregate());
        } finally {
            s2.logout();
        }
    }
View Full Code Here

            String privName = "testCustomPrivilegeVisibleAfterRefresh";
            privilegeManager.registerPrivilege(privName, isAbstract, new String[0]);

            // before refreshing: privilege not visible
            try {
                Privilege priv = pm.getPrivilege(privName);
                fail("Custom privilege will show up after Session#refresh()");
            } catch (AccessControlException e) {
                // success
            }

            // latest after refresh privilege manager must be updated
            s2.refresh(true);
            Privilege priv = pm.getPrivilege(privName);
            assertEquals(privName, priv.getName());
            assertEquals(isAbstract, priv.isAbstract());
            assertFalse(priv.isAggregate());
        } finally {
            s2.logout();
        }
    }
View Full Code Here

    public Privilege[] getRegisteredPrivileges() throws RepositoryException {
        Map<String, Privilege> privileges = new HashMap<String, Privilege>();
        NodeIterator it = getPrivilegeRoot().getNodes();
        while (it.hasNext()) {
            Node privilegeNode = it.nextNode();
            Privilege p = getPrivilege(privilegeNode, privileges);
            if (p != null) {
                privileges.put(p.getName(),  p);
            }
        }
        return privileges.values().toArray(new Privilege[privileges.size()]);
    }
View Full Code Here

    private NodeImpl getPrivilegeRoot() throws RepositoryException {
        return (NodeImpl) sessionContext.getSession().getNode(PRIVILEGE_ROOT);
    }

    private Privilege getPrivilege(Node privilegeNode, Map<String, Privilege> collected) throws RepositoryException {
        Privilege privilege = null;
        if (privilegeNode.isNodeType(NT_REP_PRIVILEGE)) {
            String name = privilegeNode.getName();
            boolean isAbstract = privilegeNode.getProperty(REP_IS_ABSTRACT).getBoolean();

            Set<String> declaredAggrNames;
View Full Code Here

    //--------------------------------------------------< privilegeFromName >---
    @Test
    public void testPrivilegeFromName() throws Exception {
        List<Privilege> allPrivileges = Arrays.asList(getPrivilegeManager(root).getRegisteredPrivileges());
        for (Privilege privilege : allPrivileges) {
            Privilege p = acMgr.privilegeFromName(privilege.getName());
            assertEquals(privilege, p);
        }
    }
View Full Code Here

        }
    }

    @Test
    public void testPrivilegeFromExpandedName() throws Exception {
        Privilege readPriv = getPrivilegeManager(root).getPrivilege(PrivilegeConstants.JCR_READ);
        assertEquals(readPriv, acMgr.privilegeFromName(Privilege.JCR_READ));
    }
View Full Code Here

    /**
     * @since oak 1.0 ACE doesn't validate privileges.
     */
    @Test
    public void testUnknownPrivilege() throws Exception {
        Privilege invalidPriv = new Privilege() {
            public String getName() {
                return "";
            }

            public boolean isAbstract() {
View Full Code Here

        for (String name : newCustomPrivs.keySet()) {
            boolean isAbstract = true;
            String[] aggrNames = newCustomPrivs.get(name);

            Privilege registered = privilegeManager.registerPrivilege(name, isAbstract, aggrNames);

            // validate definition
            Privilege privilege = privilegeManager.getPrivilege(name);
            assertNotNull(privilege);
            assertEquals(name, privilege.getName());
            assertTrue(privilege.isAbstract());
            assertEquals(0, privilege.getDeclaredAggregatePrivileges().length);
            assertContainsDeclared(privilegeManager.getPrivilege(PrivilegeConstants.JCR_ALL), name);
        }

        Map<String, String[]> newAggregates = new HashMap<String, String[]>();
        // a new aggregate of custom privileges
        newAggregates.put("newA2", getAggregateNames("test:new", "new"));
        // a new aggregate of custom and built-in privilege
        newAggregates.put("newA1", getAggregateNames("new", PrivilegeConstants.JCR_READ));
        // aggregating built-in privileges
        newAggregates.put("aggrBuiltIn", getAggregateNames(PrivilegeConstants.JCR_MODIFY_PROPERTIES, PrivilegeConstants.JCR_READ));

        for (String name : newAggregates.keySet()) {
            boolean isAbstract = false;
            String[] aggrNames = newAggregates.get(name);
            privilegeManager.registerPrivilege(name, isAbstract, aggrNames);
            Privilege p = privilegeManager.getPrivilege(name);

            assertNotNull(p);
            assertEquals(name, p.getName());
            assertFalse(p.isAbstract());

            for (String n : aggrNames) {
                assertContainsDeclared(p, n);
            }
            assertContainsDeclared(privilegeManager.getPrivilege(PrivilegeConstants.JCR_ALL), name);
View Full Code Here

TOP

Related Classes of javax.jcr.security.Privilege

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.