我有两个型号:用户和汽车
用户acl:
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "admin",
"permission": "ALLOW",
"property": "find"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "login"
},
{
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW"
},
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "admin",
"permission": "ALLOW"
}
car acl:
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "find"
},
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW"
},
{
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW"
},
{
"accessType": "WRITE",
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW"
},
{
"accessType": "WRITE",
"principalType": "ROLE",
"principalId": "$authenticated",
"permission": "ALLOW"
}
我可以使用api /cars
添加汽车但无法获取使用api /cars
的汽车列表,在获取它时返回AUTHORIZATION_REQUIRED
错误代码。
注意:我以用户身份登录,然后我正在尝试获取用户拥有的汽车列表。
答案 0 :(得分:0)
您可能遗漏了与Loopback documentation一致的模型关系:
要限定$ owner,目标模型需要具有belongsTo关系 到User模型(或模型从User扩展)和属性匹配 目标模型实例的外键。 $ owner的检查是 仅针对路径上具有':id'的远程方法执行 例如,GET / api / users /:id。
此外,我认为将default setting aclErrorStatus
从 401 更改为 403 是一个好主意。这样就可以更容易理解身份验证或授权是否存在问题。