【发布时间】:2012-02-10 14:27:42
【问题描述】:
我成功地让我的 Rails 3 应用程序使用 devise 和 devise_ldap_authenticable 运行以针对本地 Active Directory 进行身份验证。
现在我想添加授权功能,以便只允许属于某些 AD 组的 AD 用户访问。
首先,我首先使用 linux 命令 ldapsearch 在 AD 中查找我自己的用户。结果包含类似...
(...)
memberOf: CN=my,OU=foo,DC=bar,DC=role,DC=domain,DC=com
memberOf: CN=my,OU=foo,DC=bar2,DC=role,DC=domain,DC=com
memberOf: (...)
(...)
好的,现在我决定,我要限制对CN=my,OU=foo,DC=bar,DC=role,DC=domain,DC=com. 成员的访问
所以,我将 ldap.yml 更改为包含:
authorizations: &AUTHORIZATIONS
group_base: ou=role,dc=domain,dc=com
required_groups:
- CN=my,OU=foo,DC=bar,DC=role,DC=domain,DC=com
development:
(...)
<<: *AUTHORIZATIONS
另外将我的 devise.rb 更改为包含:
Devise.setup do |config|
config.ldap_logger = true
config.ldap_create_user = true
config.ldap_update_password = false
config.ldap_check_group_membership = true # <-- activated this line
config.ldap_use_admin_to_bind = true
#config.ldap_ad_group_check = true <-- don't know what this is good for
现在,当尝试进行身份验证时,访问被拒绝,这是我没想到的:
User CN=myuser,OU=org,DC=domain,DC=com is not in group: CN=my,OU=foo,DC=bar,DC=role,DC=domain,DC=com
任何想法,如何通过 devise_ldap_authenticable 完成对 AD 的授权?该模块的文档在授权方面还不够全面。
【问题讨论】:
-
请在下方回答您的问题(提交答案)。这样问题仍然存在(不必要的打开)。
-
谢谢,效果很好。注意require_attribute中的大写'CN'和'OU',否则不起作用。花了我几个小时...
-
你能发布一个自我回答吗?
标签: ruby-on-rails-3 active-directory devise authorization