Search in sources :

Example 61 with AccessControlEntry

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

the class AccessControlImporterTest method testImportPolicyExists.

/**
     * Imports a resource-based ACL containing a single entry for a policy that
     * already exists: expected outcome its that the existing ACE is replaced.
     */
public void testImportPolicyExists() throws Exception {
    try {
        Node target = createImportTargetWithPolicy(EveryonePrincipal.getInstance());
        doImport(target.getPath(), XML_POLICY_TREE_2);
        AccessControlManager acMgr = superuser.getAccessControlManager();
        AccessControlPolicy[] policies = acMgr.getPolicies(target.getPath());
        assertEquals(1, policies.length);
        assertTrue(policies[0] instanceof JackrabbitAccessControlList);
        AccessControlEntry[] entries = ((JackrabbitAccessControlList) policies[0]).getAccessControlEntries();
        assertEquals(1, entries.length);
        AccessControlEntry entry = entries[0];
        assertEquals(EveryonePrincipal.getInstance(), entry.getPrincipal());
        List<Privilege> privs = Arrays.asList(entry.getPrivileges());
        assertEquals(1, privs.size());
        assertEquals(acMgr.privilegeFromName(Privilege.JCR_WRITE), entry.getPrivileges()[0]);
        if (entry instanceof JackrabbitAccessControlEntry) {
            assertTrue(((JackrabbitAccessControlEntry) entry).isAllow());
        }
    } finally {
        superuser.refresh(false);
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) Node(javax.jcr.Node) JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) AccessControlEntry(javax.jcr.security.AccessControlEntry) Privilege(javax.jcr.security.Privilege) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList)

Example 62 with AccessControlEntry

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

the class AccessControlImporterTest method testImportEmptyExistingPolicy.

/**
     * Imports an empty resource-based ACL for a policy that already exists.
     *
     * @throws Exception
     */
public void testImportEmptyExistingPolicy() throws Exception {
    try {
        Node target = createImportTargetWithPolicy(null);
        doImport(target.getPath(), XML_POLICY_ONLY);
        AccessControlPolicy[] policies = superuser.getAccessControlManager().getPolicies(target.getPath());
        assertEquals(1, policies.length);
        assertTrue(policies[0] instanceof JackrabbitAccessControlList);
        AccessControlEntry[] entries = ((JackrabbitAccessControlList) policies[0]).getAccessControlEntries();
        assertEquals(0, entries.length);
    } finally {
        superuser.refresh(false);
    }
}
Also used : AccessControlPolicy(javax.jcr.security.AccessControlPolicy) Node(javax.jcr.Node) JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) AccessControlEntry(javax.jcr.security.AccessControlEntry) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList)

Example 63 with AccessControlEntry

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

the class L9_RemoveAuthorizableTest method testAccessControlEntry.

public void testAccessControlEntry() throws RepositoryException, NotExecutableException {
    // remove test user
    removeTestUser();
    boolean found = false;
    AccessControlList acl = AccessControlUtils.getAccessControlList(superuser, testRoot);
    if (acl != null) {
        for (AccessControlEntry ace : acl.getAccessControlEntries()) {
            if (testUser.getPrincipal().getName().equals(ace.getPrincipal().getName())) {
                found = true;
            }
        }
    }
    // EXERCISE: do you expect the ACE for test-principal to be still present? explain why and fix the test if necessary.
    assertTrue(found);
}
Also used : AccessControlList(javax.jcr.security.AccessControlList) AccessControlEntry(javax.jcr.security.AccessControlEntry)

Example 64 with AccessControlEntry

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

the class L3_AccessControlListTest method testReorderEntries.

public void testReorderEntries() throws Exception {
    Privilege[] read = AccessControlUtils.privilegesFromNames(acMgr, Privilege.JCR_READ, Privilege.JCR_READ_ACCESS_CONTROL);
    Privilege[] write = AccessControlUtils.privilegesFromNames(acMgr, Privilege.JCR_WRITE);
    acl.addAccessControlEntry(testPrincipal, read);
    acl.addEntry(testPrincipal, write, false);
    acl.addAccessControlEntry(EveryonePrincipal.getInstance(), write);
    AccessControlEntry[] entries = acl.getAccessControlEntries();
    assertEquals(3, entries.length);
    AccessControlEntry first = entries[0];
    AccessControlEntry second = entries[1];
    AccessControlEntry third = entries[2];
    // EXERCISE: reorder 'second' to the first position
    entries = acl.getAccessControlEntries();
    assertEquals(second, entries[0]);
    assertEquals(first, entries[1]);
    assertEquals(third, entries[2]);
    // EXERCISE reorder 'third' before 'first'
    entries = acl.getAccessControlEntries();
    assertEquals(second, entries[0]);
    assertEquals(third, entries[1]);
    assertEquals(first, entries[2]);
    // EXERCISE reorder 'second' to the end of the list
    entries = acl.getAccessControlEntries();
    assertEquals(third, entries[0]);
    assertEquals(first, entries[1]);
    assertEquals(second, entries[2]);
}
Also used : AccessControlEntry(javax.jcr.security.AccessControlEntry) Privilege(javax.jcr.security.Privilege)

Example 65 with AccessControlEntry

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

the class L2_AccessControlManagerTest method testSetPolicy.

public void testSetPolicy() throws RepositoryException {
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, testRoot);
    assertTrue(acl.addEntry(testPrincipal, AccessControlUtils.privilegesFromNames(acMgr, Privilege.JCR_READ), false));
    // EXERCISE: fix the test.
    assertFalse(acMgr.getApplicablePolicies(testRoot).hasNext());
    AccessControlPolicy[] policies = acMgr.getPolicies(testRoot);
    assertEquals(1, policies.length);
    assertTrue(policies[0] instanceof JackrabbitAccessControlList);
    JackrabbitAccessControlList acl2 = (JackrabbitAccessControlList) policies[0];
    assertFalse(acl2.isEmpty());
    assertEquals(1, acl2.size());
    AccessControlEntry ace = acl2.getAccessControlEntries()[0];
    assertTrue(ace instanceof JackrabbitAccessControlEntry);
    assertEquals(testPrincipal, ace.getPrincipal());
    assertFalse(((JackrabbitAccessControlEntry) ace).isAllow());
}
Also used : AccessControlPolicy(javax.jcr.security.AccessControlPolicy) JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) AccessControlEntry(javax.jcr.security.AccessControlEntry) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList)

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