【发布时间】:2017-08-17 04:02:19
【问题描述】:
我正在研究找到 here 的 LoopBack 文档。我没有按照文档来构建涵盖的应用程序,而是将这些概念应用到我自己的东西上。
我有以下型号:
-
SuperUser=> 扩展了内置的User模型 -
Profile=> 扩展了内置的User模型 -
Account=> 环回PersistedModel -
Transaction=> 一个
简介:
我不希望经过身份验证的实例 Profile 能够访问端点 Profile GET /Profiles。我不希望Profile 能够访问有关所有Profile(s) 的信息。所以,我提出了SuperUser,它应该可以通过Role的实现来访问端点Profile GET /Profiles。
站立:
这是我目前所拥有的:
创建SuperUser 的函数,以及Role 和name 的admin。然后将该角色分配给创建的SuperUser。
function createSuperUser(){
SuperUser.create([
{email: "reubs@reubs.com", username:"reubs", password: 'password'}
], function(err, users) {
if (err) throw err;
console.log('Created user:', users);
//create the admin role
Role.create({
name: 'admin'
}, function(err, role) {
if (err) throw err;
console.log('Created role:', role);
role.principals.create({
principalType: RoleMapping.USER,
principalId: users[0].id
}, function(err, principal) {
if (err) throw err;
console.log('Created principal:', principal);
});
});
});
}
我的profile.json 在acls 中使用动态角色$owner 以尝试确保Profile 只能获得它拥有的东西。在acls 中也不包含admin 规则。
{
"name": "Profile",
"base": "User",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {},
"validations": [],
"relations": {
"accounts": {
"type": "hasMany",
"model": "Account",
"foreignKey": "profileId"
}
},
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
},
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "admin",
"permission": "ALLOW",
"property": "find"
}
],
"methods": {}
}
问题:
此设置允许经过身份验证的Profile 访问端点Profile GET /Profiles
目标:
我只希望SuperUser 能够真正完全控制Projects API 端点。 IE。 SuperUser 应该可以得到所有Profiles 等。
提前致谢, 鲁布斯
【问题讨论】:
标签: loopbackjs loopback