I am trying to search ldap. This is doing successful authentication,
ldap connection is successful. Then when I make a search query it can
not read attributes from LDAP (AD). What is wrong here?


#!/usr/bin/env ruby
require "net-ldap"
$username = String.new

class ActiveDirectoryUser
SERVER = '10.10.10.10'
PORT = 389
BASE = 'DC=mydomain,DC=com'
DOMAIN = 'mydomain.com'

def self.authenticate(login, pass)
conn = Net::LDAP.new :host => SERVER,
:port => PORT,
:base => BASE,
:auth => { :username => "#{login}@#{DOMAIN}",
:password => pass,
:method => :simple }
if conn.bind
conn.search(
:base => BASE, :filter => Net::LDAP::Filter.eq(
"sAMAccountName", login ),
:attributes => %w[ givenName ], :return_result => true) do
entry|
puts "givenName: #{entry.givenName}"
$username = entry.givenName
end
return true

else
return false
end
rescue Net::LDAP::LdapError => e
return false
end
end

if ActiveDirectoryUser.authenticate('myusername', 'mypassword')
puts "Authentication Successful! The user is "+$username #I get this,
but blank username
else
puts "Authentication FAILED!"
end

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 1 | next ›
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedMar 26, '12 at 11:35p
activeMar 26, '12 at 11:35p
posts1
users1
websiterubyonrails.org
irc#RubyOnRails

1 user in discussion

Ruby User: 1 post

People

Translate

site design / logo © 2021 Grokbase