PrincipalBasedPermissionProvider implements AggregatedPermissionProvider, Constants { @Override public boolean isGranted(@NotNull Tree tree, @Nullable PropertyState property, long permissions) { Tree readOnly = getReadOnlyTree(tree); TreeType type = typeProvider.getType(readOnly); switch (type) { case HIDDEN: return true; case INTERNAL: return false; case VERSION: if (!isVersionStoreTree(readOnly)) { Tree versionableTree = getVersionableTree(readOnly); if (versionableTree == null) { return false; } readOnly = versionableTree; } break; case ACCESS_CONTROL: if (!isGrantedOnEffective(readOnly, permissions)) { return false; } break; default: break; } return isGranted(readOnly.getPath(), EntryPredicate.create(readOnly, property), EntryPredicate.createParent(readOnly, permissions), permissions); } PrincipalBasedPermissionProvider(@NotNull Root root,
                                     @NotNull String workspaceName,
                                     @NotNull Iterable<String> principalPaths,
                                     @NotNull PrincipalBasedAuthorizationConfiguration authorizationConfiguration); @Override void refresh(); @NotNull @Override Set<String> getPrivileges(@Nullable Tree tree); @Override boolean hasPrivileges(@Nullable Tree tree, @NotNull String... privilegeNames); @Override @NotNull RepositoryPermission getRepositoryPermission(); @Override @NotNull TreePermission getTreePermission(@NotNull Tree tree, @NotNull TreePermission parentPermission); @Override boolean isGranted(@NotNull Tree tree, @Nullable PropertyState property, long permissions); @Override boolean isGranted(@NotNull String oakPath, @NotNull String jcrActions); @Override @NotNull PrivilegeBits supportedPrivileges(@Nullable Tree tree, @Nullable PrivilegeBits privilegeBits); @Override long supportedPermissions(@Nullable Tree tree, @Nullable PropertyState property, long permissions); @Override long supportedPermissions(@NotNull TreeLocation location, long permissions); @Override long supportedPermissions(@NotNull TreePermission treePermission, @Nullable PropertyState property, long permissions); @Override boolean isGranted(@NotNull TreeLocation location, long permissions); @Override @NotNull TreePermission getTreePermission(@NotNull Tree tree, @NotNull TreeType type, @NotNull TreePermission parentPermission);  }
@Test public void testIsGranted() { Tree t = root.getTree(childPath); assertTrue(permissionProvider.isGranted(t, null, Permissions.READ_NODE)); assertTrue(permissionProvider.isGranted(t, t.getProperty(JCR_PRIMARYTYPE), Permissions.READ_PROPERTY)); assertFalse(permissionProvider.isGranted(t, null, Permissions.READ_NODE|Permissions.VERSION_MANAGEMENT)); t = root.getTree(TEST_OAK_PATH); assertTrue(permissionProvider.isGranted(t, null, Permissions.READ_NODE|Permissions.VERSION_MANAGEMENT)); assertTrue(permissionProvider.isGranted(t, t.getProperty(JCR_PRIMARYTYPE), Permissions.READ_PROPERTY|Permissions.VERSION_MANAGEMENT)); }
@Test public void testIsGrantedNonExistingTree() { Tree nonExisting = root.getTree(TEST_OAK_PATH).getChild("nonExisting"); assertTrue(permissionProvider.isGranted(nonExisting, null, Permissions.READ)); assertTrue(permissionProvider.isGranted(nonExisting, PropertyStates.createProperty("propName", "value"), Permissions.READ)); }
@Test public void testIsGrantedWithRestriction() { assertFalse(permissionProvider.isGranted(root.getTree(TEST_OAK_PATH), null, Permissions.REMOVE_NODE)); assertFalse(permissionProvider.isGranted(root.getTree(childPath), null, Permissions.REMOVE_NODE)); assertTrue(permissionProvider.isGranted(root.getTree(TEST_OAK_PATH + "/folder"), null, Permissions.REMOVE_NODE)); assertTrue(permissionProvider.isGranted(root.getTree(childPath + "/folder"), null, Permissions.REMOVE_NODE)); }
@Test public void testIsGrantedTreeLocation() { TreeLocation tl = TreeLocation.create(root, TEST_OAK_PATH); assertFalse(permissionProvider.isGranted(tl, Permissions.READ|Permissions.REMOVE_NODE)); }
@Test public void testIsGrantedNonExistingTreeLocation() { TreeLocation tl = TreeLocation.create(root, childPath + "/nonExisting"); assertTrue(permissionProvider.isGranted(tl, Permissions.READ)); assertFalse(permissionProvider.isGranted(tl, Permissions.REMOVE_NODE)); }
@Test public void testIsGrantedNonExistingParentTreeLocation() { TreeLocation tl = TreeLocation.create(root, childPath + "/nonExistingParent/nonExisting"); assertTrue(permissionProvider.isGranted(tl, Permissions.READ)); assertFalse(permissionProvider.isGranted(tl, Permissions.REMOVE_NODE)); }
@Test public void testIsGrantedAccessControlTreeLocation() throws Exception{ TreeLocation tl = TreeLocation.create(root, PathUtils.concat(getTestSystemUser().getPath(), REP_PRINCIPAL_POLICY)); assertFalse(permissionProvider.isGranted(tl, Permissions.READ)); }