Skip to content

Instantly share code, notes, and snippets.

@johnivanoff
Created November 6, 2012 02:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnivanoff/4022050 to your computer and use it in GitHub Desktop.
Save johnivanoff/4022050 to your computer and use it in GitHub Desktop.
require 'sinatra'
require 'net/ldap'
ldap = Net::LDAP.new
ldap.host = '192.168.1.1'
ldap.port = 389
ldap.auth "username", "password"
get '/people/:id' do
filter = Net::LDAP::Filter.eq('cn', params[:id] + '*')
treebase = "dc=reputablecompany, dc=com"
ldap.search(:base => treebase, :filter => filter) do |entry|
puts "CN: #{entry.cn}"
if entry.respond_to?("company")
puts "Department: #{entry.company}"
end
end
p ldap.get_operation_result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment