Commit d30a55a9 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Use LDAP user uid from config. Search by first value from user dn

parent 397282b4
......@@ -51,14 +51,20 @@ module Gitlab
end
end
def users(uid = "*")
def users(opts)
if opts.respond_to? :key?
key, uid = opts.keys.first, opts.values.first
else
key, uid = config.uid, opts || "*"
end
options = {
base: config['base'],
filter: Net::LDAP::Filter.eq(config.uid, uid)
filter: Net::LDAP::Filter.eq(key, uid)
}
entries = ldap.search(options).select do |entry|
entry.respond_to? :uid
entry.respond_to? config.uid
end
entries.map do |entry|
......@@ -66,8 +72,8 @@ module Gitlab
end
end
def user(uid)
users(uid).first
def user(opts)
users(opts).first
end
private
......
......@@ -20,8 +20,8 @@ module Gitlab
end
def members
member_uids.map do |uid|
adapter.user(uid)
member_uids.map do |opts|
adapter.user(opts)
end.compact
end
......@@ -30,7 +30,7 @@ module Gitlab
entry.memberuid
else
member_dns.map do |dn|
$1 if dn =~ /uid=([a-zA-Z0-9.-]+)/
dn_to_opts(dn)
end
end.compact
end
......@@ -56,6 +56,10 @@ module Gitlab
def adapter
@adapter ||= Gitlab::LDAP::Adapter.new
end
def dn_to_opts(dn)
dn.split(",").first.split("=")
end
end
end
end
......@@ -8,14 +8,9 @@ module Gitlab
module LDAP
class Person
def self.find(user_uid)
uid = if user_uid =~ /uid=([a-zA-Z0-9.-]+)/
$1
else
user_uid
end
Gitlab::LDAP::Adapter.new.user(uid)
id = user_uid.split(",").first
key, value = id.split("=")
Gitlab::LDAP::Adapter.new.user(key => value)
end
def initialize(entry)
......@@ -27,7 +22,7 @@ module Gitlab
end
def uid
entry.uid.join(" ")
entry.send(config.uid).join(" ")
end
def username
......@@ -49,6 +44,10 @@ module Gitlab
def adapter
@adapter ||= Gitlab::LDAP::Adapter.new
end
def config
@config ||= Gitlab.config.ldap
end
end
end
end
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