Search in sources :

Example 86 with AccessControlEntry

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

the class JackrabbitAccessControlListTest method testAddEntry.

public void testAddEntry() throws NotExecutableException, RepositoryException {
    Principal princ = getValidPrincipal();
    Privilege[] priv = privilegesFromName(Privilege.JCR_ALL);
    List<AccessControlEntry> entriesBefore = Arrays.asList(templ.getAccessControlEntries());
    if (templ.addEntry(princ, priv, true, Collections.<String, Value>emptyMap())) {
        AccessControlEntry[] entries = templ.getAccessControlEntries();
        if (entries.length == 0) {
            fail("GrantPrivileges was successful -> at least 1 entry for principal.");
        }
        PrivilegeBits allows = PrivilegeBits.getInstance();
        for (AccessControlEntry en : entries) {
            PrivilegeBits bits = privilegeMgr.getBits(en.getPrivileges());
            if (en instanceof JackrabbitAccessControlEntry && ((JackrabbitAccessControlEntry) en).isAllow()) {
                allows.add(bits);
            }
        }
        assertEquals(privilegeMgr.getBits(priv), allows);
    } else {
        AccessControlEntry[] entries = templ.getAccessControlEntries();
        assertEquals("Grant ALL not successful -> entries must not have changed.", entriesBefore, Arrays.asList(entries));
    }
}
Also used : JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) AccessControlEntry(javax.jcr.security.AccessControlEntry) Privilege(javax.jcr.security.Privilege) Principal(java.security.Principal)

Example 87 with AccessControlEntry

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

the class ACLTemplateTest method testNewEntriesAppendedAtEnd.

/**
     * Test if new entries get appended at the end of the list.
     *
     * @throws RepositoryException
     * @throws NotExecutableException
     */
public void testNewEntriesAppendedAtEnd() throws RepositoryException, NotExecutableException {
    JackrabbitAccessControlList pt = createEmptyTemplate(getTestPath());
    Privilege[] readPriv = privilegesFromName(Privilege.JCR_READ);
    Privilege[] writePriv = privilegesFromName(Privilege.JCR_WRITE);
    pt.addEntry(testPrincipal, readPriv, true, emptyRestrictions);
    pt.addEntry(principalMgr.getEveryone(), readPriv, true, emptyRestrictions);
    pt.addEntry(testPrincipal, writePriv, false, emptyRestrictions);
    AccessControlEntry[] entries = pt.getAccessControlEntries();
    assertEquals(3, entries.length);
    JackrabbitAccessControlEntry last = (JackrabbitAccessControlEntry) entries[2];
    assertEquals(testPrincipal, last.getPrincipal());
    assertEquals(false, last.isAllow());
    assertEquals(writePriv[0], last.getPrivileges()[0]);
}
Also used : JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) 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 88 with AccessControlEntry

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

the class ACLTemplateTest method testUpdateComplementaryEntry.

public void testUpdateComplementaryEntry() throws RepositoryException, NotExecutableException {
    JackrabbitAccessControlList pt = createEmptyTemplate(getTestPath());
    Privilege[] readPriv = privilegesFromName(Privilege.JCR_READ);
    Privilege[] writePriv = privilegesFromName(Privilege.JCR_WRITE);
    Principal principal2 = principalMgr.getEveryone();
    pt.addEntry(testPrincipal, readPriv, true, emptyRestrictions);
    pt.addEntry(principal2, readPriv, true, emptyRestrictions);
    pt.addEntry(testPrincipal, writePriv, false, emptyRestrictions);
    pt.addEntry(principal2, writePriv, true, emptyRestrictions);
    // entry complementary to the first entry
    // -> must remove the allow-READ entry and update the deny-WRITE entry.
    pt.addEntry(testPrincipal, readPriv, false, emptyRestrictions);
    AccessControlEntry[] entries = pt.getAccessControlEntries();
    assertEquals(2, entries.length);
    JackrabbitAccessControlEntry first = (JackrabbitAccessControlEntry) entries[0];
    assertEquals(principal2, first.getPrincipal());
    JackrabbitAccessControlEntry second = (JackrabbitAccessControlEntry) entries[1];
    assertEquals(testPrincipal, second.getPrincipal());
    assertFalse(second.isAllow());
    assertSamePrivileges(new Privilege[] { readPriv[0], writePriv[0] }, second.getPrivileges());
}
Also used : JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) AccessControlEntry(javax.jcr.security.AccessControlEntry) Privilege(javax.jcr.security.Privilege) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) Principal(java.security.Principal)

Example 89 with AccessControlEntry

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

the class JackrabbitAccessControlListTest method testRemoveEntry.

public void testRemoveEntry() throws NotExecutableException, RepositoryException {
    Principal princ = getValidPrincipal();
    Privilege[] grPriv = privilegesFromName(PrivilegeRegistry.REP_WRITE);
    templ.addEntry(princ, grPriv, true, Collections.<String, Value>emptyMap());
    AccessControlEntry[] entries = templ.getAccessControlEntries();
    int length = entries.length;
    assertTrue("Grant was both successful -> at least 1 entry.", length > 0);
    for (AccessControlEntry entry : entries) {
        templ.removeAccessControlEntry(entry);
        length = length - 1;
        assertEquals(length, templ.size());
        assertEquals(length, templ.getAccessControlEntries().length);
    }
    assertTrue(templ.isEmpty());
    assertEquals(0, templ.size());
    assertEquals(0, templ.getAccessControlEntries().length);
}
Also used : JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) AccessControlEntry(javax.jcr.security.AccessControlEntry) Privilege(javax.jcr.security.Privilege) Principal(java.security.Principal)

Example 90 with AccessControlEntry

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

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