# LDAP Issues

**URL:** <https://discuss.rubyonrails.org/t/ldap-issues/28443>\
**Category:** rubyonrails-talk\
**Created:** [April 23, 2008, 12:40pm UTC](https://discuss.rubyonrails.org/t/ldap-issues/28443 "2008-04-23T12:40:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rory\_McKinley](https://avatars.discourse-cdn.com/v4/letter/r/6bbea6/32.png) [@Rory\_McKinley](https://discuss.rubyonrails.org/u/Rory_McKinley)\
**Post date:** [April 23, 2008, 12:40pm UTC](https://discuss.rubyonrails.org/t/ldap-issues/28443/1 "2008-04-23T12:40:26Z")

</div>

Hi All

I am at wits end trying to get LDAP to work in Rails running on ubuntu (yes, I'm a noob!). I have version 0.9.7 of ruby-ldap installed. Every thing seems fine, until I test in the console:

\>\> require 'ldap' =\> ["LDAP"] \>\> l = LDAP::Conn.new('xxxx.xxxx.xxxx.net', 389) =\> #\<LDAP::Conn:0xb74a4a40\> \>\> l.set\_option( LDAP::LDAP\_OPT\_PROTOCOL\_VERSION, 3 ) =\> #\<LDAP::Conn:0xb74a4a40\> \>\> l.bind('cn=xxxx,dc=xxxx,dc=xxxx,dc=xxxx', 'xxxxxxx') LDAP::ResultError: Can't contact LDAP server &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):4:in `bind' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):4

Now, it appears that a connection object is created, but yet it says that it can't contact the server. I can telnet to the relevant server so there is connectivity but further than that, I have no idea.

Any clues as to what might be causing this?

All help appreciated.

Rory

---

<div class="post-metadata">

**Author:** ![Craig\_White1](https://avatars.discourse-cdn.com/v4/letter/c/3ec8ea/32.png) [@Craig\_White1](https://discuss.rubyonrails.org/u/Craig_White1)\
**Post date:** [April 23, 2008, 5:41pm UTC](https://discuss.rubyonrails.org/t/ldap-issues/28443/2 "2008-04-23T17:41:03Z")

</div>

> Hi All
> 
> I am at wits end trying to get LDAP to work in Rails running on ubuntu (yes, I'm a noob!). I have version 0.9.7 of ruby-ldap installed. Every thing seems fine, until I test in the console:
> 
> \>\> require 'ldap' =\> ["LDAP"] \>\> l = LDAP::Conn.new('xxxx.xxxx.xxxx.net', 389) =\> #\<LDAP::Conn:0xb74a4a40\> \>\> l.set\_option( LDAP::LDAP\_OPT\_PROTOCOL\_VERSION, 3 ) =\> #\<LDAP::Conn:0xb74a4a40\> \>\> l.bind('cn=xxxx,dc=xxxx,dc=xxxx,dc=xxxx', 'xxxxxxx') LDAP::ResultError: Can't contact LDAP server &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):4:in `bind' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):4
> 
> Now, it appears that a connection object is created, but yet it says that it can't contact the server. I can telnet to the relevant server so there is connectivity but further than that, I have no idea.
> 
> Any clues as to what might be causing this?
> 
> All help appreciated.
> 
> Rory

---

<div class="post-metadata">

**Author:** ![IndyCodeWarrior](https://avatars.discourse-cdn.com/v4/letter/i/85e7bf/32.png) [@IndyCodeWarrior](https://discuss.rubyonrails.org/u/IndyCodeWarrior)\
**Post date:** [April 23, 2008, 5:58pm UTC](https://discuss.rubyonrails.org/t/ldap-issues/28443/3 "2008-04-23T17:58:25Z")

</div>

An LDAP object doesn't try to connect when it's created, so don't be surprised that succeeded. When you say you can telnet, was that to the standard port 23 or did you test 389.

---

<div class="post-metadata">

**Author:** ![Rory\_McKinley](https://avatars.discourse-cdn.com/v4/letter/r/6bbea6/32.png) [@Rory\_McKinley](https://discuss.rubyonrails.org/u/Rory_McKinley)\
**Post date:** [April 23, 2008, 7:11pm UTC](https://discuss.rubyonrails.org/t/ldap-issues/28443/4 "2008-04-23T19:11:58Z")

</div>

Mack Earnhardt wrote:

> An LDAP object doesn't try to connect when it's created, so don't be surprised that succeeded. When you say you can telnet, was that to the standard port 23 or did you test 389.

\<snip\> Hi

It was port 389. I also, at the suggestion of one of my colleagues, tried setting up Thunderbird to use the LDAP server for an address book. This worked perfectly, so, in terms of connectivity it seems to be working.

Does Rails store any debugging/error info that could help pinpoint a reason for this lack of connectivity?

Regards

Rory

---

<div class="post-metadata">

**Author:** ![Rory\_McKinley](https://avatars.discourse-cdn.com/v4/letter/r/6bbea6/32.png) [@Rory\_McKinley](https://discuss.rubyonrails.org/u/Rory_McKinley)\
**Post date:** [April 24, 2008, 4:24am UTC](https://discuss.rubyonrails.org/t/ldap-issues/28443/5 "2008-04-24T04:24:08Z")

</div>

Craig White wrote: \<snip\>

> ---- here's how I do it using ruby-ldap
> 
> \*\* my\_ldap.rb \*\* require "ldap" # Provides access to authenticate user from LDAP using the user provided user name and password class MyLDAP \< LDAP::Conn &nbsp;&nbsp;BASE\_DN = "dc=example,dc=com" &nbsp;&nbsp;PEOPLE\_DN = "ou=people,dc=example,dc=com" &nbsp;&nbsp;LDAP\_HOST = "server.example.com" &nbsp;&nbsp;LDAP\_PORT = 389 &nbsp;&nbsp;PROTOCOL\_VERSION = 3 &nbsp;&nbsp;# sets up connection to LDAP server &nbsp;&nbsp;def initialize (host = LDAP\_HOST, version = PROTOCOL\_VERSION) &nbsp;&nbsp;&nbsp;&nbsp;super( host, LDAP\_PORT ) &nbsp;&nbsp;&nbsp;&nbsp;set\_option( LDAP::LDAP\_OPT\_PROTOCOL\_VERSION, version ) &nbsp;&nbsp;&nbsp;&nbsp;return self &nbsp;&nbsp;end &nbsp;&nbsp;# Bind with the user supplied information &nbsp;&nbsp;def bind(mydn, pass) &nbsp;&nbsp;&nbsp;&nbsp;dn = "uid=" + mydn + "," + PEOPLE\_DN &nbsp;&nbsp;&nbsp;&nbsp;super( dn, pass ) &nbsp;&nbsp;end end

\<snip\>

Hi Craig

I will give this a try. Can you perhaps tell me why you use "super" in the method definitions?

Rory

---

<div class="post-metadata">

**Author:** ![Craig\_White2](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@Craig\_White2](https://discuss.rubyonrails.org/u/Craig_White2)\
**Post date:** [April 24, 2008, 4:48am UTC](https://discuss.rubyonrails.org/t/ldap-issues/28443/6 "2008-04-24T04:48:12Z")

</div>

> Craig White wrote: \<snip\> \> ---- \> here's how I do it using ruby-ldap \> \> \*\* my\_ldap.rb \*\* \> require "ldap" \> # Provides access to authenticate user from LDAP using the user provided \> user name and password \> class MyLDAP \< LDAP::Conn \> BASE\_DN = "dc=example,dc=com" \> PEOPLE\_DN = "ou=people,dc=example,dc=com" \> LDAP\_HOST = "server.example.com" \> LDAP\_PORT = 389 \> PROTOCOL\_VERSION = 3 \> # sets up connection to LDAP server \> def initialize (host = LDAP\_HOST, version = PROTOCOL\_VERSION) \> super( host, LDAP\_PORT ) \> set\_option( LDAP::LDAP\_OPT\_PROTOCOL\_VERSION, version ) \> return self \> end \> # Bind with the user supplied information \> def bind(mydn, pass) \> dn = "uid=" + mydn + "," + PEOPLE\_DN \> super( dn, pass ) \> end \> end \<snip\>
> 
> Hi Craig
> 
> I will give this a try. Can you perhaps tell me why you use "super" in the method definitions?

---

<div class="post-metadata">

**Author:** ![Craig\_White1](https://avatars.discourse-cdn.com/v4/letter/c/3ec8ea/32.png) [@Craig\_White1](https://discuss.rubyonrails.org/u/Craig_White1)\
**Post date:** [April 24, 2008, 4:05pm UTC](https://discuss.rubyonrails.org/t/ldap-issues/28443/7 "2008-04-24T16:05:08Z")

</div>

> \> Craig White wrote: \> \<snip\> \> \> ---- \> \> here's how I do it using ruby-ldap \> \> \> \> \*\* my\_ldap.rb \*\* \> \> require "ldap" \> \> # Provides access to authenticate user from LDAP using the user provided \> \> user name and password \> \> class MyLDAP \< LDAP::Conn \> \> BASE\_DN = "dc=example,dc=com" \> \> PEOPLE\_DN = "ou=people,dc=example,dc=com" \> \> LDAP\_HOST = "server.example.com" \> \> LDAP\_PORT = 389 \> \> PROTOCOL\_VERSION = 3 \> \> # sets up connection to LDAP server \> \> def initialize (host = LDAP\_HOST, version = PROTOCOL\_VERSION) \> \> super( host, LDAP\_PORT ) \> \> set\_option( LDAP::LDAP\_OPT\_PROTOCOL\_VERSION, version ) \> \> return self \> \> end \> \> # Bind with the user supplied information \> \> def bind(mydn, pass) \> \> dn = "uid=" + mydn + "," + PEOPLE\_DN \> \> super( dn, pass ) \> \> end \> \> end \> \<snip\> \> \> Hi Craig \> \> I will give this a try. Can you perhaps tell me why you use "super" in \> the method definitions? ---- It was years ago when I wrote this and I think I got it off the wiki ([http://wiki.rubyonrails.org](http://wiki.rubyonrails.org)) - I honestly don't remember but it worked really nicely.
