Skip to content

Instantly share code, notes, and snippets.

@mroch
Created October 23, 2009 21:13
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 mroch/217192 to your computer and use it in GitHub Desktop.
Save mroch/217192 to your computer and use it in GitHub Desktop.
class CmuLdap
BASE_DN = 'ou=Person, dc=cmu, dc=edu'
def self.find_by_principal_name(name)
new.search(:filter => Net::LDAP::Filter.eq('cmuPersonPrincipalName', name))
end
def self.find_by_andrew_id(username)
new.search(:filter => Net::LDAP::Filter.eq('cmuAndrewID', username))
end
def initialize
@ldap = Net::LDAP.new(:host => 'ldap.andrew.cmu.edu', :port => 389)
end
def search(opts = {})
options = {
:base => BASE_DN,
:attributes => [
'givenName', 'sn', 'nickname', 'eduPersonSchoolCollegeName',
'cmuStudentClass', 'mail', 'cmuPreferredMail'
]
}.merge!(opts)
@ldap.search(options) do |entry|
results = {}
entry.each do |attribute, values|
results[attribute] = values.first
end
return results
end
return nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment