How to make ldap work with devise in rails?

2019-07-28 05:03发布

问题:

I am using devise and i try to use ldap and all my attempts resulted in failure. I have followed http://vimeo.com/13105005 and I am really looking for help.

Started POST "/users/sign_in" for 127.0.0.1 at 2013-04-16 18:01:54 +0530
Processing by Devise::SessionsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"N7Xkqk8nHWqK4tgiCxyX4wFccSO8ozhy+nxXqS19arA=", "user"=>{"email"=>"logesh@gmail.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
WARNING: Can't verify CSRF token authenticity
  User Load (0.6ms)  SELECT "users".* FROM "users" WHERE "users"."email" = 'logesh@gmail.com' LIMIT 1
  LDAP: LDAP dn lookup: cn=logesh@gmail.com
  LDAP: LDAP search for login: cn=logesh@gmail.com
  LDAP: Authorizing user cn=logesh@gmail.com,dc=server,dc=local
  LDAP: LDAP dn lookup: cn=logesh@gmail.com
  LDAP: LDAP search for login: cn=logesh@gmail.com
DEPRECATION WARNING: an empty resource was given to Devise::Strategies::LdapAuthenticatable#validate. Please ensure the resource is not nil. (called from service at /Users/logesh/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/webrick/httpserver.rb:111)
Completed 401 Unauthorized in 13ms
Processing by Devise::SessionsController#new as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"N7Xkqk8nHWqK4tgiCxyX4wFccSO8ozhy+nxXqS19arA=", "user"=>{"email"=>"logesh@gmail.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
WARNING: Can't verify CSRF token authenticity
  Rendered devise/shared/_links.erb (0.4ms)
  Rendered devise/sessions/new.html.erb within layouts/application (3.1ms)
Completed 200 OK in 8ms (Views: 6.5ms | ActiveRecord: 0.0ms)

I do not know how to step forward. I am struggling with this for about 2 days and still could not resolve.

when i signup the user is saved in user model but login doesnt work. please help me.

回答1:

Is it possible that in the LDAP directory you are using, rather than the naming attribute being cn=logesh@gmail.com, rather the mail attribute has that value, and the full DN is something other than: cn=logesh@gmail.com,dc=server,dc=local

Thus, your config, if possible should search for mail=logesh@gmail.com to then get the DN from that user object to then attempt to bind.