use of javax.jcr.security.AccessControlEntry in project jackrabbit-oak by apache.
the class JackrabbitAccessControlListTest method testRemoveEntry.
@Test
public void testRemoveEntry() throws NotExecutableException, RepositoryException {
Principal princ = getValidPrincipal();
Privilege[] grPriv = privilegesFromName("rep:write");
acl.addEntry(princ, grPriv, true, Collections.<String, Value>emptyMap());
AccessControlEntry[] entries = acl.getAccessControlEntries();
int length = entries.length;
assertTrue("Grant was both successful -> at least 1 entry.", length > 0);
for (AccessControlEntry entry : entries) {
acl.removeAccessControlEntry(entry);
length = length - 1;
assertEquals(length, acl.size());
assertEquals(length, acl.getAccessControlEntries().length);
}
assertTrue(acl.isEmpty());
assertEquals(0, acl.size());
assertEquals(0, acl.getAccessControlEntries().length);
}
use of javax.jcr.security.AccessControlEntry in project jackrabbit-oak by apache.
the class JackrabbitAccessControlListTest method testAddEntry.
@Test
public void testAddEntry() throws NotExecutableException, RepositoryException {
List<AccessControlEntry> entriesBefore = Arrays.asList(acl.getAccessControlEntries());
if (acl.addEntry(testPrincipal, testPrivileges, true, Collections.<String, Value>emptyMap())) {
AccessControlEntry[] entries = acl.getAccessControlEntries();
AccessControlEntry ace = null;
for (AccessControlEntry entry : entries) {
if (testPrincipal.equals(entry.getPrincipal())) {
ace = entry;
}
}
assertNotNull("addEntry was successful -> expected entry for tesPrincipal.", ace);
assertTrue("addEntry was successful -> at least 1 entry.", entries.length > 0);
} else {
AccessControlEntry[] entries = acl.getAccessControlEntries();
assertEquals("Grant ALL not successful -> entries must not have changed.", entriesBefore, Arrays.asList(entries));
}
}
use of javax.jcr.security.AccessControlEntry in project jackrabbit-oak by apache.
the class ReadVersionContentTest method tearDown.
@Override
@After
protected void tearDown() throws Exception {
JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(superuser, VersionConstants.VERSION_STORE_PATH);
if (acl != null) {
for (AccessControlEntry entry : acl.getAccessControlEntries()) {
if (entry.getPrincipal().equals(testUser.getPrincipal())) {
acl.removeAccessControlEntry(entry);
}
}
acMgr.setPolicy(VersionConstants.VERSION_STORE_PATH, acl);
superuser.save();
}
}
use of javax.jcr.security.AccessControlEntry in project jackrabbit-oak by apache.
the class ImportBesteffortTest method testImportUnknownPrincipal.
@Test
public void testImportUnknownPrincipal() throws Exception {
runImport();
AccessControlManager acMgr = adminSession.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("unknownprincipal", entry.getPrincipal().getName());
assertEquals(1, entry.getPrivileges().length);
assertEquals(acMgr.privilegeFromName(Privilege.JCR_WRITE), entry.getPrivileges()[0]);
if (entry instanceof JackrabbitAccessControlEntry) {
assertTrue(((JackrabbitAccessControlEntry) entry).isAllow());
}
}
use of javax.jcr.security.AccessControlEntry in project jackrabbit-oak by apache.
the class RandomizedReadTest method clearContent.
@Override
protected void clearContent() throws Exception {
for (JackrabbitSession session : writeSessions) {
Node root = session.getRootNode();
if (root.hasNode("n1")) {
root.getNode("n1").remove();
}
if (root.hasNode("n2")) {
root.getNode("n2").remove();
}
AccessControlList acl = AccessControlUtils.getAccessControlList(session, "/");
if (acl != null) {
boolean modified = false;
for (AccessControlEntry ace : acl.getAccessControlEntries()) {
if (getTestPrincipal(session).equals(ace.getPrincipal())) {
acl.removeAccessControlEntry(ace);
modified = true;
}
}
if (modified) {
session.getAccessControlManager().setPolicy("/", acl);
}
}
session.save();
}
}
Aggregations