Rails 3 公司帐户具有许多用户,限制对数据的访问
我想知道在我的应用程序中构建身份验证/授权的最佳方法。我想要拥有
许多公司帐户,可能使用子域
帐户有许多用户
并且用户只能访问以下记录由他们自己或具有相同帐户的其他用户创建。
我所做的研究提供了许多混合搭配的想法,以奇怪而美妙的方式组合 devise / cancan / authlogic,但我还没有找到任何东西可以向我展示限制用户访问同一数据的最佳方法模型。
例如:
帐户 1:Eurasia
用户 1:Bob
用户 2:Jim
帐户 2:Eastasia
用户 1:Dave
用户 2:Alan
Isbn 1:account_id 为 1
Isbn 2:account_id 为 2
如何确保 Bob 无法访问还是粗略的 Isbn 2?
///更新 当然,现在我已经发布了这个,我的 google fu 已经启动,我找到了 RyanB 的自述文件 CanCan 2.0,看起来很完美:
>资源
如果您需要根据模型更改授权该怎么办 属性?您可以通过传递条件散列作为最后一个来做到这一点 论证可以。例如,如果您只想允许一个人访问 他拥有的项目可以设置 :user_id 选项。
I'm wondering about the best way to structure authentication/authorization in my app. I want to have
many company accounts, possibly using subdomains
account has many users
and users can only access records that were created by themselves or another user with the same account.
The research I've done provides lots of mix n' match ideas for combining devise / cancan / authlogic in weird and wonderful ways, but I've yet to find anything which shows me the best way to restrict user access to data within the same model.
So for instance:
Account 1: Eurasia
User 1: Bob
User 2: Jim
Account 2: Eastasia
User 1: Dave
User 2: Alan
Isbn 1: account_id is 1
Isbn 2: account_id is 2
How do I make sure Bob can't access or crud Isbn 2?
///update
Of course, now I've posted this, my google fu has kicked in and I've found the readme from RyanB for CanCan 2.0, which seems perfect:
> Resources
What if you need to change authorization based on a model's
attributes? You can do so by passing a hash of conditions as the last
argument to can. For example, if you want to only allow one to access
projects which he owns you can set the :user_id option.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议使用 CanCan 进行授权。
您的能力模型看起来像这样
然后您可以使用条件语句,例如
can? :manage, @post
在你的控制器/视图中。I'd suggest using CanCan for authorization.
Your Ability model would look something like
Then you can use conditionals like
can? :manage, @post
in your Controller/Views.你应该看看 https://github.com/stffn/declarative_authorization 我认为人们确实这样做正如您所要求的(您可以限制对某些记录的访问),
因此,在您的示例中,您可以使用如下方式设置授权:
You should have a look at https://github.com/stffn/declarative_authorization I think that one do exactly as you're asking for (you can limit access to certain records)
so, in your example you could set up the authorization with something like this:
你看过XACML吗?它是一个基于策略的声明性授权框架。这也是 OASIS 的标准。
使用 XACML,您可以获取所需的任何属性(用户、资源、操作或上下文属性)并表达您拥有的用例。
您最初的要求是
在 XACML 中,这将成为以下策略:
就这样! XACML 的架构定义了策略执行点 (PEP),它是保护您的应用程序/数据并将授权请求发送到策略决策点 (PDP) 的组件。
PEP 说:“Alice 可以访问记录 #123 吗?”
PDP 检查 Alice 的帐户 ID 和记录的帐户 ID 以及所有者。
PDP 最终返回“许可”或“拒绝”。
华泰
Have you looked at XACML? It's a policy-based, declarative framework for authorization. It's also a standard from OASIS.
With XACML you can take any attributes you need (user, resource, action, or context attributes) and express the use case that you have.
Your initial requirement was
In XACML that would become the following policy:
That's all! XACML's architecture defines the policy enforcement point (PEP) which is the component that protects your app/data and sends the authorization request to the policy decision point (PDP).
The PEP says: "Can Alice access record #123?"
The PDP checks Alice's account Id and the record's account id as well as owner.
The PDP eventually returns a "Permit" or a "Deny".
HTH