Search in sources :

Example 91 with AccessControlEntry

use of javax.jcr.security.AccessControlEntry 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 92 with AccessControlEntry

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

the class AccessControlListTest method testRemoveAccessControlEntryAndSetPolicy.

public void testRemoveAccessControlEntryAndSetPolicy() throws NotExecutableException, RepositoryException {
    checkCanModifyAc(path);
    // add a new ACE that can be removed later on.
    AccessControlList acl = getList(acMgr, path);
    if (!acl.addAccessControlEntry(testPrincipal, privs)) {
        throw new NotExecutableException();
    } else {
        acMgr.setPolicy(path, acl);
    }
    // try to re-access the modifiable ACL in order to remove the ACE
    // added before.
    acl = getList(acMgr, path);
    AccessControlEntry ace = null;
    AccessControlEntry[] aces = acl.getAccessControlEntries();
    if (aces.length == 0) {
        throw new NotExecutableException();
    } else {
        ace = aces[0];
        acl.removeAccessControlEntry(ace);
    }
    // before setting the policy again -> no changes visible.
    assertEquals("Removal of an ACE must only be visible upon 'setPolicy'", Arrays.asList(aces), Arrays.asList(getList(acMgr, path).getAccessControlEntries()));
    // set policy again.
    acMgr.setPolicy(path, acl);
    assertEquals("After 'setPolicy' the ACE-removal must be visible to the editing session.", Arrays.asList(acl.getAccessControlEntries()), 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 93 with AccessControlEntry

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

the class AccessControlListTest method testRemoveAccessControlEntryIsTransient.

public void testRemoveAccessControlEntryIsTransient() throws NotExecutableException, RepositoryException {
    checkCanModifyAc(path);
    AccessControlList acl = getList(acMgr, path);
    // make sure an ACE is present and modifications are persisted.
    if (acl.addAccessControlEntry(testPrincipal, privs)) {
        acMgr.setPolicy(path, acl);
        superuser.save();
    } else {
        throw new NotExecutableException();
    }
    // retrieve ACL again -> transient removal of the ace
    acl = getList(acMgr, path);
    AccessControlEntry ace = acl.getAccessControlEntries()[0];
    acl.removeAccessControlEntry(ace);
    acMgr.setPolicy(path, acl);
    // revert changes -> removed entry must be present again.
    superuser.refresh(false);
    List<AccessControlEntry> entries = Arrays.asList(getList(acMgr, path).getAccessControlEntries());
    assertTrue("After reverting any changes the removed ACE should be present again.", entries.contains(ace));
}
Also used : AccessControlList(javax.jcr.security.AccessControlList) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) AccessControlEntry(javax.jcr.security.AccessControlEntry)

Example 94 with AccessControlEntry

use of javax.jcr.security.AccessControlEntry 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 95 with AccessControlEntry

use of javax.jcr.security.AccessControlEntry 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)

Aggregations

AccessControlEntry (javax.jcr.security.AccessControlEntry)126 JackrabbitAccessControlEntry (org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry)50 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)50 Privilege (javax.jcr.security.Privilege)47 AccessControlManager (javax.jcr.security.AccessControlManager)39 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)39 AccessControlList (javax.jcr.security.AccessControlList)38 Test (org.junit.Test)29 Principal (java.security.Principal)28 NodeImpl (org.apache.jackrabbit.core.NodeImpl)13 ArrayList (java.util.ArrayList)12 Node (javax.jcr.Node)12 Value (javax.jcr.Value)10 JackrabbitAccessControlManager (org.apache.jackrabbit.api.security.JackrabbitAccessControlManager)9 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 InputStream (java.io.InputStream)8 RepositoryException (javax.jcr.RepositoryException)8 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)8 ParsingContentHandler (org.apache.jackrabbit.commons.xml.ParsingContentHandler)8