如何在环回中分配角色访问权限?

时间:2018-12-22 05:14:37

标签: mongodb loopback

我试图将角色访问权限分配给我在回送中创建的两个用户。我能够成功创建角色,但是,在模型中创建ACL之后,访问控制将无法正常运行。谁能指出我做错了什么?

在我的第一个启动脚本中:

#import the Beautiful soup functions to parse the data returned from the website
from bs4 import BeautifulSoup


category = BeautifulSoup('<div class="_1GGPkHIiaumnRMT-S1cU29"><span>print me 1</span><span><div class="_2ZBv5UiBzOiApuonYSpb92"><div>patates</div></div></span><span>print me 2</span></div>')

def printSpan(s):
  s = s.find_all("span")
  for string in s:
    if len(string.find_all("div")) != 0:
      continue
    else:
      print (str(string).replace("<span>", "").replace("</span>", ""))

printSpan(category)

在我的第二个启动脚本中:

                module.exports = (app) => {
                const User = app.models.User;
                const Role = app.models.Role;
                const RoleMapping = app.models.RoleMapping;

                User.findOrCreate(
                {
                    where: {
                    username: 'admin'
                    }
                },
                {
                    username: 'admin',
                    email: process.env.ADMIN_EMAIL,
                    firstName: 'Admin',
                    lastName: 'Account',
                    password: process.env.ADMIN_PWD,
                    emailVerified: true
                },
                (err, user) => {
                    if (err) console.log(err);
                    Role.findOrCreate(
                    {
                        where: {
                        name: 'admin'
                        }
                    },
                    {
                        name: 'admin'
                    },
                    (errRole, role) => {
                        if (errRole) console.log('error creating role', errRole);
                        RoleMapping.findOrCreate(
                        {
                            where: {
                            principalType: 'admin'
                            }
                        },
                        {
                            principalType: 'admin',
                            principalId: user.id
                        },
                        (error, mapping) => {
                            if (error) console.log(error);
                        }
                        );
                    }
                    );
                }
                );
            };

在我的模型中:

            const EMPLOYEE_PWD = 'test' || process.env.EMPLOYEE_PWD;

            module.exports = (app) => {
                const User = app.models.User;
                const Role = app.models.Role;
                const RoleMapping = app.models.RoleMapping;

            User.findOrCreate(
                {
                    where: {
                    username: 'employee'
                    }
                },
                {
                    username: 'employee',
                    email: process.env.EMPLOYEE_EMAIL,
                    firstName: 'Jerry',
                    lastName: 'Javascript',
                    password: process.env.EMPLOYEE_PWD,
                    emailVerified: true
                },
                (err, user) => {
                    if (err) console.log(err);
                    Role.findOrCreate(
                    {
                        where: {
                        name: 'employee'
                        }
                    },
                    {
                        name: 'employee'
                    },
                    (errRole, role) => {
                        if (errRole) console.log('error creating role', errRole);
                        RoleMapping.findOrCreate(
                        {
                            where: {
                            principalType: 'employee'
                            }
                        },
                        {
                            principalType: 'employee',
                            principalId: user.id
                        },
                        (error, mapping) => {
                            if (error) console.log(error);
                        }
                        );
                    }
                    );
                }
                );
            }

角色:

            "acls": [
                    {
                    "accessType": "*",
                    "principalType": "ROLE",
                    "principalId": "$everyone",
                    "permission": "DENY"
                    },
                    {
                    "accessType": "*",
                    "principalType": "ROLE",
                    "principalId": "admin",
                    "permission": "ALLOW"
                    },  
                    {
                    "accessType": "EXECUTE",
                    "principalType": "ROLE",
                    "principalId": "employee",
                    "permission": "ALLOW",
                    "property": "findById"
                    }
                ],

0 个答案:

没有答案