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