设计LDAP身份验证问题

时间:2011-12-06 05:29:26

标签: ruby-on-rails-3 devise ldap

我目前正在尝试在RAILS3上使用LDAP身份验证实现Devise。我已经设置了它似乎连接并尝试auth,但似乎失败。我似乎没有得到任何类型的真实错误消息,因此很难再接受它。

登录会话日志:

Started POST "/users/sign_in" for 192.168.160.1 at Tue Dec 06 05:20:16 +0000 2011
  Processing by Devise::SessionsController#create as HTML
  Parameters: {"commit"=>"Sign in", "authenticity_token"=>"G2tEq9gPpJiN0RhanTd8HMWno62F+1oLWbU4xdX78bg=", "utf8"=>"\342\234\223", "user"=>{"remember_me"=>"0", "password"=>"[FILTERED]", "login"=>"richmond@email.com"}}
  User Load (0.1ms)  SELECT `users`.* FROM `users` WHERE `users`.`login` = 'richmond@email.com' LIMIT 1
  LDAP: LDAP dn lookup: mail=richmond@email.com
  LDAP: LDAP search for login: mail=richmond@email.com
  LDAP: Authorizing user mail=richmond@email.com,ou=groupxx,o=company.com
  LDAP: LDAP dn lookup: mail=richmond@email.com
  LDAP: LDAP search for login: mail=richmond@email.com
Completed 401 Unauthorized in 7147ms
  Processing by Devise::SessionsController#new as HTML
  Parameters: {"commit"=>"Sign in", "authenticity_token"=>"G2tEq9gPpJiN0RhanTd8HMWno62F+1oLWbU4xdX78bg=", "utf8"=>"\342\234\223", "user"=>{"remember_me"=>"0", "password"=>"[FILTERED]", "login"=>"richmond@email.com"}}
Rendered devise/shared/_links.erb (0.1ms)
Rendered devise/sessions/new.html.erb within layouts/application (5.0ms)
Completed 200 OK in 23ms (Views: 21.4ms | ActiveRecord: 0.0ms)


Started GET "/assets/defaults.js" for 192.168.160.1 at Tue Dec 06 05:20:23 +0000 2011
Served asset /defaults.js - 404 Not Found (3ms)

ActionController::RoutingError (No route matches [GET] "/assets/defaults.js"):


Rendered /usr/local/lib/ruby/gems/1.8/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (0.5ms)

ldap config:

development:
  host: ldap.company.com
  port: 636
  attribute: mail
  base: ou=groupxx,o=company.com
  #admin_user: cn=admin,dc=test,dc=com
  #admin_password: admin_password
  ssl: true
  # <<: *AUTHORIZATIONS

我无法访问LDAP服务器,因此我无法从此确认任何内容。我遇到的主要问题是我无法从登录过程中收到任何错误消息 - 是否无法找到用户?它是否找到了用户但登录失败了?为什么要进行2次LDAP搜索?

3 个答案:

答案 0 :(得分:4)

同样的问题。做了一个ldapsearch,但是有效。公司在这里运行ActiveDirectory服务器:

ldapsearch -Z -h ldap.company.com -p 389 -s sub -D
"cn=somebody,ou=my_ou,dc=ldap,dc=company,dc=com" -W -b
"dc=ldap,dc=company,dc=com" "(&(cn=somebody))" mail

<强>解决方案:

我找到了解决方案:在config/initializers/devise.rb我错过了激活config.ldap_use_admin_to_bind = true。只有使用此标志,devise_ldap_authenticatable才真正使用在config/ldap.yml定义的BindDN(即admin_user,admin_password,两者都必须取消注释)。

答案 1 :(得分:3)

我发现我遇到的问题是我公司(IBM)使用的LDAP服务器使用的是与NET-LDAP正式支持的协议标准不同的协议标准。 您只需将PagedResults控件类型更改为略有不同的标准:

#PagedResults = "1.2.840.113556.1.4.319" # Microsoft evil from RFC 2696
PagedResults = "2.16.840.1.113730.3.4.2" # IBM Bluepages compatible ControlType

Full code change details here.

我把它分叉并修复了here on GitHub.

答案 2 :(得分:0)

我在ActiveDirectory上遇到了同样的问题。我尝试使用绑定用户,但它也没有帮助。我根据截屏视频210改变了设计以使用用户名字段。这是我的ldap.yml

  development:
  host: dcburda0
  port: 636
  attribute: cn
  base: OU=Organisation,DC=mydomain,DC=com
  admin_user: CN=username,OU=Support Center Muenchen,OU=name GmbH,OU=Organisation,DC=mydomain,DC=com
  admin_password: password
  ssl: true