【问题标题】:how to check whether a user is able to update or insert a document in marklogic database?如何检查用户是否能够在 marklogic 数据库中更新或插入文档?
【发布时间】:2023-03-11 22:20:02
【问题描述】:

如何检查用户是否能够更新或插入marklogic数据库中的任何文档?

例如,有4个用户,有的有更新权限,有的有权限读取marklogic数据库中的文档

try{
    let $uri := abc.xml
    let $doc : <a/>
    if (condition)
    then check whether the current user is able to update or insert the doc in marklogic or not , if it is not then throw fn:error()
    else 
    xdmp:document-insert($uri,$doc) (:it will throw error, when user have no permission to insert the doc:)
    }
catch($e)
{$e}

【问题讨论】:

    标签: security authentication permissions marklogic roles


    【解决方案1】:

    用户插入和更新文档所需的权限将取决于用户的显式角色和权限,以及默认权限和对文档设置的任何显式权限。

    https://docs.marklogic.com/guide/admin/security#chapter

    https://docs.marklogic.com/xdmp:document-insert

    所需权限 如果插入新文档,则还需要 unprotected-uri 权限(仅当 URI 不受保护时)、any-uri 权限或适当的 URI 权限。如果向文档添加不受保护的集合,则需要unprotected-collections 权限;如果添加受保护的集合,用户必须具有更新集合的权限或any-collection 权限。

    如果您要更新文档,那么您必须具有为该文档指定的必要权限(可以包括默认权限)。

    使用 xdmp:document-get-permissions 返回哪些角色对该特定 URI 具有哪些权限,然后将其与附加到感兴趣的用户的角色相交,您将知道用户是否可以访问或更新文档。

    因此,要检查用户是否具有插入或更新 URI 的能力,您需要获取该用户的角色,然后查看默认权限或文档权限中的权限是否具有该角色以及插入或更新能力:

    xquery version "1.0-ml";
    import module namespace sec="http://marklogic.com/xdmp/security" at "/MarkLogic/security.xqy";
    let $name := "user-foo"
    let $uri := "/bar.xml"
    let $user-roles := xdmp:invoke-function(
      function(){ sec:user-get-roles($name) }, 
      <options xmlns="xdmp:eval">
        <database>{xdmp:security-database()}</database>
      </options>)
    let $permissions := (xdmp:default-permissions(), xdmp:document-get-permissions($uri))
    return
     exists($permissions[sec:capability=('insert', 'update') and sec:role-id/xdmp:role-name(.) = $user-roles])
    

    【讨论】:

      猜你喜欢
      • 2012-09-16
      • 2015-11-22
      • 1970-01-01
      • 1970-01-01
      • 2010-11-08
      • 2019-01-09
      • 1970-01-01
      • 1970-01-01
      • 2013-08-22
      相关资源
      最近更新 更多