Thank you and that get me going in the right direction! Thanks,
Eric Shevchuk Sr. Production Support/Applications Consultant Infosys/Bristow Group, Inc. 2103 City West Blvd., 2nd Floor Houston, TX 77042 [email protected] From: [email protected] [mailto:[email protected]] On Behalf Of Gary Vidal Sent: Wednesday, March 29, 2017 1:55 PM To: [email protected] Subject: [MarkLogic Dev General] marklogic xquery to extract users and roles (Eric Shevchuk) Here is a basic script you can call from any database that has a security database. The trick is to use xdmp:invoke-function from your database to security database. Once your in security database just read the database as regular xml. For the sake of clarity you should never!!!! expose the security ids. A caveat of this is that it does not handle role recursion so you will have to solve that issue. But something I did in a few minutes I leave you as an exercise :-D import module namespace sec = "http://marklogic.com/xdmp/security" at "/MarkLogic/security.xqy"; xdmp:invoke-function(function() { let $users := /sec:user let $roles := map:new(/sec:role ! map:entry(fn:string(./sec:role-id),fn:string(./sec:role-name))) return for $user in $users return <user>{ $user/sec:user-name ! <userName>{fn:data(.)}</userName>, <roles>{ for $role in $user/sec:role-ids/sec:role-id return <role>{map:get($roles,fn:string($role))}</role> }</roles> }</user> }, <options xmlns="xdmp:eval"> <database>{xdmp:security-database()}</database> </options> )
_______________________________________________ General mailing list [email protected] Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general
