我有两个表A
和B
。 A
有一个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?
最佳答案
在当前版本的环回中就是这种情况。您可以在 github issues 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 的新方法,但我无法再次找到引用。
关于javascript - StrongLoop:子表的 ACL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36918561/