# Active\_Ldap Base Config Question

**URL:** <https://www.ruby-forum.com/t/active-ldap-base-config-question/178819>\
**Category:** Ruby\
**Created:** [November 11, 2009, 7:39pm UTC](https://www.ruby-forum.com/t/active-ldap-base-config-question/178819 "2009-11-11T19:39:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jackster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jackster](https://www.ruby-forum.com/u/jackster)\
**Post date:** [November 11, 2009, 7:39pm UTC](https://www.ruby-forum.com/t/active-ldap-base-config-question/178819/1 "2009-11-11T19:39:26Z")

</div>

I haven’t done much with polling AD in the past but I am now trying to  
write a basic script using active\_ldap that pulls a list of users from  
AD. The following code I have here doesn’t work but the thing that  
bothers me the most is that when I use a sniffer on the AD server, I  
don’t see any attempt by the script to communicate with the server.

require ‘rubygems’  
require ‘active\_ldap’

ActiveLdap::Base.setup\_connection(  
:host =\> “10.1.1.1”,  
:user =\> “admin”,  
:password =\> “password”,  
:base =\> “dc=voice,dc=company,dc=com”  
)  
all\_users = Group.find(:all, ‘\*’)  
puts all\_users

The actual error I get is:

/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active\_support/dependencies.rb:443:in  
`load\_missing\_constant’: uninitialized constant Group (NameError)

Any ideas as to why this basic config isn’t working?

Thanks

jack

---

<div class="post-metadata">

**Author:** ![jackster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jackster](https://www.ruby-forum.com/u/jackster)\
**Post date:** [November 11, 2009, 9:02pm UTC](https://www.ruby-forum.com/t/active-ldap-base-config-question/178819/2 "2009-11-11T21:02:57Z")

</div>

Haven’t used that particular gem (I use ActiveDirectory myself) but it  
looks  
like just a namespace issue. You haven’t included the namespace  
therefore  
you would require the full object path e.g. ActiveLdap::Group.find(:all,  
“\*”)

---

<div class="post-metadata">

**Author:** ![jackster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jackster](https://www.ruby-forum.com/u/jackster)\
**Post date:** [November 11, 2009, 9:21pm UTC](https://www.ruby-forum.com/t/active-ldap-base-config-question/178819/3 "2009-11-11T21:21:11Z")

</div>

Putting in the full object path renders the same error message, I’m  
afraid.

To be honest, I don’t have a preference toward Active\_Ldap, I just  
thought that it was the most common way to do AD lookups but if  
ActiveDirectory works for you, can you please give me a link to the  
binary (unleass it’s a gem?) and perhaps a sample of a base config?

thanks

jack

---

<div class="post-metadata">

**Author:** ![jackster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jackster](https://www.ruby-forum.com/u/jackster)\
**Post date:** [November 11, 2009, 10:48pm UTC](https://www.ruby-forum.com/t/active-ldap-base-config-question/178819/4 "2009-11-11T22:48:19Z")

</div>

Sorry I just assumed: are you running rails? That’s what I was using it  
with  
so I just made the assumption. Better question: What version of ruby and  
gem  
are you running?

---

<div class="post-metadata">

**Author:** ![jackster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jackster](https://www.ruby-forum.com/u/jackster)\
**Post date:** [November 11, 2009, 10:38pm UTC](https://www.ruby-forum.com/t/active-ldap-base-config-question/178819/5 "2009-11-11T22:38:22Z")

</div>

Ah, my bad. For every complex problem there is a solution that is clear,  
simple and wrong 🙂

The ActiveDirectory lib works for me but hasn’t been updated in a while.  
It  
can be found at:

[http://code.google.com/p/ruby-activedirectory/](http://code.google.com/p/ruby-activedirectory/)

Setup is fairly much the same:

ActiveDirectory::Base.server\_settings = {  
:host =\> “hostname or ip address”,  
:port =\> 3268,  
:username =\> “username”,  
:password =\> “password”,  
:domain =\> “your.ad.domain.here”,  
:base\_dn =\> “DC=your,DC=base,DC=dn”  
}

But I get the feeling that you might have the same issue. I seem to  
remember  
that this was a rails+gem version problem since I had this this same  
issue  
with the activedirectory gem once upon a time. What version of rails are  
you  
using? Did you upgrade it recently?

---

<div class="post-metadata">

**Author:** ![jackster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jackster](https://www.ruby-forum.com/u/jackster)\
**Post date:** [November 11, 2009, 10:52pm UTC](https://www.ruby-forum.com/t/active-ldap-base-config-question/178819/6 "2009-11-11T22:52:44Z")

</div>

Sven S. wrote:

> Sorry I just assumed: are you running rails? That’s what I was using it  
> with  
> so I just made the assumption. Better question: What version of ruby and  
> gem  
> are you running?

Yes, I’m running this directly through ruby version 1.8.6.

Gems is version 1.3.5

thanks

---

<div class="post-metadata">

**Author:** ![jackster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jackster](https://www.ruby-forum.com/u/jackster)\
**Post date:** [November 11, 2009, 11:08pm UTC](https://www.ruby-forum.com/t/active-ldap-base-config-question/178819/7 "2009-11-11T23:08:13Z")

</div>

I just installed and tried it and got the same thing. I read the docs  
and  
found that you need to subclass Base to get a mapping. e.g.

class User \< ActiveLdap::Base  
ldap\_mapping  
end

And the config is different. So here is what I got so far:

require ‘active\_ldap’

ActiveLdap::Base.setup\_connection(  
:host =\> “hostname”,  
:bind\_dn =\> “username”,  
:password =\> “passwords”,  
:base =\> “DC=your,DC=ldap,DC=base”  
)

class User \< ActiveLdap::Base  
ldap\_mapping  
end

That gets me the connection at least.

---

<div class="post-metadata">

**Author:** ![jackster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jackster](https://www.ruby-forum.com/u/jackster)\
**Post date:** [November 11, 2009, 11:23pm UTC](https://www.ruby-forum.com/t/active-ldap-base-config-question/178819/8 "2009-11-11T23:23:17Z")

</div>

unfortunately, that doesn’t give me a tcp connection either…but  
thanks for the effort

jack

---

<div class="post-metadata">

**Author:** ![jackster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jackster](https://www.ruby-forum.com/u/jackster)\
**Post date:** [November 12, 2009, 3:46pm UTC](https://www.ruby-forum.com/t/active-ldap-base-config-question/178819/9 "2009-11-12T15:46:46Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“Active\_Ldap Base Config Question” on Thu, 12 Nov 2009 03:39:28 +0900,  
jackster the jackle [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> :host =\> “10.1.1.1”,  
> /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active\_support/dependencies.rb:443:in  
> `load\_missing\_constant’: uninitialized constant Group (NameError)
> 
> Any ideas as to why this basic config isn’t working?

You need to define your Group class:  
class Group \< ActiveLdap::Base  
ldap\_mapping :dn\_attribute =\> “cn”,  
:classes =\> [‘posixGroup’]  
# Inspired by ActiveRecord, this tells ActiveLDAP that the  
# LDAP entry has a attribute which contains one or more of  
# some class |:class\_name| where the attributes name is  
# |:local\_key|. This means that it will call  
# :class\_name.new(value\_of(:local\_key)) to create the objects.  
has\_many :members, :class\_name =\> “User”, :wrap =\> “memberUid”  
has\_many :primary\_members, :class\_name =\> ‘User’,  
:foreign\_key =\> ‘gidNumber’,  
:primary\_key =\> ‘gidNumber’  
end # Group

# from

[http://code.google.com/p/ruby-activeldap/source/browse/trunk/examples/objects/group.rb](http://code.google.com/p/ruby-activeldap/source/browse/trunk/examples/objects/group.rb)

I confused the lines:

> all\_users = Group.find(:all, ‘\*’)  
> puts all\_users

Did you want to write like the following?  
all\_groups = Group.all  
puts all\_groups

Thanks,
