StrongLoop:子表的 ACL

StrongLoop: ACL for Subtable

我有两个表 ABA hasOne B, B 属于 A.

现在我在 B 中有以下 ACL:

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

当我向 localhost/api/B/{id} 发出请求时,我收到 401。

当我向 localhost/api/A/{id}/B 发出请求时,我收到了数据。

我该如何解决这个问题?两者都应该得到 401 错误。有没有我不必触摸的解决方案?A.json?

我可以在 A 中修复 acl,但我认为这会很丑陋。

StrongLoop Doc 中找到了一些东西,这意味着我也必须在 A 中定义 ACL?

在当前的loopback版本中是这样的。您可以在 github 个问题 https://github.com/strongloop/loopback/issues/960 中找到不同的参考资料 https://github.com/strongloop/loopback-example-access-control/issues/41

您链接的文档实际上有一个针对相反问题的明确警告,通过用户连接时获取相关实例。

If a model has a DENY ALL permission (for example a built-in model such as the User model), but related models have no ACLs, the related models will still not be accessible through the User model. So, for example, even if the books model's default ACL is ALLOW $authenticated for GET /books, the route GET /user/{id}/books default will still be DENY ALL.

看来您还需要明确授予或不授予访问权限,为您希望修改的每个生成的方法这样做。具有 hasAndBelongsToMany 的用户示例:

{
  "accessType": "READ",
  "principalType": "ROLE",
  "principalId": "$authenticated",
  "permission": "ALLOW",
  "property": "__get__skills"
},
{
  "accessType": "WRITE",
  "principalType": "ROLE",
  "principalId": "$owner",
  "permission": "ALLOW",
  "property": "__link__skills"
},
{
  "accessType": "WRITE",
  "principalType": "ROLE",
  "principalId": "$owner",
  "permission": "ALLOW",
  "property": "__unlink__skills"
}

我记得在版本 3 中看到了一种处理影响相关模型的 ACL 的新方法,但我找不到参考资料了。