Commit cd85a558 authored by Tiago Botelho's avatar Tiago Botelho

Creates compound query for LDAP email attributes.

parent 718e5b08
......@@ -73,19 +73,27 @@ module Gitlab
private
def user_options(field, value, limit)
options = { attributes: Gitlab::LDAP::Person.ldap_attributes(config).compact.uniq }
filter = nil
options = {
attributes: Gitlab::LDAP::Person.ldap_attributes(config).compact.uniq,
base: config.base
}
options[:size] = limit if limit
if field.to_sym == :dn
case field.to_sym
when :dn
options[:base] = value
options[:scope] = Net::LDAP::SearchScope_BaseObject
options[:filter] = user_filter
when :email
filter = config.attributes['email'].map do |field|
Net::LDAP::Filter.eq(field, value)
end.inject(:|)
else
options[:base] = config.base
options[:filter] = user_filter(Net::LDAP::Filter.eq(field, value))
filter = Net::LDAP::Filter.eq(field, value)
end
options
options.merge(filter: user_filter(filter))
end
def user_filter(filter = nil)
......
......@@ -18,7 +18,7 @@ module Gitlab
end
def self.find_by_email(email, adapter)
Array(adapter.config.attributes['email']).find { |attr| adapter.user(attr, email) }
adapter.user('email', email)
end
def self.disabled_via_active_directory?(dn, adapter)
......
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