简体   繁体   中英

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

I want to write a method which has to return all the root nodes a certain user is able to write/read.

Currently I am doing the following:

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();
    }

My old method was to use the

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

and test

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

but since thats deprecated I'm currently looking for another solution. I am aware that Session has a test for AccessRights but i seems that only works for a usersession.

Maybe someone has an Idea how to do that without manually grabbing the Roles and checking for the int values.

Greetings, Hellfiend

As Ducaz035 suggested you can do MgnlContext.getAccessManager("website") and call isGranted() on AccessManager.
Alternatively you can just call PermissionUtil.isGranted(node,permission) and let that method to locate proper access manager itself.

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

Seems like the one you are looking for.

Hope that helps,

Cheers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM