Search in sources :

Example 16 with AccessControlEntry

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

the class EntryTest method testHashCode.

@Test
public void testHashCode() throws RepositoryException {
    JackrabbitAccessControlEntry ace = createEntry(PrivilegeConstants.JCR_ALL);
    Privilege[] declaredAllPrivs = acMgr.privilegeFromName(PrivilegeConstants.JCR_ALL).getDeclaredAggregatePrivileges();
    Privilege[] aggregateAllPrivs = acMgr.privilegeFromName(PrivilegeConstants.JCR_ALL).getAggregatePrivileges();
    List<Privilege> l = Lists.newArrayList(aggregateAllPrivs);
    l.add(l.remove(0));
    Privilege[] reordered = l.toArray(new Privilege[l.size()]);
    Map<AccessControlEntry, AccessControlEntry> equivalent = new HashMap<AccessControlEntry, AccessControlEntry>();
    // create same entry again
    equivalent.put(ace, createEntry(PrivilegeConstants.JCR_ALL));
    // create entry with duplicate privs
    equivalent.put(ace, createEntry(PrivilegeConstants.JCR_ALL, PrivilegeConstants.JCR_ALL));
    // create entry with declared aggregate privileges
    equivalent.put(ace, createEntry(testPrincipal, declaredAllPrivs, true));
    // create entry with aggregate privileges
    equivalent.put(ace, createEntry(testPrincipal, aggregateAllPrivs, true));
    // create entry with different privilege order
    equivalent.put(ace, createEntry(testPrincipal, reordered, true));
    equivalent.put(createEntry(testPrincipal, declaredAllPrivs, true), createEntry(testPrincipal, reordered, true));
    // even if entries are build with aggregated or declared aggregate privileges
    equivalent.put(createEntry(testPrincipal, declaredAllPrivs, true), createEntry(testPrincipal, aggregateAllPrivs, true));
    for (AccessControlEntry entry : equivalent.keySet()) {
        AccessControlEntry eqv = equivalent.get(entry);
        assertEquals(entry.hashCode(), eqv.hashCode());
    }
}
Also used : JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) HashMap(java.util.HashMap) JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) AccessControlEntry(javax.jcr.security.AccessControlEntry) Privilege(javax.jcr.security.Privilege) Test(org.junit.Test)

Example 17 with AccessControlEntry

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

the class EntryTest method testEquals.

@Test
public void testEquals() throws RepositoryException {
    Map<AccessControlEntry, AccessControlEntry> equalAces = new HashMap<AccessControlEntry, AccessControlEntry>();
    ACE ace = createEntry(PrivilegeConstants.JCR_ALL);
    // create same entry again
    equalAces.put(ace, createEntry(PrivilegeConstants.JCR_ALL));
    // create entry with declared aggregate privileges
    Privilege[] declaredAllPrivs = acMgr.privilegeFromName(PrivilegeConstants.JCR_ALL).getDeclaredAggregatePrivileges();
    equalAces.put(ace, createEntry(testPrincipal, declaredAllPrivs, true));
    // create entry with aggregate privileges
    Privilege[] aggregateAllPrivs = acMgr.privilegeFromName(PrivilegeConstants.JCR_ALL).getAggregatePrivileges();
    equalAces.put(ace, createEntry(testPrincipal, aggregateAllPrivs, true));
    // create entry with different privilege order
    List<Privilege> reordered = new ArrayList<Privilege>(Arrays.asList(aggregateAllPrivs));
    reordered.add(reordered.remove(0));
    equalAces.put(createEntry(testPrincipal, reordered.toArray(new Privilege[reordered.size()]), true), createEntry(testPrincipal, aggregateAllPrivs, true));
    // even if entries are build with aggregated or declared aggregate privileges
    equalAces.put(createEntry(testPrincipal, declaredAllPrivs, true), createEntry(testPrincipal, aggregateAllPrivs, true));
    for (AccessControlEntry entry : equalAces.keySet()) {
        assertEquals(entry, equalAces.get(entry));
    }
}
Also used : ACE(org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.ACE) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) AccessControlEntry(javax.jcr.security.AccessControlEntry) Privilege(javax.jcr.security.Privilege) Test(org.junit.Test)

