Hi all,
Another ldap newb question.
I can't seem to bind to the ldap server with a password. For example, this works:
# ldaptest.rb
require "ldap"
ldap_server = "ldap.foo.com"
password = "XXX"
ldap = LDAP::Conn.new(ldap_server)
ldap.simple_bind("cn=djberge,dc=foo,dc=bar,dc=com")
However, if I try to password as the second argument to simple_bind, I get an Invalid credentials (LDAP::ResultError). I'm positive the password is correct.
My main goal is to perform ldap authentication within a Rails controller. I thought I could just check success or failure on simple_bind, but that doesn't seem to be the case.
What am I doing wrong?
Thanks,
Dan
class LdapAdmin
def initialize()
@LDAP_SERVER = 'ldap.lse.ac.uk'
@LDAP_BASE_DN = 'dc=linux,dc=lse,dc=ac,dc=uk'
end
def login_connect?(login, password)
# test whether the login can connect to ldap with password
# -> true - yes
# -> false - no
require 'ldap'
flag = false
con = LDAP::Conn.new(@LDAP_SERVER)
con.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)
begin
con.bind("cn=#{login},#{@LDAP_BASE_DN}", password)
con.unbind()
flag = true
rescue LDAP::ResultError
flag = false
end
return flag
end
end
the above chunk of code works for me. the #{login} is admin and the password
is the one specified in /etc/ldap/slapd.conf file (basically, i use it to
log in to ldap admin account).
hope this helps,
vlad
http://pegacat.com/jxplorer/
helps me a lot with ldap.
vlad