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
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to