Home Contact Download


Welcome to Bruno Bonfils's (aka asyd homepage).

Ruby ActiveLDAP

I'm currently playing with Ruby, Rails because I try to write a little RoR application as a frontend of the GUSES's LDAP Directory. Few days ago, I search for ruby and ldap, and find an ActiveRecord like for LDAP, named ActiveLDAP. It's really nice, ActiveLDAP maps a LDAP to a ruby object, which is schema's aware. It's now very simple to create, query a LDAP directory.

Here a little example which search for all users in ou=People and display their name.

require 'activeldap'
pwb = Proc.new {
class Membre < ActiveLDAP::Base
   ldap_mapping   :dnattr => "uid",
                  :classes => [ "top" , "person", "organizationalPerson", "inetOrgPerson" ],
                  :prefix => "ou=People"
   :user => "admin",
   :password_block => pwb,
   :bind_format => "cn=%s,dc=asyd,dc=net",
   :base => "dc=asyd,dc=net",
   :port => 389,
   :ldap_scope => 2,
   :host => "localhost" )
membres = Membre.find_all(:attribute => "objectClass", :objects => true, :value => "person")
membres.each do |membre|
   puts membre.cn