CugPermissionProvider implements AggregatedPermissionProvider, CugConstants { @NotNull TreePermission getTreePermission(@NotNull Tree parent, @NotNull TreeType parentType, @NotNull String childName, @NotNull NodeState childState, @NotNull AbstractTreePermission parentPermission) { Tree t = treeProvider.createReadOnlyTree(parent, childName, childState); TreeType type = typeProvider.getType(t, parentType); return getTreePermission(t, type, parentPermission); } 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 testGetTreePermissions() throws AccessDeniedException { TreePermission rootTp = cugPermProvider.getTreePermission(root.getTree("/"), TreePermission.EMPTY); assertTrue(rootTp instanceof EmptyCugTreePermission); TreePermission contentTp = cugPermProvider.getTreePermission(root.getTree(SUPPORTED_PATH), rootTp); assertTrue(contentTp instanceof CugTreePermission); TreePermission aTp = cugPermProvider.getTreePermission(root.getTree("/content/a"), contentTp); assertTrue(aTp instanceof CugTreePermission); TreePermission bTp = cugPermProvider.getTreePermission(root.getTree("/content/a/b"), aTp); assertTrue(bTp instanceof CugTreePermission); TreePermission cTp = cugPermProvider.getTreePermission(root.getTree("/content/a/b/c"), bTp); assertTrue(cTp instanceof CugTreePermission); TreePermission aaTp = cugPermProvider.getTreePermission(root.getTree("/content/aa"), contentTp); assertTrue(aaTp instanceof CugTreePermission); TreePermission bbTp = cugPermProvider.getTreePermission(root.getTree("/content/aa/bb"), aaTp); assertTrue(bbTp instanceof CugTreePermission); TreePermission ccTp = cugPermProvider.getTreePermission(root.getTree("/content/aa/bb/cc"), bbTp); assertTrue(ccTp instanceof CugTreePermission); Tree aaTree = root.getTree("/content/aa"); TreeUtil.addChild(aaTree, CugConstants.REP_CUG_POLICY, NT_OAK_UNSTRUCTURED); TreePermission aaTp2 = cugPermProvider.getTreePermission(root.getTree("/content/aa"), contentTp); assertTrue(aaTp2 instanceof CugTreePermission); TreePermission falseCugTp = cugPermProvider.getTreePermission(root.getTree("/content/aa/rep:cugPolicy"), aaTp2); assertNotSame(TreePermission.EMPTY, falseCugTp); TreePermission cugTp = cugPermProvider.getTreePermission(root.getTree("/content/a/rep:cugPolicy"), aTp); assertSame(TreePermission.NO_RECOURSE, cugTp); TreePermission jcrSystemTp = cugPermProvider.getTreePermission(root.getTree("/jcr:system"), rootTp); assertTrue(jcrSystemTp instanceof EmptyCugTreePermission); assertSame(TreePermission.NO_RECOURSE, cugPermProvider.getTreePermission(root.getTree(NodeTypeConstants.NODE_TYPES_PATH), jcrSystemTp)); TreePermission unsupportedPathTp = cugPermProvider.getTreePermission(root.getTree(UNSUPPORTED_PATH), rootTp); assertSame(TreePermission.NO_RECOURSE, unsupportedPathTp); try { cugPermProvider.getTreePermission(root.getTree(UNSUPPORTED_PATH + "/child"), unsupportedPathTp); fail(); } catch (IllegalStateException e) { } }
@Test public void testGetTreePermissionNonExistingVersionTree() { Tree versionTree = mock(Tree.class); when(versionTree.exists()).thenReturn(false); when(versionTree.getProperty(JCR_PRIMARYTYPE)).thenReturn(PropertyStates.createProperty(JCR_PRIMARYTYPE, NT_VERSION, Type.NAME)); TreePermission tp = cugPermProvider.getTreePermission(versionTree, TreeType.VERSION, mock(TreePermission.class)); assertSame(TreePermission.NO_RECOURSE, tp); }