Mads Hansen 提供了一个很好的示例来演示用户权限和一个测试,以确保您可以看到如何为用户提供有限的阅读文档权限并使用查询控制台 - 一组供用户探索的重要权限数据。但是,根据您对我最初的 cmets 的回复,我认为了解如何找到对文档和用户的访问权限的练习对于故障排除很重要。
请参阅以下脚本。它必须以管理员用户或具有执行权限“user-get-roles”和可能的“xdmp-invoke-function”的用户身份运行
xquery version "1.0-ml";
import module namespace sec="http://marklogic.com/xdmp/security" at
"/MarkLogic/security.xqy";
let $sec-db := xdmp:security-database()
let $uris := cts:uri-match('*')[1 to 20]
let $user := 'test-a-user'
(: run on the security database :)
let $role-report := xdmp:invoke-function(function(){
let $direct-roles := xdmp:role(sec:user-get-roles($user))
let $roles := (xdmp:role-roles(sec:user-get-roles($user)), $direct-roles)
return <roles>{
for $role-id in $roles
return element {'role'} {
attribute {'id'} {$role-id},
attribute {'directly-attached'} {if ($direct-roles = $role-id) then '1' else '0'},
xdmp:role-name($role-id)
}
}
</roles>
}, <options xmlns="xdmp:eval">
<database>{$sec-db}</database>
</options>
)
let $doc-report := <doc-access>
{
for $uri in $uris
return for $permission in xdmp:document-get-permissions($uri)
where $permission/*:capability = 'update' and $role-report//role/@id = $permission/*:role-id
return <match uri='{$uri}' capability='update'>{xdmp:role-name($permission/*:role-id)}</match>
}
</doc-access>
return element {'report'} {
if($role-report//role/text() = 'admin')
then element {'attention'} {'Admin role found - access to all documents'}
else (
$role-report,
$doc-report
)
}
填写有问题的用户名和一系列 URI(我刚刚在示例中抓取了 20 个)
如果管理员的任何直接或继承角色将导致以下报告:
<report>
<attention>Admin role found - access to all documents</attention>
</report>
否则,您将返回该用户的所有角色(直接或继承)和所有具有更新访问权限的 uri(以及匹配角色)的报告。这应该足以解决权限问题——尤其是继承权限。它不是生产代码。如果需要,您还可以修改它以查找读取或执行。它也是使用 sec 命名空间函数中的某些项目的示例。
<report>
<roles>
<role id="15240420431168313686" directly-attached="0">test-b</role>
<role id="7089338530631756591" directly-attached="0">rest-reader</role>
<role id="13041542794130379697" directly-attached="0">rest-extension-user</role>
<role id="15520654661378671735" directly-attached="0">rest-writer</role>
<role id="15240420431090884371" directly-attached="1">test-a</role>
</roles>
<doc-access>
<match uri="/foo/bar.xml" capability="update">test-b</match>
</doc-access>
</report>