use of javax.jcr.security.AccessControlPolicy in project jackrabbit-oak by apache.
the class AccessControlManagerImplTest method testSetPrincipalPolicy.
//-----------------------------------------------< setPrincipalPolicy() >---
@Test
public void testSetPrincipalPolicy() throws Exception {
JackrabbitAccessControlPolicy[] applicable = acMgr.getApplicablePolicies(testPrincipal);
assertNotNull(applicable);
assertEquals(1, applicable.length);
assertTrue(applicable[0] instanceof ACL);
ACL acl = (ACL) applicable[0];
Value pathValue = getValueFactory().createValue(testPath, PropertyType.PATH);
assertTrue(acl.addEntry(testPrincipal, testPrivileges, true, Collections.singletonMap(REP_NODE_PATH, pathValue)));
acMgr.setPolicy(acl.getPath(), acl);
root.commit();
Root root2 = adminSession.getLatestRoot();
AccessControlPolicy[] policies = getAccessControlManager(root2).getPolicies(testPath);
assertEquals(1, policies.length);
assertEquals(1, ((ACL) policies[0]).getAccessControlEntries().length);
policies = getAccessControlManager(root2).getPolicies(testPrincipal);
assertEquals(1, policies.length);
assertArrayEquals(acl.getAccessControlEntries(), ((ACL) policies[0]).getAccessControlEntries());
}
use of javax.jcr.security.AccessControlPolicy in project jackrabbit-oak by apache.
the class AccessControlManagerImplTest method testRemovePolicyAcContent.
@Test
public void testRemovePolicyAcContent() throws Exception {
for (String acPath : getAcContentPaths()) {
try {
AccessControlPolicy acl = createPolicy(acPath);
acMgr.removePolicy(acPath, acl);
fail("Removing access control policy to access control content should fail");
} catch (AccessControlException e) {
// success
}
}
}
use of javax.jcr.security.AccessControlPolicy in project jackrabbit-oak by apache.
the class AccessControlManagerImplTest method testGetEffectivePoliciesByPrincipal.
@Test
public void testGetEffectivePoliciesByPrincipal() throws Exception {
// no ACLs containing entries for the specified principals
// -> no effective policies expected
Set<Set<Principal>> principalSets = new HashSet<Set<Principal>>();
principalSets.add(Collections.singleton(testPrincipal));
principalSets.add(Collections.<Principal>singleton(EveryonePrincipal.getInstance()));
principalSets.add(ImmutableSet.of(testPrincipal, EveryonePrincipal.getInstance()));
for (Set<Principal> principals : principalSets) {
AccessControlPolicy[] policies = acMgr.getEffectivePolicies(principals);
assertNotNull(policies);
assertEquals(0, policies.length);
}
setupPolicy(testPath);
// changes not yet persisted -> no effecitve policies found for testprincipal
for (Set<Principal> principals : principalSets) {
AccessControlPolicy[] policies = acMgr.getEffectivePolicies(principals);
assertNotNull(policies);
assertEquals(0, policies.length);
}
root.commit();
// after persisting changes -> the policy must be found
for (Set<Principal> principals : principalSets) {
AccessControlPolicy[] policies = acMgr.getEffectivePolicies(principals);
assertNotNull(policies);
if (principals.contains(testPrincipal)) {
assertEquals(1, policies.length);
} else {
assertEquals(0, policies.length);
}
}
NodeUtil child = new NodeUtil(root.getTree(testPath)).addChild("child", JcrConstants.NT_UNSTRUCTURED);
String childPath = child.getTree().getPath();
setupPolicy(childPath);
// changes not yet persisted -> no effecitve policies found for testprincipal
for (Set<Principal> principals : principalSets) {
AccessControlPolicy[] policies = acMgr.getEffectivePolicies(principals);
assertNotNull(policies);
if (principals.contains(testPrincipal)) {
assertEquals(1, policies.length);
} else {
assertEquals(0, policies.length);
}
}
root.commit();
// after persisting changes -> the policy must be found
for (Set<Principal> principals : principalSets) {
AccessControlPolicy[] policies = acMgr.getEffectivePolicies(principals);
assertNotNull(policies);
if (principals.contains(testPrincipal)) {
assertEquals(2, policies.length);
} else {
assertEquals(0, policies.length);
}
}
}
use of javax.jcr.security.AccessControlPolicy in project jackrabbit-oak by apache.
the class AccessControlManagerImplTest method testSetPolicyInvalidPath.
@Test
public void testSetPolicyInvalidPath() throws Exception {
for (String invalid : getInvalidPaths()) {
try {
AccessControlPolicy acl = createPolicy(invalid);
acMgr.setPolicy(invalid, acl);
fail("Setting access control policy with invalid path should fail");
} catch (RepositoryException e) {
// success
}
}
}
use of javax.jcr.security.AccessControlPolicy in project jackrabbit-oak by apache.
the class AccessControlManagerImplTest method testTestSessionGetPolicies.
@Test
public void testTestSessionGetPolicies() throws Exception {
setupPolicy(testPath);
root.commit();
Root testRoot = getTestRoot();
testRoot.refresh();
JackrabbitAccessControlManager testAcMgr = getTestAccessControlManager();
PrincipalManager testPrincipalMgr = getPrincipalManager(testRoot);
List<Principal> principals = ImmutableList.of(testPrincipal, EveryonePrincipal.getInstance());
for (Principal principal : principals) {
if (testPrincipalMgr.hasPrincipal(principal.getName())) {
// testRoot can't read access control content -> doesn't see
// the existing policies and creates a new applicable policy.
AccessControlPolicy[] policies = testAcMgr.getPolicies(principal);
assertNotNull(policies);
assertEquals(0, policies.length);
} else {
// testRoot can't read principal -> no policies for that principal
assertEquals(0, testAcMgr.getPolicies(principal).length);
}
}
}
Aggregations