use of javax.jcr.security.AccessControlEntry in project jackrabbit-oak by apache.
the class AccessControlImporterTest method testImportPolicyExists.
/**
* Imports a resource-based ACL containing a single entry for a policy that
* already exists: expected outcome its that the existing ACE is replaced.
*/
public void testImportPolicyExists() throws Exception {
try {
Node target = createImportTargetWithPolicy(EveryonePrincipal.getInstance());
doImport(target.getPath(), XML_POLICY_TREE_2);
AccessControlManager acMgr = superuser.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(EveryonePrincipal.getInstance(), entry.getPrincipal());
List<Privilege> privs = Arrays.asList(entry.getPrivileges());
assertEquals(1, privs.size());
assertEquals(acMgr.privilegeFromName(Privilege.JCR_WRITE), entry.getPrivileges()[0]);
if (entry instanceof JackrabbitAccessControlEntry) {
assertTrue(((JackrabbitAccessControlEntry) entry).isAllow());
}
} finally {
superuser.refresh(false);
}
}
use of javax.jcr.security.AccessControlEntry in project jackrabbit-oak by apache.
the class AccessControlImporterTest method testImportEmptyExistingPolicy.
/**
* Imports an empty resource-based ACL for a policy that already exists.
*
* @throws Exception
*/
public void testImportEmptyExistingPolicy() throws Exception {
try {
Node target = createImportTargetWithPolicy(null);
doImport(target.getPath(), XML_POLICY_ONLY);
AccessControlPolicy[] policies = superuser.getAccessControlManager().getPolicies(target.getPath());
assertEquals(1, policies.length);
assertTrue(policies[0] instanceof JackrabbitAccessControlList);
AccessControlEntry[] entries = ((JackrabbitAccessControlList) policies[0]).getAccessControlEntries();
assertEquals(0, entries.length);
} finally {
superuser.refresh(false);
}
}
use of javax.jcr.security.AccessControlEntry in project jackrabbit-oak by apache.
the class L9_RemoveAuthorizableTest method testAccessControlEntry.
public void testAccessControlEntry() throws RepositoryException, NotExecutableException {
// remove test user
removeTestUser();
boolean found = false;
AccessControlList acl = AccessControlUtils.getAccessControlList(superuser, testRoot);
if (acl != null) {
for (AccessControlEntry ace : acl.getAccessControlEntries()) {
if (testUser.getPrincipal().getName().equals(ace.getPrincipal().getName())) {
found = true;
}
}
}
// EXERCISE: do you expect the ACE for test-principal to be still present? explain why and fix the test if necessary.
assertTrue(found);
}
use of javax.jcr.security.AccessControlEntry in project jackrabbit-oak by apache.
the class L3_AccessControlListTest method testReorderEntries.
public void testReorderEntries() throws Exception {
Privilege[] read = AccessControlUtils.privilegesFromNames(acMgr, Privilege.JCR_READ, Privilege.JCR_READ_ACCESS_CONTROL);
Privilege[] write = AccessControlUtils.privilegesFromNames(acMgr, Privilege.JCR_WRITE);
acl.addAccessControlEntry(testPrincipal, read);
acl.addEntry(testPrincipal, write, false);
acl.addAccessControlEntry(EveryonePrincipal.getInstance(), write);
AccessControlEntry[] entries = acl.getAccessControlEntries();
assertEquals(3, entries.length);
AccessControlEntry first = entries[0];
AccessControlEntry second = entries[1];
AccessControlEntry third = entries[2];
// EXERCISE: reorder 'second' to the first position
entries = acl.getAccessControlEntries();
assertEquals(second, entries[0]);
assertEquals(first, entries[1]);
assertEquals(third, entries[2]);
// EXERCISE reorder 'third' before 'first'
entries = acl.getAccessControlEntries();
assertEquals(second, entries[0]);
assertEquals(third, entries[1]);
assertEquals(first, entries[2]);
// EXERCISE reorder 'second' to the end of the list
entries = acl.getAccessControlEntries();
assertEquals(third, entries[0]);
assertEquals(first, entries[1]);
assertEquals(second, entries[2]);
}
use of javax.jcr.security.AccessControlEntry in project jackrabbit-oak by apache.
the class L2_AccessControlManagerTest method testSetPolicy.
public void testSetPolicy() throws RepositoryException {
JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, testRoot);
assertTrue(acl.addEntry(testPrincipal, AccessControlUtils.privilegesFromNames(acMgr, Privilege.JCR_READ), false));
// EXERCISE: fix the test.
assertFalse(acMgr.getApplicablePolicies(testRoot).hasNext());
AccessControlPolicy[] policies = acMgr.getPolicies(testRoot);
assertEquals(1, policies.length);
assertTrue(policies[0] instanceof JackrabbitAccessControlList);
JackrabbitAccessControlList acl2 = (JackrabbitAccessControlList) policies[0];
assertFalse(acl2.isEmpty());
assertEquals(1, acl2.size());
AccessControlEntry ace = acl2.getAccessControlEntries()[0];
assertTrue(ace instanceof JackrabbitAccessControlEntry);
assertEquals(testPrincipal, ace.getPrincipal());
assertFalse(((JackrabbitAccessControlEntry) ace).isAllow());
}
Aggregations