Search in sources :

Example 76 with AccessControlList

use of javax.jcr.security.AccessControlList in project jackrabbit by apache.

the class AccessControlListTest method testAddAccessControlEntryAgain.

public void testAddAccessControlEntryAgain() throws NotExecutableException, RepositoryException {
    checkCanModifyAc(path);
    AccessControlList list = getList(acMgr, path);
    list.addAccessControlEntry(testPrincipal, privs);
    AccessControlEntry[] entries = list.getAccessControlEntries();
    if (entries.length > 0) {
        assertFalse("Adding an existing entry again must not modify the AC-List", list.addAccessControlEntry(entries[0].getPrincipal(), entries[0].getPrivileges()));
    } else {
        throw new NotExecutableException();
    }
}
Also used : AccessControlList(javax.jcr.security.AccessControlList) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) AccessControlEntry(javax.jcr.security.AccessControlEntry)

Example 77 with AccessControlList

use of javax.jcr.security.AccessControlList in project jackrabbit by apache.

the class AccessControlListTest method testExtendPrivileges.

public void testExtendPrivileges() throws NotExecutableException, RepositoryException {
    checkCanModifyAc(path);
    // search 2 non-aggregated privileges
    List<Privilege> twoPrivs = new ArrayList<Privilege>(2);
    for (int i = 0; i < privs.length && twoPrivs.size() < 2; i++) {
        if (!privs[i].isAggregate()) {
            twoPrivs.add(privs[i]);
        }
    }
    if (twoPrivs.size() < 2) {
        throw new NotExecutableException("At least 2 supported, non-aggregate privileges required at " + path);
    }
    AccessControlList acl = getList(acMgr, path);
    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 = twoPrivs.get(1);
    acl.addAccessControlEntry(testPrincipal, new Privilege[] { privilege2 });
    List<Privilege> currentPrivileges = currentPrivileges(acl, testPrincipal);
    assertTrue("'AccessControlList.addAccessControlEntry' must not remove privileges added before", currentPrivileges.containsAll(twoPrivs));
}
Also used : AccessControlList(javax.jcr.security.AccessControlList) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) ArrayList(java.util.ArrayList) Privilege(javax.jcr.security.Privilege)

Example 78 with AccessControlList

use of javax.jcr.security.AccessControlList in project jackrabbit by apache.

the class AccessControlListTest method testAddAccessControlEntryInvalidPrincipal.

public void testAddAccessControlEntryInvalidPrincipal() throws NotExecutableException, RepositoryException {
    checkCanModifyAc(path);
    try {
        Principal invalidPrincipal = getHelper().getUnknownPrincipal(superuser);
        AccessControlList acl = getList(acMgr, path);
        acl.addAccessControlEntry(invalidPrincipal, privs);
        fail("Adding an entry with an unknown principal must throw AccessControlException.");
    } catch (AccessControlException e) {
    // success.
    } finally {
        superuser.refresh(false);
    }
}
Also used : AccessControlList(javax.jcr.security.AccessControlList) AccessControlException(javax.jcr.security.AccessControlException) Principal(java.security.Principal)

Example 79 with AccessControlList

use of javax.jcr.security.AccessControlList in project jackrabbit by apache.

the class AccessControlListTest method testRemoveIllegalAccessControlEntry.

public void testRemoveIllegalAccessControlEntry() throws NotExecutableException, RepositoryException {
    checkCanModifyAc(path);
    try {
        AccessControlEntry entry = new AccessControlEntry() {

            public Principal getPrincipal() {
                return testPrincipal;
            }

            public Privilege[] getPrivileges() {
                return privs;
            }
        };
        AccessControlList acl = getList(acMgr, path);
        acl.removeAccessControlEntry(entry);
        fail("AccessControlManager.removeAccessControlEntry with an unknown entry must throw AccessControlException.");
    } catch (AccessControlException e) {
    // ok
    }
}
Also used : AccessControlList(javax.jcr.security.AccessControlList) AccessControlEntry(javax.jcr.security.AccessControlEntry) AccessControlException(javax.jcr.security.AccessControlException) Privilege(javax.jcr.security.Privilege)

Example 80 with AccessControlList

use of javax.jcr.security.AccessControlList in project jackrabbit by apache.

the class AccessControlListTest method testAddAccessControlEntryEmptyPrivilegeArray.

public void testAddAccessControlEntryEmptyPrivilegeArray() throws NotExecutableException, RepositoryException {
    checkCanModifyAc(path);
    try {
        Privilege[] invalidPrivs = new Privilege[0];
        AccessControlList acl = getList(acMgr, path);
        acl.addAccessControlEntry(testPrincipal, invalidPrivs);
        fail("Adding an entry with an invalid privilege array must throw AccessControlException.");
    } catch (AccessControlException e) {
    // success.
    } finally {
        superuser.refresh(false);
    }
}
Also used : AccessControlList(javax.jcr.security.AccessControlList) AccessControlException(javax.jcr.security.AccessControlException) Privilege(javax.jcr.security.Privilege)

Aggregations

AccessControlList (javax.jcr.security.AccessControlList)97 AccessControlEntry (javax.jcr.security.AccessControlEntry)49 AccessControlManager (javax.jcr.security.AccessControlManager)49 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)39 Privilege (javax.jcr.security.Privilege)25 Node (javax.jcr.Node)17 RepositoryException (javax.jcr.RepositoryException)17 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)17 AccessControlPolicyIterator (javax.jcr.security.AccessControlPolicyIterator)15 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)15 Test (org.junit.Test)13 Principal (java.security.Principal)12 AccessDeniedException (javax.jcr.AccessDeniedException)12 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)6 AccessControlException (javax.jcr.security.AccessControlException)6 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)6 NodeImpl (org.apache.jackrabbit.core.NodeImpl)6 MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)5 AccessControlException (java.security.AccessControlException)5