Package org.apache.jackrabbit.api.security

Examples of org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry


        // match the required ones.
        Privilege[] privs = privilegesFromName(Privilege.JCR_ALL);

        Map<String, Value> restr = new HashMap<String, Value>();
        restr.put(nodePath, new StringValue("/a/b/c/d"));
        JackrabbitAccessControlEntry pe = createEntry(testPrincipal, privs, true, restr);

        assertEquals("/a/b/c/d", pe.getRestriction(nodePath).getString());
        assertEquals(PropertyType.PATH, pe.getRestriction(nodePath).getType());

        restr = new HashMap<String, Value>();
        restr.put(nodePath,  restrictions.get(nodePath));
        restr.put(glob,  new BooleanValue(true));
        pe = createEntry(testPrincipal, privs, true, restr);

        assertEquals(true, pe.getRestriction(glob).getBoolean());
        assertEquals(PropertyType.STRING, pe.getRestriction(glob).getType());
    }
View Full Code Here


        assertEquals(testPrincipal.getName(), tmpl.getPrincipal().getName());
        assertSame(testPrincipal, tmpl.getPrincipal());
    }

    public void testGetPrivilegeBits() throws RepositoryException, NotExecutableException {
        JackrabbitAccessControlEntry tmpl = createEntry(new String[] {Privilege.JCR_READ}, true);

        int privs = PrivilegeRegistry.getBits(tmpl.getPrivileges());
        assertEquals(1, tmpl.getPrivileges().length);
        assertEquals(getAccessControlManager(superuser).privilegeFromName(Privilege.JCR_READ),
                tmpl.getPrivileges()[0]);

        tmpl = createEntry(new String[] {PrivilegeRegistry.REP_WRITE}, true);
        assertEquals(getAccessControlManager(superuser).privilegeFromName(PrivilegeRegistry.REP_WRITE),
                tmpl.getPrivileges()[0]);
    }
View Full Code Here

        assertEquals(getAccessControlManager(superuser).privilegeFromName(PrivilegeRegistry.REP_WRITE),
                tmpl.getPrivileges()[0]);
    }

    public void testGetPrivileges() throws RepositoryException, NotExecutableException {
        JackrabbitAccessControlEntry entry = createEntry(new String[] {Privilege.JCR_READ}, true);

        Privilege[] privs = entry.getPrivileges();
        assertNotNull(privs);
        assertEquals(1, privs.length);
        assertEquals(privs[0], acMgr.privilegeFromName(Privilege.JCR_READ));
        assertTrue(PrivilegeRegistry.getBits(privs) == PrivilegeRegistry.getBits(entry.getPrivileges()));

        entry = createEntry(new String[] {PrivilegeRegistry.REP_WRITE}, true);
        privs = entry.getPrivileges();
        assertNotNull(privs);
        assertEquals(1, privs.length);
        assertEquals(privs[0], acMgr.privilegeFromName(PrivilegeRegistry.REP_WRITE));
        assertTrue(PrivilegeRegistry.getBits(privs) == PrivilegeRegistry.getBits(entry.getPrivileges()));

        entry = createEntry(new String[] {Privilege.JCR_ADD_CHILD_NODES,
                Privilege.JCR_REMOVE_CHILD_NODES}, true);
        privs = entry.getPrivileges();
        assertNotNull(privs);
        assertEquals(2, privs.length);

        Privilege[] param = privilegesFromNames(new String[] {
                Privilege.JCR_ADD_CHILD_NODES,
                Privilege.JCR_REMOVE_CHILD_NODES
        });
        assertEquals(Arrays.asList(param), Arrays.asList(privs));
        assertEquals(PrivilegeRegistry.getBits(privs), PrivilegeRegistry.getBits(entry.getPrivileges()));
    }
