Created
October 23, 2009 21:13
-
-
Save mroch/217192 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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