use of javax.jcr.security.Privilege in project jackrabbit-oak by apache.
the class ReadTest method testGlobRestriction2.
@Test
public void testGlobRestriction2() throws Exception {
Group group2 = getUserManager(superuser).createGroup(generateId("group2_"));
Group group3 = getUserManager(superuser).createGroup(generateId("group3_"));
superuser.save();
try {
Privilege[] readPrivs = privilegesFromName(Privilege.JCR_READ);
modify(path, getTestGroup().getPrincipal(), readPrivs, true, createGlobRestriction("/*"));
allow(path, group2.getPrincipal(), readPrivs);
deny(path, group3.getPrincipal(), readPrivs);
Set<Principal> principals = new HashSet<Principal>();
principals.add(getTestGroup().getPrincipal());
principals.add(group2.getPrincipal());
principals.add(group3.getPrincipal());
assertFalse(((JackrabbitAccessControlManager) acMgr).hasPrivileges(path, principals, readPrivs));
assertFalse(((JackrabbitAccessControlManager) acMgr).hasPrivileges(childNPath, principals, readPrivs));
} finally {
group2.remove();
group3.remove();
superuser.save();
}
}
use of javax.jcr.security.Privilege in project jackrabbit-oak by apache.
the class InheritanceTest method testReorderGroupPermissions.
@Test
public void testReorderGroupPermissions() throws Exception {
/* add privileges for the Group the test-user is member of */
deny(path, testGroup.getPrincipal(), modPropPrivileges);
allow(path, group2.getPrincipal(), modPropPrivileges);
/*
testuser must get the permissions/privileges inherited from
the group it is member of.
granting permissions for group2 must be effective
*/
String actions = getActions(Session.ACTION_SET_PROPERTY, Session.ACTION_READ);
assertTrue(testSession.hasPermission(path, actions));
Privilege[] privs = privilegesFromName(Privilege.JCR_MODIFY_PROPERTIES);
assertTrue(testAcMgr.hasPrivileges(path, privs));
// reorder the ACEs
AccessControlEntry srcEntry = null;
AccessControlEntry destEntry = null;
JackrabbitAccessControlList acl = (JackrabbitAccessControlList) acMgr.getPolicies(path)[0];
for (AccessControlEntry entry : acl.getAccessControlEntries()) {
Principal princ = entry.getPrincipal();
if (testGroup.getPrincipal().equals(princ)) {
destEntry = entry;
} else if (group2.getPrincipal().equals(princ)) {
srcEntry = entry;
}
}
acl.orderBefore(srcEntry, destEntry);
acMgr.setPolicy(path, acl);
superuser.save();
testSession.refresh(false);
/* after reordering the permissions must be denied */
assertFalse(testSession.hasPermission(path, actions));
assertFalse(testAcMgr.hasPrivileges(path, privs));
}
use of javax.jcr.security.Privilege 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.Privilege in project jackrabbit-oak by apache.
the class ACLTest method testMultiplePrincipals.
@Test
public void testMultiplePrincipals() throws Exception {
Principal everyone = principalManager.getEveryone();
Privilege[] privs = privilegesFromNames(JCR_READ);
acl.addAccessControlEntry(testPrincipal, privs);
assertFalse(acl.addAccessControlEntry(testPrincipal, privs));
// add same privileges for another principal -> must modify as well.
assertTrue(acl.addAccessControlEntry(everyone, privs));
// .. 2 entries must be present.
assertTrue(acl.getAccessControlEntries().length == 2);
assertEquals(everyone, acl.getAccessControlEntries()[1].getPrincipal());
}
use of javax.jcr.security.Privilege in project jackrabbit-oak by apache.
the class ACLTest method testNewEntriesAppendedAtEnd.
@Test
public void testNewEntriesAppendedAtEnd() throws Exception {
Privilege[] readPriv = privilegesFromNames(JCR_READ);
Privilege[] writePriv = privilegesFromNames(JCR_WRITE);
acl.addEntry(testPrincipal, readPriv, true);
acl.addEntry(principalManager.getEveryone(), readPriv, true);
acl.addEntry(testPrincipal, writePriv, false);
AccessControlEntry[] entries = acl.getAccessControlEntries();
assertEquals(3, entries.length);
JackrabbitAccessControlEntry last = (JackrabbitAccessControlEntry) entries[2];
assertEquals(testPrincipal, last.getPrincipal());
assertACE(last, false, writePriv);
}
Aggregations