CugPermissionProvider implements AggregatedPermissionProvider, CugConstants { @Override public boolean hasPrivileges(@Nullable Tree tree, @NotNull String... privilegeNames) { if (tree == null) { return false; } for (String privilegeName : privilegeNames) { if (!READ_PRIVILEGE_NAMES.contains(privilegeName)) { return false; } } return canRead(tree); } 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 testHasReadPrivileges() { for (String p : NOT_READABLE_PATHS) { Tree tree = root.getTree(p); if (tree.exists()) { assertFalse(cugPermProvider.hasPrivileges(tree, PrivilegeConstants.JCR_READ)); assertFalse(cugPermProvider.hasPrivileges(tree, PrivilegeConstants.REP_READ_NODES)); assertFalse(cugPermProvider.hasPrivileges(tree, PrivilegeConstants.REP_READ_PROPERTIES)); assertFalse(cugPermProvider.hasPrivileges(tree, PrivilegeConstants.REP_READ_NODES, PrivilegeConstants.REP_READ_PROPERTIES)); } } }
@Test public void testHasReadPrivilegesAtCug() { for (String p : READABLE_PATHS) { Tree tree = root.getTree(p); if (tree.exists()) { assertTrue(cugPermProvider.hasPrivileges(tree, PrivilegeConstants.JCR_READ)); assertTrue(cugPermProvider.hasPrivileges(tree, PrivilegeConstants.REP_READ_NODES)); assertTrue(cugPermProvider.hasPrivileges(tree, PrivilegeConstants.REP_READ_PROPERTIES)); assertTrue(cugPermProvider.hasPrivileges(tree, PrivilegeConstants.REP_READ_NODES, PrivilegeConstants.REP_READ_PROPERTIES)); } } }
@Test public void testHasNonReadPrivileges() { for (String p : Iterables.concat(READABLE_PATHS, NOT_READABLE_PATHS)) { Tree tree = root.getTree(p); if (tree.exists()) { assertFalse(cugPermProvider.hasPrivileges(tree, PrivilegeConstants.JCR_WRITE)); assertFalse(cugPermProvider.hasPrivileges(tree, PrivilegeConstants.JCR_LIFECYCLE_MANAGEMENT)); assertFalse(cugPermProvider.hasPrivileges(tree, PrivilegeConstants.JCR_READ, PrivilegeConstants.JCR_LIFECYCLE_MANAGEMENT)); assertFalse(cugPermProvider.hasPrivileges(tree, PrivilegeConstants.JCR_READ_ACCESS_CONTROL)); assertFalse(cugPermProvider.hasPrivileges(tree, PrivilegeConstants.JCR_ALL)); } } }
@Test public void testHasPrivilegesNullPath() { assertFalse(cugPermProvider.hasPrivileges(null, PrivilegeConstants.JCR_READ)); }
@Test public void testHasPrivilegesNonExistingVersionTree() { 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); assertFalse(cugPermProvider.hasPrivileges(versionTree, PrivilegeConstants.JCR_READ)); }