cancel
Showing results for 
Search instead for 
Did you mean: 

How to find user role on space?

nenad982
Champ on-the-rise
Champ on-the-rise
Hi all,

how I can check is some user has specific role (Consumer, Contributor, Collaborator…) on space in repository using Java API - Alfresco Ent 4.2 ?

Thanks,
Nenad
3 REPLIES 3

scouil
Star Contributor
Star Contributor
Hi,

I never used it myself but the SiteService have the following method:

**
     * List the members of the site.  This includes both users and groups.
     * <p>
     * Name and role filters are optional and if not specified all the members of the site are returned.
     *
     * @param shortName     site short name
     * @param nameFilter    name filter
     * @param roleFilter    role filter
     * @param size          max results size crop if >0
     * @return Map<String, String>  the authority name and their role
     */
    @NotAuditable
    Map<String, String> listMembers(String shortName, String nameFilter, String roleFilter, int size);


Looks like with the right role filter (e.g. SiteModel.SITE_MANAGER), and the right name filter, you'd just have to check if the returned map is empty.

nenad982
Champ on-the-rise
Champ on-the-rise
Hi Scouil,

thank you for your answer. But I am actually think on roles (permissions) that user have on specific space (folder) under the Share site (not on site membership roles).
So If we create Share site and using Manage Permissions action on site's folder we can delete all Locally Set Permissions and just to say that EVERYBODY are Consumers on that site. After that on site's documentLibrary folder we can user the same action and to add authorities and to give them specific permissions (for example: Collaborator, Contributor…). So my question is how I can find which permissions/roles user have on specific space in repository using Java API?

Thanks,
Nenad

scouil
Star Contributor
Star Contributor
Sorry my bad I read too fast and read site instead of space.

Then please try this. I haven't double checked personally but found this in a piece of old code and simplified it a bit to only match the part of interest to you:

Set<AccessPermission> allPermissions = permissionService.getAllSetPermissions(myNodeRef);

        for (AccessPermission ap : allPermissions)
        {
            if (ap.getPermission().equals(PermissionService.COORDINATOR))
            {
                //is coordinator
            }
        }