AccessControlManagerImpl extends AbstractAccessControlManager implements PolicyOwner { @NotNull @Override public AccessControlPolicy[] getPolicies(@Nullable String absPath) throws RepositoryException { String oakPath = getOakPath(absPath); Tree tree = getTree(oakPath, Permissions.READ_ACCESS_CONTROL, true); AccessControlPolicy policy = createACL(oakPath, tree, false, Predicates.alwaysTrue()); List<AccessControlPolicy> policies = new ArrayList<>(2); if (policy != null) { policies.add(policy); } if (readPaths.contains(oakPath)) { policies.add(ReadPolicy.INSTANCE); } return policies.toArray(new AccessControlPolicy[0]); } AccessControlManagerImpl(@NotNull Root root, @NotNull NamePathMapper namePathMapper,
                                    @NotNull SecurityProvider securityProvider); @NotNull @Override AccessControlPolicy[] getPolicies(@Nullable String absPath); @NotNull @Override AccessControlPolicy[] getEffectivePolicies(@Nullable String absPath); @NotNull @Override AccessControlPolicyIterator getApplicablePolicies(@Nullable String absPath); @Override void setPolicy(@Nullable String absPath, @NotNull AccessControlPolicy policy); @Override void removePolicy(@Nullable String absPath, @NotNull AccessControlPolicy policy); @NotNull @Override JackrabbitAccessControlPolicy[] getApplicablePolicies(@NotNull Principal principal); @NotNull @Override JackrabbitAccessControlPolicy[] getPolicies(@NotNull Principal principal); @NotNull @Override AccessControlPolicy[] getEffectivePolicies(@NotNull Set<Principal> principals); @Override boolean defines(String absPath, @NotNull AccessControlPolicy accessControlPolicy);  }
@Test public void testGetApplicablePoliciesInvalidPath() { for (String invalid : getInvalidPaths()) { try { acMgr.getPolicies(invalid); fail("Getting applicable policies for an invalid path should fail"); } catch (RepositoryException e) { } } }
@Test public void testGetPolicies() throws Exception { AccessControlPolicy policy = TestUtility.getApplicablePolicy(acMgr, testPath); acMgr.setPolicy(testPath, policy); AccessControlPolicy[] policies = acMgr.getPolicies(testPath); assertPolicies(policies, 1); assertTrue(policies[0] instanceof ACL); ACL acl = (ACL) policies[0]; assertTrue(acl.isEmpty()); assertEquals(testPath, acl.getOakPath()); }
@Test public void testGetPoliciesNodeNotAccessControlled() throws Exception { AccessControlPolicy[] policies = acMgr.getPolicies(testPath); assertPolicies(policies, 0); }
@Test public void testGetPoliciesAfterSet() throws Exception { setupPolicy(testPath); AccessControlPolicy[] policies = acMgr.getPolicies(testPath); assertPolicies(policies, 1); assertTrue(policies[0] instanceof ACL); ACL acl = (ACL) policies[0]; assertFalse(acl.isEmpty()); }
@Test public void testGetPoliciesInvalidPath() { for (String invalid : getInvalidPaths()) { try { acMgr.getPolicies(invalid); fail("Getting policies for an invalid path should fail"); } catch (RepositoryException e) { } } }
@Test(expected = PathNotFoundException.class) public void testGetPoliciesPropertyPath() throws Exception { String propertyPath = "/jcr:primaryType"; acMgr.getPolicies(propertyPath); }
@Test(expected = PathNotFoundException.class) public void testGetPoliciesNonExistingNodePath() throws Exception { String nonExistingPath = "/not/existing"; acMgr.getPolicies(nonExistingPath); }
@Test public void testGetPoliciesAcContentPaths() throws Exception { for (String path : getAcContentPaths()) { try { acMgr.getPolicies(path); fail("Getting policies for access control content should fail."); } catch (AccessControlException e) { } } }
@Test public void testGetPoliciesWithNonAceChild() throws Exception { ACL policy = setupPolicy(testPath, testPrivileges); assertEquals(1, policy.size()); Tree policyTree = root.getTree(testPath).getChild(REP_POLICY); TreeUtil.addChild(policyTree, "child", NT_OAK_UNSTRUCTURED); AccessControlPolicy[] policies = acMgr.getPolicies(testPath); assertPolicies(policies, 1); assertEquals(1, ((ACL) policies[0]).size()); }
@Test public void testGetPoliciesWithInvalidatedPrivileges() throws Exception { ACL policy = setupPolicy(testPath, privilegesFromNames(JCR_LOCK_MANAGEMENT)); assertEquals(1, policy.size()); Tree privTree = root.getTree(PrivilegeConstants.PRIVILEGES_PATH).getChild(JCR_LOCK_MANAGEMENT); privTree.remove(); AccessControlPolicy[] policies = acMgr.getPolicies(testPath); assertPolicies(policies, 1); ACL acl = (ACL) policies[0]; assertEquals(1, acl.size()); Privilege[] privs = acl.getAccessControlEntries()[0].getPrivileges(); assertArrayEquals(new Privilege[0], privs); }
@Test(expected = AccessControlException.class) public void testGetPoliciesNullPrincipal() throws Exception { acMgr.getPolicies((Principal) null); }
@Test public void testGetPoliciesByPrincipal() throws Exception { List<Principal> principals = ImmutableList.of(testPrincipal, EveryonePrincipal.getInstance()); for (Principal principal : principals) { assertPolicies(acMgr.getPolicies(principal), 0); } }
@Test public void testGetPoliciesByPrincipal2() throws Exception { setupPolicy(testPath); assertPolicies(acMgr.getPolicies(testPrincipal), 0); root.commit(); assertPolicies(acMgr.getPolicies(testPrincipal), 1); }
@Test public void testGetPoliciesByPrincipalRemapped() throws Exception { setupPolicy(testPath); root.commit(); NamePathMapper mapper = getNamePathMapperWithLocalRemapping(); AccessControlPolicy[] policies = createAccessControlManager(root, mapper).getPolicies(testPrincipal); assertNotNull(policies); assertEquals(1, policies.length); List<ACE> entries = ((ACL) policies[0]).getEntries(); Value rest = entries.get(0).getRestriction(REP_NODE_PATH); assertNotNull(rest); assertEquals(mapper.getJcrPath(testPath), rest.getString()); }
@Test public void testGetPoliciesByPrincipalRepositoryLevel() throws Exception { setupPolicy(null, privilegesFromNames(PrivilegeConstants.JCR_NODE_TYPE_DEFINITION_MANAGEMENT)); AccessControlPolicy[] policies = acMgr.getPolicies(testPrincipal); assertNotNull(policies); assertEquals(0, policies.length); root.commit(); policies = acMgr.getPolicies(testPrincipal); assertNotNull(policies); assertEquals(1, policies.length); JackrabbitAccessControlList acl = (JackrabbitAccessControlList) policies[0]; AccessControlEntry[] entries = acl.getAccessControlEntries(); assertEquals(1, entries.length); JackrabbitAccessControlEntry entry = (JackrabbitAccessControlEntry) entries[0]; assertTrue(entry.getRestriction(REP_NODE_PATH).getString().isEmpty()); }