具有相同角色的用户如何访问具有不同权限的不同帖子? [英] How can a user with same role access different posts with different permissions?
问题描述
我使用 devise 进行身份验证,并为每个用户分配了一个角色.我还有一个包含帖子数的模型 posts
.我想限制角色 employee
的一名用户查看特定帖子,而同一用户查看和创建不同的帖子.我该怎么做?
I use devise for authentication and have assigned a role for each user. I have one more model posts
which contain number of posts. I want to restrict one user of the role employee
to view the specific post and the same user to view and create the different post. How can I do this?
推荐答案
我意识到我已经迟到了.
I realize I am late to the battle here.
您正在寻找的是基于角色的访问控制的扩展.RBAC 无法很好地满足您的情况.您需要考虑基于属性的访问控制.CanCan 和 Devise 是两个特定于语言的框架,用于解决基于属性的访问控制.
What you are looking for is an extension to role-based access control. RBAC cannot cater well for your scenario. You need to consider attribute-based access control. CanCan and Devise are two language-specific frameworks that address attribute-based access control.
如果您想要更广泛、更通用的 ABAC 解决方案,请考虑 XACML,即可扩展访问控制标记语言,它是 OASIS 定义的标准,与 SAML 非常相似.
If you want a broader, more generic ABAC solution, then consider XACML, the eXtensible Access Control Markup Language, which is a standard defined by OASIS much like SAML is.
XACML 为您提供:
XACML gives you:
- 基于属性的访问控制:属性可用于描述几乎任何事物(用户、对象、资源、上下文、时间、操作...).
- 基于策略的访问控制:策略汇集属性来定义授权.例如,员工可以查看同一团队中员工的帖子,并可以编辑他们拥有的帖子.
- 细粒度访问:可以定义非常具体和细粒度的授权策略
- 支持职责分离
- 独立于语言的授权:它适用于 Java、.NET、Ruby、Python 等......
- 集中政策管理
这里有一些有趣的资源可以了解更多信息:
Here are some interesting resources to learn more:
- NIST RBAC model
- NIST ABAC model
- OASIS XACML website
这篇关于具有相同角色的用户如何访问具有不同权限的不同帖子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!