首页 > 解决方案 > 如何在 Feathers 中“限制所有者”但允许“管理员”角色

问题描述

我使用 feathers-permissions 和 feathers-authentication-hooks 来构建一个 RBAC 系统,但仍然无法实现。我想要的是例如:

  before: {
    all: [],
    find: [authenticate('jwt'), checkPermissions({roles: ['admin']})],
    get: [authenticate('jwt'), checkPermissions({roles: ['admin']}), hooks.restrictToOwner({ownerField: '_id'})],
    create: [hashPassword()],
    update: [hashPassword(), authenticate('jwt'), checkPermissions({roles: ['admin']}), hooks.restrictToOwner({ownerField: '_id'})],
    patch: [hashPassword(), authenticate('jwt'), checkPermissions({roles: ['admin']}), hooks.restrictToOwner({ownerField: '_id'})],
    remove: [authenticate('jwt'), checkPermissions({roles: ['admin']})]
  },

这样管理员仍然无法查看/更新其他帐户。

有什么帮助吗?

标签: authenticationpermissionshookrbacfeathersjs

解决方案


feathers-permissions我在->有条件限制角色中找到了答案

此外,是的,最好使用现有的钩子,如feathers-hooks-common. 但是,如果它不可行,那么您始终可以创建适合您需求的自己的钩子。


推荐阅读