设计LDAP Authenticatable是否绑定不正确?

时间:2012-12-10 20:07:15

标签: ruby-on-rails devise ldap

出于某种原因,在我的页面上使用Devise进行身份验证似乎无法正常工作,从而导致出现未经授权的401错误。通过net / ldap中的步骤似乎绑定得很好。我不确定问题出在哪里。

服务器输出:

Processing by Devise::SessionsController#create as HTML
  Parameters: {"utf8"=>"â", "authenticity_token"=>"0uaLJJKobrDkn1mGDRP/RM6gIec+Wi7oykgWYuutsvk=", "user"=>{"login"=><login>, "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
Completed 401 Unauthorized in 14ms

来自ldap.yml:

development:
  host: <hostname>
  port: 389
  attribute: sAMAccountName
  base: <base>
  admin_user: <admin user>
  admin_password: <admin pass>
  ssl: false
  # <<: *AUTHORIZATIONS

来自devise.rb:

config.ldap_use_admin_to_bind = true
config.authentication_keys = [ :login ]

来自irb的测试:

$ irb
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'net/ldap'
=> true
irb(main):003:0> ldap = Net::LDAP.new
=> #<Net::LDAP:0x141d19 @host="127.0.0.1", @auth={:method=>:anonymous}, @encryption=nil, @base="dc=com", @port=389, @verbose=false, @open_connection=nil>
irb(main):004:0> ldap.host = <hostname>
=> <hostname>
irb(main):005:0> ldap.port = 389
=> 389
irb(main):006:0> ldap.base = <base>
=> <base>
irb(main):007:0> ldap.auth <admin user>, <admin pass>
=> {:method=>:simple, :username=><admin user>, :password=><admin pass>}
irb(main):008:0> dn = ldap.search( :filter => Net::LDAP::Filter.eq('sAMAccountName', <login>)).first.dn
=> <login dn information>
irb(main):009:0> ldap.auth dn, <password>
=> {:method=>:simple, :username=><login dn information>, :password=><password>}
irb(main):010:0> ldap.bind
=> true

正如您所看到的,绑定在正常的net / ldap测试中运行良好,但是当我出于某种原因浏览实际的Rails站点时它似乎无法工作,即使我复制了Devise模块应该正在做。

2 个答案:

答案 0 :(得分:0)

身份验证密钥不是:login但是:username。它可能会解决你的问题

答案 1 :(得分:0)

如果有其他人遇到此问题,this question会向我提供我需要的修复程序。