CugPermissionProvider implements AggregatedPermissionProvider, CugConstants { @Override public boolean isGranted(@NotNull Tree tree, PropertyState property, long permissions) { if (isRead(permissions)) { return canRead(tree); } else { return false; } } 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 testIsGrantedByLocation() { for (String p : NOT_READABLE_PATHS) { TreeLocation location = TreeLocation.create(root, p); assertFalse(cugPermProvider.isGranted(location, Permissions.READ)); assertFalse(cugPermProvider.isGranted(location, Permissions.READ_NODE)); assertFalse(cugPermProvider.isGranted(location, Permissions.READ_PROPERTY)); assertFalse(cugPermProvider.isGranted(location, Permissions.ALL)); assertFalse(cugPermProvider.isGranted(location, Permissions.ADD_NODE)); assertFalse(cugPermProvider.isGranted(location, Permissions.READ_ACCESS_CONTROL)); } for (String p : READABLE_PATHS) { TreeLocation location = TreeLocation.create(root, p); assertTrue(cugPermProvider.isGranted(location, Permissions.READ)); assertTrue(cugPermProvider.isGranted(location, Permissions.READ_NODE)); assertTrue(cugPermProvider.isGranted(location, Permissions.READ_PROPERTY)); assertFalse(cugPermProvider.isGranted(location, Permissions.ALL)); assertFalse(cugPermProvider.isGranted(location, Permissions.ADD_NODE)); assertFalse(cugPermProvider.isGranted(location, Permissions.READ_ACCESS_CONTROL)); } }
@Test public void testIsGrantedNonExistingLocation() throws Exception { try (ContentSession anonymous = login(new GuestCredentials())) { Root anonymousRoot = anonymous.getLatestRoot(); for (Root r : new Root[]{anonymousRoot, root}) { TreeLocation location = TreeLocation.create(r, "/path/to/non/existing/tree"); assertFalse(cugPermProvider.isGranted(location, Permissions.READ)); assertFalse(cugPermProvider.isGranted(location, Permissions.READ_NODE)); assertFalse(cugPermProvider.isGranted(location, Permissions.READ_PROPERTY)); assertFalse(cugPermProvider.isGranted(location, Permissions.ALL)); assertFalse(cugPermProvider.isGranted(location, Permissions.ADD_NODE)); assertFalse(cugPermProvider.isGranted(location, Permissions.READ_ACCESS_CONTROL)); } } }
@Test public void testIsGrantedNonRead() { for (String p : Iterables.concat(READABLE_PATHS, NOT_READABLE_PATHS)) { Tree tree = root.getTree(p); if (tree.exists()) { assertFalse(cugPermProvider.isGranted(tree, null, Permissions.ALL)); assertFalse(cugPermProvider.isGranted(tree, null, Permissions.READ | Permissions.READ_ACCESS_CONTROL)); assertFalse(cugPermProvider.isGranted(tree, null, Permissions.REMOVE_NODE)); } } }
@Test public void testIsGrantedRead() { for (String p : NOT_READABLE_PATHS) { Tree tree = root.getTree(p); if (tree.exists()) { assertFalse(cugPermProvider.isGranted(tree, null, Permissions.READ)); assertFalse(cugPermProvider.isGranted(tree, tree.getProperty(JCR_PRIMARYTYPE), Permissions.READ_PROPERTY)); } } for (String p : READABLE_PATHS) { Tree tree = root.getTree(p); if (tree.exists()) { assertTrue(cugPermProvider.isGranted(tree, null, Permissions.READ)); assertTrue(cugPermProvider.isGranted(tree, null, Permissions.READ_NODE)); assertTrue(cugPermProvider.isGranted(tree, tree.getProperty(JCR_PRIMARYTYPE), Permissions.READ_PROPERTY)); } } }
@Test public void testIsGrantedJcrActions() { for (String p : NOT_READABLE_PATHS) { assertFalse(cugPermProvider.isGranted(p, Session.ACTION_READ)); assertFalse(cugPermProvider.isGranted(p, Session.ACTION_ADD_NODE)); assertFalse(cugPermProvider.isGranted(p, Session.ACTION_READ + ',' + Session.ACTION_ADD_NODE)); } for (String p : READABLE_PATHS) { assertTrue(cugPermProvider.isGranted(p, Session.ACTION_READ)); assertFalse(cugPermProvider.isGranted(p, Session.ACTION_ADD_NODE)); assertFalse(cugPermProvider.isGranted(p, Session.ACTION_READ + ',' + Session.ACTION_ADD_NODE)); } }
@Test public void testIsGrantedJcrActionsNonExistingPath() { String p = "/path/to/non/existing/tree"; assertFalse(cugPermProvider.isGranted(p, Session.ACTION_READ)); assertFalse(cugPermProvider.isGranted(p, Permissions.getString(Permissions.READ_NODE))); assertFalse(cugPermProvider.isGranted(p, Permissions.getString(Permissions.READ_PROPERTY))); assertFalse(cugPermProvider.isGranted(p, Session.ACTION_ADD_NODE)); assertFalse(cugPermProvider.isGranted(p, Session.ACTION_READ + ',' + Session.ACTION_ADD_NODE)); }