如何检查某个用户是否对根节点具有 {Write, read} 权限

How to get check if a certain user has {Write, read} permissions on a root node

我想编写一个方法,该方法必须 return 某个用户能够 write/read 的所有根节点。

目前我正在做以下事情:

public List<String> getAllowedRootPaths(String username) throws RepositoryException {

    SecuritySupport securitySupport = Components.getComponent(SecuritySupport.class);
    UserManager userManager = securitySupport.getUserManager();
    myUser = userManager.getUser(username);
    Session session = MgnlContext.getJCRSession("website");
    List<String> results = new ArrayList<String>();

        if (getRoles().contains("rootPublisher")) {
                //check user access and add to array
        }
        return results;
    }

    public Collection<String> getRoles() {
       return magnoliaUser.getAllRoles();
    }

我以前的方法是使用

HierarchyManager hm = MgnlContext.getHierarchyManager("website");

并测试

hm.isGranted(node.getPath(), Permission.READ)

但由于已弃用,我目前正在寻找另一种解决方案。我知道 Session 有一个 AccessRights 测试,但我似乎只适用于 usersession。

也许有人知道如何在不手动获取角色并检查 int 值的情况下做到这一点。

您好, 地狱魔

AccessManager#isGranted(node.getPath(), Permission.READ)

看起来就是你要找的人。

希望对您有所帮助,

干杯

正如 Ducaz035 所建议的那样,您可以执行 MgnlContext.getAccessManager("website") 并在 AccessManager 上调用 isGranted()
或者,您可以只调用 PermissionUtil.isGranted(node,permission) 并让该方法自行定位适当的访问管理器。