我創建了一個從LoopBack用戶模型繼承的MyUser模型。在啓動腳本中,我在MyUser模型,自定義角色中創建了一個用戶,並將該角色映射到它。但是在MyUser.json文件中分配後ACL不起作用。LoopBack ACL不起作用
Bootscript.js
'use strict';
module.exports = function(app) {
var User = app.models.MyUser;
var Role = app.models.Role;
var RoleMapping = app.models.RoleMapping;
User.findOrCreate({ name: "Administrator", email: "[email protected]", username: "admin", password: "12345" }, function(err, succ) {
if (err) {
console.log(err);
} else {
Role.create({ name: "superUser" }, function(err, role) {
if (err) {
console.log(err);
} else {
console.log("Role created successfuly");
role.principals.create({ principalType: RoleMapping.USER, principalId: succ.id }, function(err, success) {
if (err) {
console.log(err);
} else {
console.log("role mapped successfuly");
}
});
}
});
}
});
};
MyUser.json
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "superUser",
"permission": "ALLOW"
}
]
但是,當我訪問MyUser.find(獲取所有用戶)的API資源管理器的方法,它說
{
"error": {
"statusCode": 401,
"name": "Error",
"message": "Authorization Required",
"code": "AUTHORIZATION_REQUIRED",
"stack": "Error: Authorization Required\n at ...
}
}
我在做什麼錯?