Jeremy Smith's blog

Entry Is Labelled

First Steps with Ruby's ActiveLDAP

Mmmm... Ruby/ActiveLDAP fun:

require 'activeldap'

class User < ActiveLDAP::Base
  ldap_mapping :dnattr => 'uid', :prefix => ''
end

print "What's your username: "
user = gets.strip
print "What's your password: "
pass = gets.strip

puts "\nHere's your LDAP record:\n\n----"

ActiveLDAP::Base.connect(:host => 'ldap.cwru.edu',
                         :port => 389,
                         :base => 'ou=People,o=cwru.edu,o=isp',
                         :bind_format => 'uid=%s,ou=People,o=cwru.edu,o=isp',
                         :user => user,
                         :password_block => Proc.new { pass } )

user = User.new(user)

user.attributes.sort_by{ |attr| attr }.each{ |attr| 
  user.send(attr.to_sym).each{ |value| puts "#{attr}: #{value}" }
}

Comments