CugPermissionProvider implements AggregatedPermissionProvider, CugConstants { @NotNull @Override public Set<String> getPrivileges(@Nullable Tree tree) { if (tree != null && canRead(tree)) { return READ_PRIVILEGE_NAMES; } else { return Collections.emptySet(); } } 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 getPrivileges() { for (String p : NOT_READABLE_PATHS) { Tree tree = root.getTree(p); if (tree.exists()) { assertTrue(cugPermProvider.getPrivileges(root.getTree(p)).isEmpty()); } } }
@Test public void testGetPrivilegesAtCug() { Set<String> expected = ImmutableSet.of( PrivilegeConstants.JCR_READ, PrivilegeConstants.REP_READ_NODES, PrivilegeConstants.REP_READ_PROPERTIES); for (String p : READABLE_PATHS) { Tree tree = root.getTree(p); if (tree.exists()) { assertEquals(expected, cugPermProvider.getPrivileges(tree)); } } }
@Test public void testGetPrivilegesAtCug2() { PermissionProvider pp = createCugPermissionProvider(ImmutableSet.of(SUPPORTED_PATH), testGroupPrincipal); Set<String> expected = ImmutableSet.of( PrivilegeConstants.JCR_READ, PrivilegeConstants.REP_READ_NODES, PrivilegeConstants.REP_READ_PROPERTIES); assertEquals(expected, pp.getPrivileges(root.getTree("/content/a"))); assertEquals(expected, pp.getPrivileges(root.getTree("/content/aa/bb"))); assertTrue(pp.getPrivileges(root.getTree("/content/a/b/c")).isEmpty()); }
@Test public void testGetPrivilegesNullPath() { assertTrue(cugPermProvider.getPrivileges(null).isEmpty()); }
@Test public void testGetPrivilegesWithInvalidCugTree() { Tree invalidCug = mock(Tree.class); when(invalidCug.getProperty(JCR_PRIMARYTYPE)).thenReturn(PropertyStates.createProperty(JCR_PRIMARYTYPE, NT_OAK_UNSTRUCTURED, Type.NAME)); Tree t = mock(Tree.class, withSettings().extraInterfaces(TreeTypeAware.class, ReadOnly.class)); when(t.exists()).thenReturn(true); when(t.getPath()).thenReturn(SUPPORTED_PATH); when(((TreeTypeAware)t).getType()).thenReturn(TreeType.DEFAULT); when(t.hasChild(REP_CUG_POLICY)).thenReturn(true); when(t.getChild(REP_CUG_POLICY)).thenReturn(invalidCug); assertTrue(cugPermProvider.getPrivileges(t).isEmpty()); }