代码之家  ›  专栏  ›  技术社区  ›  smcdrc

有没有一种方法可以用电子邮件/密码验证用户对LDAP的身份?

  •  0
  • smcdrc  · 技术社区  · 14 年前

    有没有方法通过电子邮件(mail)验证用户对LDAP的身份? 不是CN还是DN?我们使用的是RubyLDAP,也可能是活动LDAP(不过,我们一直在使用它)。我们所需要做的就是验证一个用户,然后根据验证的成功在我们的系统中创建一个成员。

    1 回复  |  直到 14 年前
        1
  •  0
  •   clyfe    14 年前

    使用管理用户登录LDAP,并使用过滤器通过电子邮件和密码搜索用户:

    require 'rubygems'
    require 'net/ldap'
    
    ldap = Net::LDAP.new :host => server_ip_address,
         :port => 389,
         :auth => {
               :method => :simple,
               :username => "cn=manager,dc=example,dc=com",
               :password => "opensesame"
         }
    
    filter = Net::LDAP::Filter.eq( "email", "joe@email.com" )
    treebase = "ou=Users,dc=example,dc=com"
    
    @auth = false
    ldap.search( :base => treebase, :filter => filter ) do |entry|
        ldap2 = Net::LDAP.new :host => server_ip_address,
             :port => 389,
             :auth => {
                   :method => :simple,
                   :username => entry.dn,
                   :password => "joe's password"
             }
        @auth = true if ldap2.bind
    end
    
    puts "user authenticated" if @auth