首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LoopBack和管理用户

LoopBack和管理用户
EN

Stack Overflow用户
提问于 2016-09-04 09:08:08
回答 1查看 842关注 0票数 2

我正在研究LoopBack文档,找到了这里。我不是跟随文档来构建所涵盖的应用程序,而是将这些概念应用到我自己的东西上。

我有以下几种型号:

  1. SuperUser =>扩展了内置的User模型
  2. Profile =>扩展了内置的User模型
  3. Account => a LoopBack PersistedModel
  4. Transaction => a

简介:

我不希望经过身份验证的实例Profile能够访问端点Profile GET /Profiles。我不希望Profile能够访问有关所有Profile的信息。因此,我已经提出了SuperUser,它应该能够通过实现Role来访问端点Profile GET /Profiles

起立:

到目前为止,这就是我所拥有的:

一个用于创建SuperUser的函数,以及一个带有name of adminRole。然后将该角色分配给创建的SuperUser

代码语言:javascript
复制
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中,动态角色$owneracls中被使用,以确保Profile只能得到它拥有的东西。也不包括admin规则在acls中的包含。

代码语言:javascript
复制
{
  "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等等。

谢谢你,鲁布斯

EN

回答 1

Stack Overflow用户

发布于 2017-08-16 20:02:19

在您的Profile.js文件中,您应该实现一些方法,该方法接受试图发出请求的当前/源配置文件id (您将从当前上下文中获得该请求)。比较请求的配置文件id和当前配置文件id。如果他们匹配的话,把数据发回。

确保在json中添加验证方法的名称。例如:"property": "[find, yourProfileValidationMethod]"。此外,您还可以在json中添加"model": "Profile"属性,以使此规则特定于此模型。

我希望这能回答你的大部分问题。如果你想要更多的帮助,请告诉我。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39315293

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档