Skip to content

Instantly share code, notes, and snippets.

@jmakeig
jmakeig / catch-permdenied.xqy
Last active August 17, 2016 12:45
Display roles and privileges when you get a permission denied error
import module namespace sec="http://marklogic.com/xdmp/security" at "/MarkLogic/security.xqy";
(: Don’t use this in production. It leaks security information available to a user with elevated privileges, such as admin. :)
try {
(: … :)
} catch($err) {
if('SEC-PERMDENIED' = $err/error:code/data()) then
xdmp:invoke-function( function() {
for $role in xdmp:user-roles(xdmp:get-current-user()) (: Or a specific user, especially if you’re running as an elevated role :)