PermissionStoreImpl implements PermissionStore, PermissionConstants { @Nullable @Override public Collection<PermissionEntry> load(@NotNull String principalName, @NotNull String path) { Tree principalRoot = getPrincipalRoot(principalName); Collection<PermissionEntry> entries = null; if (principalRoot != null) { String name = PermissionUtil.getEntryName(path); if (principalRoot.hasChild(name)) { Tree child = principalRoot.getChild(name); if (PermissionUtil.checkACLPath(child, path)) { entries = loadPermissionEntries(path, child); } else { for (Tree node : child.getChildren()) { if (PermissionUtil.checkACLPath(node, path)) { entries = loadPermissionEntries(path, node); break; } } } } } return entries; } PermissionStoreImpl(@NotNull Root root, @NotNull String permissionRootName, @NotNull RestrictionProvider restrictionProvider); @Override void flush(@NotNull Root root); @Nullable @Override Collection<PermissionEntry> load(@NotNull String principalName, @NotNull String path); @NotNull @Override NumEntries getNumEntries(@NotNull String principalName, long max); @Override @NotNull PrincipalPermissionEntries load(@NotNull String principalName);  }
@Test public void testLoad() { PrincipalPermissionEntries entries = permissionStore.load(EveryonePrincipal.NAME); assertNotNull(entries); assertTrue(entries.isFullyLoaded()); assertEquals(2, entries.getSize()); }
@Test public void testLoadMissingPrincipalRoot() { PrincipalPermissionEntries entries = permissionStore.load(testPrincipal.getName()); assertNotNull(entries); assertTrue(entries.isFullyLoaded()); assertEquals(0, entries.getSize()); }
@Test public void testLoadWithNesting() throws Exception { try { Tree everyoneTree = getPermissionRoot(EveryonePrincipal.NAME); everyoneTree.removeProperty(REP_NUM_PERMISSIONS); for (Tree child : everyoneTree.getChildren()) { if (child.hasProperty(REP_ACCESS_CONTROLLED_PATH)) { Tree collision = TreeUtil.addChild(child, "c_"+child.getName(), NT_REP_PERMISSION_STORE); collision.setProperty(REP_ACCESS_CONTROLLED_PATH, "/another/path"); Tree entry = TreeUtil.addChild(collision, "1", NT_REP_PERMISSIONS); entry.setProperty(PrivilegeBits.BUILT_IN.get(REP_READ_NODES).asPropertyState(REP_PRIVILEGE_BITS)); entry.setProperty(REP_IS_ALLOW, false); break; } } PrincipalPermissionEntries entries = permissionStore.load(EveryonePrincipal.NAME); assertNotNull(entries); assertTrue(entries.isFullyLoaded()); assertEquals(3, entries.getSize()); } finally { root.refresh(); } }
@Test public void testLoadWithNestingMissingAccessControlledPath() throws Exception { try { Tree everyoneTree = getPermissionRoot(EveryonePrincipal.NAME); everyoneTree.removeProperty(REP_NUM_PERMISSIONS); for (Tree child : everyoneTree.getChildren()) { if (child.hasProperty(REP_ACCESS_CONTROLLED_PATH)) { Tree collision = TreeUtil.addChild(child, "c_"+child.getName(), NT_REP_PERMISSION_STORE); Tree entry = TreeUtil.addChild(collision, "1", NT_REP_PERMISSIONS); entry.setProperty(PrivilegeBits.BUILT_IN.get(REP_READ_NODES).asPropertyState(REP_PRIVILEGE_BITS)); entry.setProperty(REP_IS_ALLOW, false); break; } } PrincipalPermissionEntries entries = permissionStore.load(EveryonePrincipal.NAME); assertNotNull(entries); assertTrue(entries.isFullyLoaded()); assertEquals(2, entries.getSize()); } finally { root.refresh(); } }
@Test public void testLoadByPath() { Collection<PermissionEntry> entries = permissionStore.load(EveryonePrincipal.NAME, testPath); assertNotNull(entries); assertFalse(entries.isEmpty()); }
@Test public void testLoadByPathWithoutEntries() { assertNull(permissionStore.load(EveryonePrincipal.NAME, testPath + "/notAccessControlled")); }
@Test public void testLoadByPathMissingPrincipalRoot() { assertNull(permissionStore.load(testPrincipal.getName(), testPath)); }
@Test public void testLoadByPathWithCollision() throws Exception { try { Tree everyoneTree = getPermissionRoot(EveryonePrincipal.NAME); Tree aa = TreeUtil.addChild(everyoneTree, "/Aa".hashCode() +"", NT_REP_PERMISSION_STORE); aa.setProperty(REP_ACCESS_CONTROLLED_PATH, "/Aa"); Tree entry = TreeUtil.addChild(aa, "1", NT_REP_PERMISSIONS); entry.setProperty(PrivilegeBits.BUILT_IN.get(REP_READ_NODES).asPropertyState(REP_PRIVILEGE_BITS)); entry.setProperty(REP_IS_ALLOW, false); Tree collision = TreeUtil.addChild(aa, "c_"+"/BB".hashCode(), NT_REP_PERMISSION_STORE); collision.setProperty(REP_ACCESS_CONTROLLED_PATH, "/BB"); Tree entryBB = TreeUtil.addChild(collision, "1", NT_REP_PERMISSIONS); entryBB.setProperty(PrivilegeBits.BUILT_IN.get(REP_READ_NODES).asPropertyState(REP_PRIVILEGE_BITS)); entryBB.setProperty(REP_IS_ALLOW, true); Collection<PermissionEntry> entries = permissionStore.load(EveryonePrincipal.NAME, "/BB"); assertNotNull(entries); assertEquals(1, entries.size()); assertTrue(entries.iterator().next().isAllow); entries = permissionStore.load(EveryonePrincipal.NAME, "/Aa"); assertNotNull(entries); assertFalse(entries.iterator().next().isAllow); } finally { root.refresh(); } }
@Test public void testLoadByPathWithCollisionMissingAccessControlledProperty() throws Exception { try { Tree everyoneTree = getPermissionRoot(EveryonePrincipal.NAME); Tree aa = TreeUtil.addChild(everyoneTree, "/Aa".hashCode() +"", NT_REP_PERMISSION_STORE); aa.setProperty(REP_ACCESS_CONTROLLED_PATH, "/Aa"); Tree collision = TreeUtil.addChild(aa, "c_"+"/BB".hashCode(), NT_REP_PERMISSION_STORE); Tree entry = TreeUtil.addChild(collision, "1", NT_REP_PERMISSIONS); entry.setProperty(PrivilegeBits.BUILT_IN.get(REP_READ_NODES).asPropertyState(REP_PRIVILEGE_BITS)); entry.setProperty(REP_IS_ALLOW, false); Collection<PermissionEntry> entries = permissionStore.load(EveryonePrincipal.NAME, "/BB"); assertNull(entries); } finally { root.refresh(); } }