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());
}
}
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));
}
}
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()));
}
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);
}
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());
}
Aggregations