我正在研究LoopBack文档,找到了这里。我不是跟随文档来构建所涵盖的应用程序,而是将这些概念应用到我自己的东西上。
我有以下几种型号:
SuperUser =>扩展了内置的User模型Profile =>扩展了内置的User模型Account => a LoopBack PersistedModelTransaction => a简介:
我不希望经过身份验证的实例Profile能够访问端点Profile GET /Profiles。我不希望Profile能够访问有关所有Profile的信息。因此,我已经提出了SuperUser,它应该能够通过实现Role来访问端点Profile GET /Profiles。
起立:
到目前为止,这就是我所拥有的:
一个用于创建SuperUser的函数,以及一个带有name of admin的Role。然后将该角色分配给创建的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中,动态角色$owner在acls中被使用,以确保Profile只能得到它拥有的东西。也不包括admin规则在acls中的包含。
{
"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端点。也就是说,SuperUser应该能够得到所有的Profiles等等。
谢谢你,鲁布斯
发布于 2017-08-16 20:02:19
在您的Profile.js文件中,您应该实现一些方法,该方法接受试图发出请求的当前/源配置文件id (您将从当前上下文中获得该请求)。比较请求的配置文件id和当前配置文件id。如果他们匹配的话,把数据发回。
确保在json中添加验证方法的名称。例如:"property": "[find, yourProfileValidationMethod]"。此外,您还可以在json中添加"model": "Profile"属性,以使此规则特定于此模型。
我希望这能回答你的大部分问题。如果你想要更多的帮助,请告诉我。
https://stackoverflow.com/questions/39315293
复制相似问题