loopback bug acl不工作?

时间:2018-03-10 17:40:11

标签: loopbackjs strongloop

我尝试为模型实现acl(命名为公司)

      "relations": {
       "user": {
       "type": "belongsTo",
       "model": "user",
       "foreignKey": "company_id"
     }
   },
      "acls": [
           {
          "accessType": "*",
          "principalType": "ROLE",
          "principalId": "$everyone",
          "permission": "DENY"
        },
     {
         "accessType": "*",
         "principalType": "ROLE",
         "principalId": "$owner",
          "permission": "ALLOW"
      }
   ],

拒绝所有用户并仅访问该对象的经过身份验证的用户所有者。在这里我也尝试为超级用户添加权限,他们拥有短管理员的所有权限和objec(数据)的所有者可以做crud是否有任何灵魂为此请帮助<​​/ p>

1 个答案:

答案 0 :(得分:0)

您可以拒绝所有未经身份验证的用户,然后拒绝所有人,并仅允许所有者,如下所示:

{
      "accessType": "*",
      "principalType": "ROLE",
      "principalId": "$unauthenticated",
      "permission": "DENY"
},

{
      "accessType": "*",
      "principalType": "ROLE",
      "principalId": "$everyone",
      "permission": "DENY"
},   

{
      "accessType": "*",
      "principalType": "ROLE",
      "principalId": "$owner",
      "permission": "ALLOW"
}

您只需为$ owner拥有CRUD,您可以按以下方式为用户分配所需的属性:

    {
              "accessType": "*",
              "principalType": "ROLE",
              "principalId": "$owner",
              "permission": "ALLOW",
              "property": [
                 "find",
                 "create",
                 "updateAll",
                 "delete"
          ]
    }

对于超级用户,您应该创建此角色并将其分配给您的某个用户。

{
  "accessType": "*",
  "principalType": "ROLE",
  "principalId": "superuser",
  "permission": "ALLOW"
}

如何创建角色?您可以按照文档here

并确保您已启用此文件/server/boot/autentication.js并启用了验证:server.enableAuth()

'use strict';

module.exports = function enableAuthentication(server) {
  // enable authentication
  server.enableAuth();
};

有关更多ACL技巧,请阅读官方文档here