# Problem doing find in ActiveLdap

**URL:** <https://www.ruby-forum.com/t/problem-doing-find-in-activeldap/109840>\
**Category:** Ruby\
**Created:** [July 19, 2007, 3:32pm UTC](https://www.ruby-forum.com/t/problem-doing-find-in-activeldap/109840 "2007-07-19T15:32:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![claxo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b9e5f3/32.png) [@claxo](https://www.ruby-forum.com/u/claxo)\
**Post date:** [July 19, 2007, 3:32pm UTC](https://www.ruby-forum.com/t/problem-doing-find-in-activeldap/109840/1 "2007-07-19T15:32:57Z")

</div>

require ‘active\_ldap’

ActiveLdap::Base.establish\_connection(  
:host =\> ‘hostname’,  
:bind\_dn =\> ‘cn=admin,ou=users,dc=company,dc=it’,  
:base =\> ‘ou=addressbooks,dc=company,dc=it’,  
:password\_block =\> ‘admin’  
)

class Addressbook \< ActiveLdap::Base  
ldap\_mapping :dn\_attribute =\> ‘cn’, :prefix =\> ‘ou=addressbooks’  
end

p Addressbook.find(:all, ‘John’)  
p Addressbook.find(:all, :attribute =\> ‘givenName’, :value =\> ‘John’)

both find returns []

What am I doing wrong?

thanks

---

<div class="post-metadata">

**Author:** ![claxo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b9e5f3/32.png) [@claxo](https://www.ruby-forum.com/u/claxo)\
**Post date:** [July 20, 2007, 1:15am UTC](https://www.ruby-forum.com/t/problem-doing-find-in-activeldap/109840/2 "2007-07-20T01:15:16Z")

</div>

Hi,

2007/7/19, Claudio C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> ActiveLdap::Base.establish\_connection(  
> :host =\> ‘hostname’,  
> :bind\_dn =\> ‘cn=admin,ou=users,dc=company,dc=it’,  
> :base =\> ‘ou=addressbooks,dc=company,dc=it’,  
> :password\_block =\> ‘admin’  
> )

You need to pass Proc object to :password\_block or use :password  
with String.

> class Addressbook \< ActiveLdap::Base  
> ldap\_mapping :dn\_attribute =\> ‘cn’, :prefix =\> ‘ou=addressbooks’  
> end

In your configuration, you need to set :prefix to ‘’ because you already  
specify ‘ou=addressbooks,dc=company,dc=it’ as :base in  
establish\_connection. Or change :base to ‘dc=company,dc=it’ and keep  
:prefix ‘ou=addressbooks’.

Thanks,

---

<div class="post-metadata">

**Author:** ![claxo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b9e5f3/32.png) [@claxo](https://www.ruby-forum.com/u/claxo)\
**Post date:** [July 20, 2007, 9:45am UTC](https://www.ruby-forum.com/t/problem-doing-find-in-activeldap/109840/3 "2007-07-20T09:45:24Z")

</div>

Kouhei S. wrote:

> Hi,
> 
> 2007/7/19, Claudio C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > ActiveLdap::Base.establish\_connection(  
> > :host =\> ‘hostname’,  
> > :bind\_dn =\> ‘cn=admin,ou=users,dc=company,dc=it’,  
> > :base =\> ‘ou=addressbooks,dc=company,dc=it’,  
> > :password\_block =\> ‘admin’  
> > )
> 
> You need to pass Proc object to :password\_block or use :password  
> with String.
> 
> > class Addressbook \< ActiveLdap::Base  
> > ldap\_mapping :dn\_attribute =\> ‘cn’, :prefix =\> ‘ou=addressbooks’  
> > end
> 
> In your configuration, you need to set :prefix to ‘’ because you already  
> specify ‘ou=addressbooks,dc=company,dc=it’ as :base in  
> establish\_connection. Or change :base to ‘dc=company,dc=it’ and keep  
> :prefix ‘ou=addressbooks’.
> 
> Thanks,

I follow your directive and i added this:

pwb = Proc.new do |user|  
ActiveLdap::Command.read\_password("[#{user}] Password: ")  
end

…and works like a charm!!!

Thanks a lot!
