Wednesday, April 23, 2008


ActiveLDAP has some annoying install warts, but it's a pretty cool library.


First download and build RubyLDAP. Annoyingly this is NOT a gem, so you can't gem install it.

Next, build it ...
ruby extconf.rb
sudo make install

Now install ActiveLDAP ...

sudo gem install ruby-activeldap
Quick Start

Many of the examples are talking to a default openldap install. If you want to talk to a Mac OS X Open Dircetory server, you will need to change the prefix for users and groups, shown below in a quick sample app:

#!/usr/bin/env ruby

require 'rubygems'
require 'active_ldap'

class Group < ActiveLdap::Base
  ldap_mapping :dn_attribute => 'cn',
               :prefix => 'cn=groups',
               :classes => ['top', 'posixGroup'],
               :scope => :one
  has_many :members,
           :class => "User",
           :wrap => "memberUid",
           :primary_key => 'uid'

class User < ActiveLdap::Base
  ldap_mapping :dn_attribute => 'uid',
               :prefix => 'cn=users',
               :classes => ['top','inetOrgPerson']
  belongs_to :groups,
             :class => 'Group',
             :many => 'memberUid'

  :host => '',
  :port => 389,
  :base => 'dc=mdimension,dc=com',
  :bind_dn => "uid=mschrag,cn=mdimension,dc=com",
  :password => 'mschragpw',
  :allow_anonymous => false,
  :try_sasl => false

#Group.find(:all, '*').each do |group|
  #puts "#{}"
  #group.members.each do |member|
    #puts "  #{}"

user = User.find('mschrag');
user.givenName = 'NewFirstName'
And that's the quick start. It should give you enough to experiment with.