【发布时间】:2017-05-22 20:23:34
【问题描述】:
我正在尝试根据基本文档使用 thise gem (https://github.com/cschiewek/devise_ldap_authenticatable)
这是我的 devise.rb 配置
# ==> LDAP Configuration
config.ldap_logger = true
config.ldap_create_user = true
config.ldap_config = "#{Rails.root}/config/ldap.yml"
这是我的 ldap.yml
authorizations: &AUTHORIZATIONS
allow_unauthenticated_bind: true
group_base: ou=groups,dc=test,dc=com
## Requires config.ldap_check_group_membership in devise.rb be true
# Can have multiple values, must match all to be authorized
required_groups:
# If only a group name is given, membership will be checked against "uniqueMember"
- cn=admins,ou=groups,dc=test,dc=com
- cn=users,ou=groups,dc=test,dc=com
# If an array is given, the first element will be the attribute to check against, the second the group name
- ["moreMembers", "cn=users,ou=groups,dc=test,dc=com"]
## Requires config.ldap_check_attributes in devise.rb to be true
## Can have multiple attributes and values, must match all to be authorized
require_attribute:
objectClass: inetOrgPerson
authorizationRole: postsAdmin
## Environment
development:
host: myACtiveDirectory.server
port: 389
attribute: userPrincipalName
base: dc=mycompanydomain,dc=com
admin_user: cn=admin,dc=test,dc=com
admin_password: admin_password
ssl: false
# <<: *AUTHORIZATIONS
当我尝试登录时,我想要实现的是使用电子邮件登录并通过,如果用户不在本地数据库中,则创建记录。 在日志中,我看到 LDAP 无法根据 userPrincipalName 找到用户并且它总是两次(它是否在失败之前尝试了两次?)
LDAP: LDAP dn lookup: userPrincipalName=mirob@mycompanydomain.com
LDAP: LDAP search for login: userPrincipalName=mirob@mycompanydomain.com
LDAP: LDAP search yielded 0 matches
LDAP: Authorizing user userPrincipalName=mirob@mycompanydomain.com,dc=mycompanydomain,dc=com
LDAP: Not authorized because not authenticated.
LDAP: LDAP dn lookup: userPrincipalName=mirob@mycompanydomain.com
LDAP: LDAP search for login: userPrincipalName=mirob@mycompanydomain.com
LDAP: LDAP search yielded 0 matches
LDAP: Authorizing user userPrincipalName=mirob@mycompanydomain.com,dc=mycompanydomain,dc=com
LDAP: Not authorized because not authenticated.
当我使用此问题中的脚本进行测试时(我将 sAMAccountName 更改为主体名称,并且我没有将用户名与域合并)我可以登录到 LDAP,因此连接正常 Ldap is not working with Devise
知道我的设计 ldap 设置有什么问题吗?
编辑: 好的,我发现 ldap_authenticable 正在搜索 DN,在我的情况下(Active Directory 设置)是 CN=Complete Name,CN=Users,CN=mydomain,CN=com 问题是如何搜索电子邮件而不是完整名称,因为我无法为所有用户更新 AD 以将电子邮件放入名称字段?
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4 devise ldap