CugPermissionProvider implements AggregatedPermissionProvider, CugConstants { @Override public long supportedPermissions(@Nullable Tree tree, @Nullable PropertyState property, long permissions) { if (tree == null) { return Permissions.NO_PERMISSION; } long supported = permissions & Permissions.READ; if (supported != Permissions.NO_PERMISSION && includesCug(tree)) { return supported; } else { return Permissions.NO_PERMISSION; } } CugPermissionProvider(@NotNull Root root,
                          @NotNull String workspaceName,
                          @NotNull Set<Principal> principals,
                          @NotNull Set<String> supportedPaths,
                          @NotNull Context ctx,
                          @NotNull RootProvider rootProvider,
                          @NotNull TreeProvider treeProvider); @Override void refresh(); @NotNull @Override Set<String> getPrivileges(@Nullable Tree tree); @Override boolean hasPrivileges(@Nullable Tree tree, @NotNull String... privilegeNames); @NotNull @Override RepositoryPermission getRepositoryPermission(); @NotNull @Override TreePermission getTreePermission(@NotNull Tree tree, @NotNull TreePermission parentPermission); @Override boolean isGranted(@NotNull Tree tree, PropertyState property, long permissions); @Override boolean isGranted(@NotNull String oakPath, @NotNull String jcrActions); @NotNull @Override 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); @NotNull TreePermission getTreePermission(@NotNull Tree immutableTree, @NotNull TreeType type, @NotNull TreePermission parentPermission);  }
@Test public void testSupportedPermissionsByTree() { for (String path : PATH_INCUG_MAP.keySet()) { boolean isInCug = PATH_INCUG_MAP.get(path); Tree tree = root.getTree(path); if (isInCug) { assertEquals(Permissions.READ, cugPermProvider.supportedPermissions(tree, null, Permissions.READ)); assertEquals(Permissions.READ_NODE, cugPermProvider.supportedPermissions(tree, null, Permissions.READ_NODE)); assertEquals(Permissions.READ_PROPERTY, cugPermProvider.supportedPermissions(tree, null, Permissions.READ_PROPERTY)); assertEquals(Permissions.READ, cugPermProvider.supportedPermissions(tree, null, Permissions.ALL)); assertEquals(Permissions.READ_NODE, cugPermProvider.supportedPermissions(tree, null, Permissions.READ_NODE | Permissions.READ_ACCESS_CONTROL)); } else { assertEquals(Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(tree, null, Permissions.READ)); assertEquals(Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(tree, null, Permissions.READ_NODE)); assertEquals(Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(tree, null, Permissions.READ_PROPERTY)); assertEquals(Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(tree, null, Permissions.ALL)); assertEquals(Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(tree, null, Permissions.READ_NODE | Permissions.READ_ACCESS_CONTROL)); } assertEquals(Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(tree, null, Permissions.WRITE)); assertEquals(Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(tree, null, Permissions.ADD_NODE | Permissions.REMOVE)); assertEquals(Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(tree, null, Permissions.READ_ACCESS_CONTROL)); } }
@Test public void testSupportedPermissionsByNullTree() { assertEquals(Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions((Tree) null, null, Permissions.READ)); assertEquals(Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions((Tree) null, null, Permissions.READ_NODE)); assertEquals(Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions((Tree) null, null, Permissions.READ_PROPERTY)); assertEquals(Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions((Tree) null, null, Permissions.ALL)); assertEquals(Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions((Tree) null, null, Permissions.READ_NODE | Permissions.READ_ACCESS_CONTROL)); assertEquals(Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions((Tree) null, null, Permissions.WRITE)); assertEquals(Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions((Tree) null, null, Permissions.ADD_NODE | Permissions.REMOVE)); assertEquals(Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions((Tree) null, null, Permissions.READ_ACCESS_CONTROL)); }
@Test public void testSupportedPermissionsByNonExistingVersionTree() { Tree versionTree = mock(Tree.class, withSettings().extraInterfaces(TreeTypeAware.class, ReadOnly.class)); when(versionTree.exists()).thenReturn(false); when(versionTree.getPath()).thenReturn(VersionConstants.VERSION_STORE_PATH + "/some/version"); when(versionTree.getProperty(JCR_PRIMARYTYPE)).thenReturn(PropertyStates.createProperty(JCR_PRIMARYTYPE, NT_VERSION, Type.NAME)); when(((TreeTypeAware)versionTree).getType()).thenReturn(TreeType.VERSION); assertEquals(Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(versionTree, null, Permissions.READ)); }
@Test public void testSupportedPermissionsByLocation() { for (String path : PATH_INCUG_MAP.keySet()) { boolean isInCug = PATH_INCUG_MAP.get(path); TreeLocation location = TreeLocation.create(root, path); if (isInCug) { assertEquals(path, Permissions.READ, cugPermProvider.supportedPermissions(location, Permissions.READ)); assertEquals(path, Permissions.READ_NODE, cugPermProvider.supportedPermissions(location, Permissions.READ_NODE)); assertEquals(path, Permissions.READ_PROPERTY, cugPermProvider.supportedPermissions(location, Permissions.READ_PROPERTY)); assertEquals(path, Permissions.READ, cugPermProvider.supportedPermissions(location, Permissions.ALL)); assertEquals(path, Permissions.READ_NODE, cugPermProvider.supportedPermissions(location, Permissions.READ_NODE | Permissions.READ_ACCESS_CONTROL)); } else { assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(location, Permissions.READ)); assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(location, Permissions.READ_NODE)); assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(location, Permissions.READ_PROPERTY)); assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(location, Permissions.ALL)); assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(location, Permissions.READ_NODE | Permissions.READ_ACCESS_CONTROL)); } assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(location, Permissions.READ_ACCESS_CONTROL)); assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(location, Permissions.MODIFY_ACCESS_CONTROL)); assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(location, Permissions.ADD_NODE)); assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(location, Permissions.WRITE)); assertEquals(path, Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(TreeLocation.create(root, "/path/to/no-existing/tree"), Permissions.READ)); } }
@Test public void testSupportedPermissionsByNullLocation() { Tree t = mock(Tree.class); when(t.getPath()).thenReturn(PathUtils.ROOT_PATH); when(t.exists()).thenReturn(false); TreeLocation location = TreeLocation.create(t); assertNull(location.getTree()); assertEquals(Permissions.NO_PERMISSION, cugPermProvider.supportedPermissions(location, Permissions.READ)); }