View Full Code Here

        assertEquals(PrivilegeRegistry.getBits(privs), PrivilegeRegistry.getBits(entry.getPrivileges()));
    }

    public void testEquals() throws RepositoryException, NotExecutableException  {

        JackrabbitAccessControlEntry ace = createEntry(new String[] {Privilege.JCR_ALL}, true);
        List<JackrabbitAccessControlEntry> equalAces = new ArrayList<JackrabbitAccessControlEntry>();
        equalAces.add(createEntry(new String[] {Privilege.JCR_ALL}, true));

        Privilege[] privs = acMgr.privilegeFromName(Privilege.JCR_ALL).getDeclaredAggregatePrivileges();
        equalAces.add(createEntry(testPrincipal, privs, true));
View Full Code Here

            assertEquals(ace, equalAce);
        }
    }

    public void testNotEquals() throws RepositoryException, NotExecutableException  {
        JackrabbitAccessControlEntry ace = createEntry(new String[] {Privilege.JCR_ALL}, true);
        List<JackrabbitAccessControlEntry> otherAces = new ArrayList<JackrabbitAccessControlEntry>();

        try {
            // ACE template with different principal
            Principal princ = new Principal() {
                public String getName() {
                    return "a name";
                }
            };
            Privilege[] privs = new Privilege[] {
                    acMgr.privilegeFromName(Privilege.JCR_ALL)
            };
            otherAces.add(createEntry(princ, privs, true));
        } catch (RepositoryException e) {
        }

        // ACE template with different privileges
        try {
            otherAces.add(createEntry(new String[] {Privilege.JCR_READ}, true));
        } catch (RepositoryException e) {
        }
        // ACE template with different 'allow' flag
        try {
            otherAces.add(createEntry(new String[] {Privilege.JCR_ALL}, false));
        } catch (RepositoryException e) {
        }
        // ACE template with different privileges and 'allows
        try {
            otherAces.add(createEntry(new String[] {PrivilegeRegistry.REP_WRITE}, false));
        } catch (RepositoryException e) {
        }

        // other ace impl
        final Privilege[] privs = new Privilege[] {
                acMgr.privilegeFromName(Privilege.JCR_ALL)
        };
        JackrabbitAccessControlEntry pe = new JackrabbitAccessControlEntry() {
            public boolean isAllow() {
                return true;
            }
            public int getPrivilegeBits() throws AccessControlException {
                return PrivilegeRegistry.getBits(privs);
View Full Code Here

        int allows = PrivilegeRegistry.NO_PRIVILEGE;
        int denies = PrivilegeRegistry.NO_PRIVILEGE;
        AccessControlEntry[] entries = templ.getAccessControlEntries();
        for (AccessControlEntry en : entries) {
            if (princ.equals(en.getPrincipal()) && en instanceof JackrabbitAccessControlEntry) {
                JackrabbitAccessControlEntry ace = (JackrabbitAccessControlEntry) en;
                int entryBits = PrivilegeRegistry.getBits(ace.getPrivileges());
                if (ace.isAllow()) {
                    allows |= Permission.diff(entryBits, denies);
                } else {
                    denies |= Permission.diff(entryBits, allows);
                }
            }
View Full Code Here

    }

    public void testRemoveInvalidEntry() throws RepositoryException {
        JackrabbitAccessControlList pt = createEmptyTemplate(getTestPath());
        try {
            pt.removeAccessControlEntry(new JackrabbitAccessControlEntry() {
                public boolean isAllow() {
                    return false;
                }
                public int getPrivilegeBits() throws RepositoryException, NotExecutableException {
                    return PrivilegeRegistry.getBits(privilegesFromName(Privilege.JCR_READ));
View Full Code Here

    }

    public void testRemoveInvalidEntry2() throws RepositoryException {
        JackrabbitAccessControlList pt = createEmptyTemplate(getTestPath());
        try {
            pt.removeAccessControlEntry(new JackrabbitAccessControlEntry() {
                public boolean isAllow() {
                    return false;
                }
                public int getPrivilegeBits() {
                    return 0;
View Full Code Here

    }

    public void testRemoveInvalidEntry() throws RepositoryException {
        JackrabbitAccessControlList pt = createEmptyTemplate(getTestPath());
        try {
            pt.removeAccessControlEntry(new JackrabbitAccessControlEntry() {
                public boolean isAllow() {
                    return false;
                }
                public int getPrivilegeBits() throws RepositoryException, NotExecutableException {
                    return PrivilegeRegistry.getBits(privilegesFromName(Privilege.JCR_READ));
View Full Code Here

    }

    public void testRemoveInvalidEntry2() throws RepositoryException {
        JackrabbitAccessControlList pt = createEmptyTemplate(getTestPath());
        try {
            pt.removeAccessControlEntry(new JackrabbitAccessControlEntry() {
                public boolean isAllow() {
                    return false;
                }
                public int getPrivilegeBits() {
                    return 0;
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry

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.