Search in sources :

Example 81 with AccessControlList

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

the class AccessControlListTest method testAddAccessControlEntry.

public void testAddAccessControlEntry() throws NotExecutableException, RepositoryException {
    checkCanModifyAc(path);
    Privilege[] privileges = new Privilege[] { privs[0] };
    AccessControlList acl = getList(acMgr, path);
    AccessControlEntry entry = null;
    if (acl.addAccessControlEntry(testPrincipal, privileges)) {
        AccessControlEntry[] aces = acl.getAccessControlEntries();
        for (int i = 0; i < aces.length; i++) {
            if (aces[i].getPrincipal().equals(testPrincipal) && Arrays.asList(privileges).equals(Arrays.asList(aces[i].getPrivileges()))) {
                entry = aces[i];
            }
        }
        if (entry == null)
            throw new NotExecutableException();
    } else {
        throw new NotExecutableException();
    }
    assertEquals("Principal name of the ACE must be equal to the name of the passed Principal", testPrincipal.getName(), entry.getPrincipal().getName());
    assertEquals("Privileges of the ACE must be equal to the passed ones", Arrays.asList(privileges), Arrays.asList(entry.getPrivileges()));
}
Also used : AccessControlList(javax.jcr.security.AccessControlList) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) AccessControlEntry(javax.jcr.security.AccessControlEntry) Privilege(javax.jcr.security.Privilege)

Example 82 with AccessControlList

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

the class AccessControlListTest method testAddAccessControlEntryIsTransient.

public void testAddAccessControlEntryIsTransient() throws NotExecutableException, RepositoryException {
    checkCanModifyAc(path);
    AccessControlList acl = getList(acMgr, path);
    List<AccessControlEntry> originalAces = Arrays.asList(acl.getAccessControlEntries());
    if (!acl.addAccessControlEntry(testPrincipal, privs)) {
        throw new NotExecutableException();
    }
    // set the policy (see #testAddAccessControlEntryAndSetPolicy)
    acMgr.setPolicy(path, acl);
    // revert the changes made
    superuser.refresh(false);
    assertEquals("After calling Session.refresh() any changes to a nodes policies must be reverted.", originalAces, Arrays.asList(getList(acMgr, path).getAccessControlEntries()));
}
Also used : AccessControlList(javax.jcr.security.AccessControlList) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) AccessControlEntry(javax.jcr.security.AccessControlEntry)

Example 83 with AccessControlList

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

the class AccessControlListTest method testAddAbstractPrivilege.

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;
        }
    }
    if (abstractPriv == null) {
        throw new NotExecutableException("No abstract privilege found.");
    }
    AccessControlList acl = getList(acMgr, path);
    try {
        acl.addAccessControlEntry(testPrincipal, new Privilege[] { abstractPriv });
        fail("Adding an ACE with an abstract privilege must fail.");
    } catch (AccessControlException e) {
    // success
    }
}
Also used : AccessControlList(javax.jcr.security.AccessControlList) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) AccessControlException(javax.jcr.security.AccessControlException) Privilege(javax.jcr.security.Privilege)

Example 84 with AccessControlList

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

the class AccessControlListTest method testRemoveAddedAccessControlEntry.

public void testRemoveAddedAccessControlEntry() throws NotExecutableException, RepositoryException {
    checkCanModifyAc(path);
    AccessControlList acl = getList(acMgr, path);
    acl.addAccessControlEntry(testPrincipal, privs);
    AccessControlEntry[] aces = acl.getAccessControlEntries();
    for (int i = 0; i < aces.length; i++) {
        acl.removeAccessControlEntry(aces[i]);
    }
    assertEquals("After removing all ACEs the ACL must be empty", 0, acl.getAccessControlEntries().length);
}
Also used : AccessControlList(javax.jcr.security.AccessControlList) AccessControlEntry(javax.jcr.security.AccessControlEntry)

Example 85 with AccessControlList

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

the class AccessControlListTest method testRemoveAccessControlEntry.

public void testRemoveAccessControlEntry() throws NotExecutableException, RepositoryException {
    checkCanModifyAc(path);
    AccessControlList acl = getList(acMgr, path);
    AccessControlEntry[] entries = acl.getAccessControlEntries();
    if (entries.length > 0) {
        AccessControlEntry ace = entries[0];
        acl.removeAccessControlEntry(ace);
        // retrieve entries again:
        List<AccessControlEntry> remainingEntries = Arrays.asList(acl.getAccessControlEntries());
        assertFalse("AccessControlList.getAccessControlEntries still returns a removed ACE.", remainingEntries.contains(ace));
    }
}
Also used : AccessControlList(javax.jcr.security.AccessControlList) AccessControlEntry(javax.jcr.security.AccessControlEntry)

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