Commit 1fe67799 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

LDAP::Adapter#ldap_search method

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 4bcc244b
......@@ -62,7 +62,7 @@ module Gitlab
options.merge!(size: size) if size
ldap.search(options).map do |entry|
ldap_search(options).map do |entry|
Gitlab::LDAP::Group.new(entry, self)
end
end
......@@ -93,7 +93,7 @@ module Gitlab
end
end
entries = ldap.search(options).select do |entry|
entries = ldap_search(options).select do |entry|
entry.respond_to? config.uid
end
......@@ -107,14 +107,30 @@ module Gitlab
end
def dn_matches_filter?(dn, filter)
results = ldap.search(base: dn, filter: filter, attributes: %w{dn})
if results.nil?
results = ldap_search(base: dn, filter: filter, attributes: %w{dn})
if results.blank?
false # Net::LDAP encountered an LDAP error
else
results.any?
end
end
def ldap_search(*args)
results = ldap.search(*args)
if results.nil?
response = ldap.get_operation_result
unless response.code.zero?
Rails.logger.warn("LDAP search error: #{response.message}")
end
[]
else
results
end
end
private
def config
......
......@@ -9,7 +9,7 @@ module Gitlab
class Person
def self.find_by_uid(uid, adapter=nil)
adapter ||= Gitlab::LDAP::Adapter.new
adapter.user(config.uid, uid)
adapter.user(Gitlab.config.ldap.uid, uid)
end
def self.find_by_dn(dn, adapter=nil)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment