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