是否可以在单个 Rails 应用程序中使用域或子域的 cookie 用户会话
我想在多子域应用程序中登录管理员和简单用户。管理员应该有权访问所有子域(即他们的会话应该存储在所有子域都可用的 cookie 中)。用户应该只能访问他们登录的子域。
例如:
admin“管理员”在域 URL (mydomain.com) 或任何子域(例如 abc.mydomain)登录.com)并在所有子域中保持登录状态。因此,他(“管理员”)可以访问 efg.mydomain.com、abc.mydomain.com、mydomain.com 等。
用户“simpleuser”在 abc.mydomain.com 登录。他(“simpleuser”)只能访问此子域(即 cookie 仅与 abc.mydomain.com 子域相关)
我知道可以选择将 cookie 关联到子域或域,但我想在同一个应用程序中混合这种行为。有谁知道一种方法吗?
这是针对 Rails 3 的,
我不想通过我的应用程序(即通过 cancan 或声明性授权)限制对子域的访问。理想情况下,应通过 cookie 在子域级别阻止访问。我相信这是一种更安全的方法,因为它不必再设置一个软件来控制对站点的访问。
I want in a multi-subdomain application to login admins and simple users. The admins should have access to all the subdomains (i.e. their session should be stored in a cookie that is available to all the subdomains). The users should have access only to the subdomain which they logged in.
so for example:
admin "administrator" signs in either at the domain url (mydomain.com) or at any subdomain (e.g. abc.mydomain.com) and remains logged in all the subdomains. He ("administrator") can therefore access efg.mydomain.com, abc.mydomain.com, mydomain.com etc. etc.
user "simpleuser" signs in at abc.mydomain.com. He ("simpleuser") can only access this subdomain (i.e. the cookie relates only to the abc.mydomain.com subdomain)
I know that it is possible to choose to associate to cookie either to subdomain or the domain, but I would like to mix this behavior in the same application. Does anyone know of an approach?
This is for Rails 3
I would not want to limit access to the subdomain through my application ( i.e. through cancan or declarative authorization ). Ideally access should be blocked at the subdomain level through the cookie. I believe that this is a safer approach since it does away with having to set up one more piece of software for controlling access to the site.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您希望 cookie 在所有子域中都有效,但使用授权来限制用户授予对子域的访问权限。
像 cancan 这样的东西可以在这里工作——如果你是管理员,你可以访问除用户之外的所有内容仅当您是该用户时才能访问。
在你的application_controller中的
capability.rb中
班级能力
包括 CanCan::Ability
You'll want to have the cookie valid across all subdomains, but use authorization to restrict users to give access to the subdomain.
Something like cancan could work here -- where if you are an admin, you can access everything, but a user can access only if you are that user.
in your application_controller
In ability.rb
class Ability
include CanCan::Ability