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