Skip to content

Commit

Permalink
get cn from dn
Browse files Browse the repository at this point in the history
  • Loading branch information
shanhong cheng committed Sep 1, 2017
1 parent 53982b4 commit a827f3c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/lib/directory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ def self.create_or_update_database_from_ldap(ldap_results, db_results)
end
end

def self.get_cn_from_dn(dn)
dn.split(',')[0].split('=')[1]
end

# search and merge results but don't change the database
# this assumes USE_LDAP = true, otherwise you wouldn't use this function
def self.search_and_merge_ldap_and_database_results(term)
Expand All @@ -218,7 +222,7 @@ def self.search_and_merge_ldap_and_database_results(term)
end
ldap_results = Directory.search_ldap(term)
ldap_results.each do |ldap_result|
uid = "#{ldap_result[LDAP_UID].try(:first).try(:downcase)}@#{DOMAIN}"
uid = self.get_cn_from_dn("#{ldap_result[LDAP_UID].try(:first).try(:downcase)}@#{DOMAIN}")
if identities[uid]
results << identities[uid]
else
Expand Down

0 comments on commit a827f3c

Please sign in to comment.