Search code examples
marklogic

How to get list of user with specific roles in MarkLogic


How do I retrieve all the users from a specific role?

I need to remove those users from the role also.

This code only displays the roles associated with the user.

xquery version "1.0-ml";
import module namespace sec="http://marklogic.com/xdmp/security" at 
"/MarkLogic/security.xqy";

sec:user-get-roles("XYZ")

Is there any function in MarkLogic to retrieve the users based on specific roles?


Solution

  • If you want to list the users that have the role XYZ, you can use the (undocumented) function sec:role-get-users() and specify the role ID:

    import module namespace sec="http://marklogic.com/xdmp/security" 
      at "/MarkLogic/security.xqy";
    (: execute this against the security database :)
    sec:role-get-users(xdmp:role("XYZ"))
    

    If you want to remove the role XYZ from all users, you can use sec:remove-role-from-users()

    import module namespace sec="http://marklogic.com/xdmp/security" 
      at "/MarkLogic/security.xqy";
    (: execute this against the security database :)
    sec:remove-role-from-users("XYZ")