Package javax.jcr.security

Examples of javax.jcr.security.Privilege


     * @throws RepositoryException If an error occurs.
     * @throws NotExecutableException If the test cannot be executed.
     */
    public void testNotHasPrivileges() throws RepositoryException, NotExecutableException {
        Privilege[] privs = acMgr.getPrivileges(testRootNode.getPath());
        Privilege all = acMgr.privilegeFromName(Privilege.JCR_ALL);

        // remove all privileges that are granted.
        Set notGranted = new HashSet(Arrays.asList(all.getAggregatePrivileges()));
        for (int i = 0; i < privs.length; i++) {
            if (privs[i].isAggregate()) {
                notGranted.removeAll(Arrays.asList(privs[i].getAggregatePrivileges()));
            } else {
                notGranted.remove(privs[i]);
View Full Code Here


        assertTrue("getSupportedPrivileges must return a non-empty array even for read-only session.", privileges.length > 0);
    }

    public void testGetPrivileges() throws RepositoryException {
        List privs = Arrays.asList(testAcMgr.getPrivileges(testPath));
        Privilege readPrivilege = testAcMgr.privilegeFromName(Privilege.JCR_READ);
        assertTrue("A read-only session must have READ access to the test node.",
                privs.contains(readPrivilege));
    }
View Full Code Here

        assertTrue("A read-only session must have READ access to the test node.",
                privs.contains(readPrivilege));
    }

    public void testHasPrivileges() throws RepositoryException, NotExecutableException {
        Privilege priv = testAcMgr.privilegeFromName(Privilege.JCR_READ);
        assertTrue("Read-only session must have READ privilege on test node.",
                testAcMgr.hasPrivileges(testPath, new Privilege[] {priv}));
    }
View Full Code Here

        assertTrue("Read-only session must have READ privilege on test node.",
                testAcMgr.hasPrivileges(testPath, new Privilege[] {priv}));
    }

    public void testNotHasPrivileges() throws RepositoryException, NotExecutableException {
        Privilege all = testAcMgr.privilegeFromName(Privilege.JCR_ALL);
        assertFalse("Read-only session must not have ALL privilege",
                testAcMgr.hasPrivileges(testPath, new Privilege[] {all}));
    }
View Full Code Here

    }

    public void testAddAggregatePrivilege() throws NotExecutableException, RepositoryException {
        checkCanModifyAc(path);

        Privilege aggregate = null;
        for (int i = 0; i < privs.length; i++) {
            if (privs[i].isAggregate()) {
                aggregate = privs[i];
                break;
            }
        }
        if (aggregate == null) {
            throw new NotExecutableException("No aggregate privilege supported at " + path);
        }

        AccessControlList acl = getList(acMgr, path);
        acl.addAccessControlEntry(testPrincipal, new Privilege[] {aggregate});

        // make sure all privileges are present now
        List privs = currentPrivileges(acl, testPrincipal);
        assertTrue("Privileges added through 'addAccessControlEntry' must be " +
                "reflected upon getAccessControlEntries",
                privs.contains(aggregate) || privs.containsAll(Arrays.asList(aggregate.getAggregatePrivileges())));
    }
View Full Code Here

    }

    public void testAddAggregatedPrivilegesSeparately() throws NotExecutableException, RepositoryException {
        checkCanModifyAc(path);

        Privilege aggregate = null;
        for (int i = 0; i < privs.length; i++) {
            if (privs[i].isAggregate()) {
                aggregate = privs[i];
                break;
            }
        }
        if (aggregate == null) {
            throw new NotExecutableException("No aggregate privilege supported at " + path);
        }

        AccessControlList acl = getList(acMgr, path);
        acl.addAccessControlEntry(testPrincipal, new Privilege[] {aggregate});

        Privilege[] privs = aggregate.getAggregatePrivileges();
        for (int i = 0; i < privs.length; i++) {
            boolean modified = acl.addAccessControlEntry(testPrincipal, new Privilege[] {privs[i]});
            assertFalse("Adding the aggregated privs individually later on must not modify the policy", modified);
        }
    }
View Full Code Here

    }

    public void testAddAbstractPrivilege() throws NotExecutableException, RepositoryException {
        checkCanModifyAc(path);

        Privilege abstractPriv = null;
        Privilege[] allPrivs = acMgr.privilegeFromName(Privilege.JCR_ALL).getAggregatePrivileges();
        for (int i = 0; i < allPrivs.length; i++) {
            if (allPrivs[i].isAbstract()) {
                abstractPriv = allPrivs[i];
                break;
View Full Code Here

    public void testAddAccessControlEntryInvalidPrivilege() throws NotExecutableException, RepositoryException {
        checkCanModifyAc(path);

        try {
            Privilege[] invalidPrivs = new Privilege[] {new Privilege() {
                public String getName() {
                    return null;
                }
                public boolean isAbstract() {
                    return false;
View Full Code Here

        if (twoPrivs.size() < 2) {
            throw new NotExecutableException("At least 2 supported, non-aggregate privileges required at " + path);
        }

        AccessControlList acl = getList(acMgr, path);
        Privilege privilege = (Privilege) twoPrivs.get(0);
        // add first privilege:
        acl.addAccessControlEntry(testPrincipal, new Privilege[] {privilege});

        // add a second privilege (but not specifying the privilege added before)
        // -> the first privilege must not be removed.
        Privilege privilege2 = (Privilege) twoPrivs.get(1);
        acl.addAccessControlEntry(testPrincipal, new Privilege[] {privilege2});

        List currentPrivileges = currentPrivileges(acl, testPrincipal);
        assertTrue("'AccessControlList.addAccessControlEntry' must not remove privileges added before", currentPrivileges.containsAll(twoPrivs));
    }
View Full Code Here

        }
    }

    public void testInvalidPrivilege() throws RepositoryException,
            NotExecutableException {
        Privilege invalidPriv = new Privilege() {
                public String getName() {
                    return "";
                }
                public boolean isAbstract() {
                    return false;
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.