Example 18 with AccessControlEntry

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

the class ACLTemplateTest method testInsertionOrder2.

public void testInsertionOrder2() throws Exception {
    JackrabbitAccessControlList pt = createEmptyTemplate(getTestPath());
    Privilege[] readPriv = privilegesFromName(Privilege.JCR_READ);
    Privilege[] writePriv = privilegesFromName(Privilege.JCR_WRITE);
    Privilege[] addNodePriv = privilegesFromName(Privilege.JCR_ADD_CHILD_NODES);
    String restrName = ((SessionImpl) superuser).getJCRName(ACLTemplate.P_GLOB);
    Map<String, Value> restrictions = Collections.singletonMap(restrName, superuser.getValueFactory().createValue("/.*"));
    pt.addEntry(testPrincipal, readPriv, true, emptyRestrictions);
    pt.addEntry(testPrincipal, addNodePriv, true, restrictions);
    pt.addEntry(testPrincipal, writePriv, false, emptyRestrictions);
    AccessControlEntry[] entries = pt.getAccessControlEntries();
    assertTrue(Arrays.equals(readPriv, entries[0].getPrivileges()));
    assertTrue(Arrays.equals(addNodePriv, entries[1].getPrivileges()));
    assertTrue(Arrays.equals(writePriv, entries[2].getPrivileges()));
}
Also used : Value(javax.jcr.Value) JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) AccessControlEntry(javax.jcr.security.AccessControlEntry) SessionImpl(org.apache.jackrabbit.core.SessionImpl) Privilege(javax.jcr.security.Privilege) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList)

Example 19 with AccessControlEntry

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

the class ACLTemplateTest method testTwoEntriesPerPrincipal.

public void testTwoEntriesPerPrincipal() throws RepositoryException, NotExecutableException {
    JackrabbitAccessControlList pt = createEmptyTemplate(getTestPath());
    Privilege[] readPriv = privilegesFromName(Privilege.JCR_READ);
    Privilege[] writePriv = privilegesFromName(Privilege.JCR_WRITE);
    Privilege[] acReadPriv = privilegesFromName(Privilege.JCR_READ_ACCESS_CONTROL);
    pt.addEntry(testPrincipal, readPriv, true, emptyRestrictions);
    pt.addEntry(testPrincipal, writePriv, true, emptyRestrictions);
    pt.addEntry(testPrincipal, acReadPriv, true, emptyRestrictions);
    pt.addEntry(testPrincipal, readPriv, false, emptyRestrictions);
    pt.addEntry(new PrincipalImpl(testPrincipal.getName()), readPriv, false, emptyRestrictions);
    pt.addEntry(new Principal() {

        public String getName() {
            return testPrincipal.getName();
        }
    }, readPriv, false, emptyRestrictions);
    AccessControlEntry[] entries = pt.getAccessControlEntries();
    assertEquals(2, entries.length);
}
Also used : JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) AccessControlEntry(javax.jcr.security.AccessControlEntry) Privilege(javax.jcr.security.Privilege) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) PrincipalImpl(org.apache.jackrabbit.core.security.principal.PrincipalImpl) Principal(java.security.Principal)

Example 20 with AccessControlEntry

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

the class ACLTemplateTest method testUpdateEntry.

public void testUpdateEntry() 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);
    // adding an entry that should update the existing allow-entry for everyone.
    pt.addEntry(principal2, writePriv, true, emptyRestrictions);
    AccessControlEntry[] entries = pt.getAccessControlEntries();
    assertEquals(3, entries.length);
    JackrabbitAccessControlEntry princ2AllowEntry = (JackrabbitAccessControlEntry) entries[1];
    assertEquals(principal2, princ2AllowEntry.getPrincipal());
    assertTrue(princ2AllowEntry.isAllow());
    assertSamePrivileges(new Privilege[] { readPriv[0], writePriv[0] }, princ2AllowEntry.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)

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