Commit 44507069 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Use dn lookup for person. Collect group members dn when check for membership

parent d30a55a9
...@@ -12,7 +12,7 @@ module Gitlab ...@@ -12,7 +12,7 @@ module Gitlab
# if instance does not use group_base setting # if instance does not use group_base setting
return true unless Gitlab.config.ldap['group_base'].present? return true unless Gitlab.config.ldap['group_base'].present?
ldap_user = Gitlab::LDAP::Person.find(user.extern_uid) ldap_user = Gitlab::LDAP::Person.find_by_dn(user.extern_uid)
ldap_groups = ldap_user.groups ldap_groups = ldap_user.groups
ldap_groups_cn = ldap_groups.map(&:name) ldap_groups_cn = ldap_groups.map(&:name)
groups = ::Group.where(ldap_cn: ldap_groups_cn) groups = ::Group.where(ldap_cn: ldap_groups_cn)
......
...@@ -51,18 +51,18 @@ module Gitlab ...@@ -51,18 +51,18 @@ module Gitlab
end end
end end
def users(opts) def users(field, value)
if opts.respond_to? :key? if field.to_sym == :dn
key, uid = opts.keys.first, opts.values.first options = {
base: value
}
else else
key, uid = config.uid, opts || "*" options = {
base: config['base'],
filter: Net::LDAP::Filter.eq(field, value)
}
end end
options = {
base: config['base'],
filter: Net::LDAP::Filter.eq(key, uid)
}
entries = ldap.search(options).select do |entry| entries = ldap.search(options).select do |entry|
entry.respond_to? config.uid entry.respond_to? config.uid
end end
...@@ -72,8 +72,8 @@ module Gitlab ...@@ -72,8 +72,8 @@ module Gitlab
end end
end end
def user(opts) def user(*args)
users(opts).first users(*args).first
end end
private private
......
...@@ -19,24 +19,14 @@ module Gitlab ...@@ -19,24 +19,14 @@ module Gitlab
name.parameterize name.parameterize
end end
def members def memberuid?
member_uids.map do |opts| entry.respond_to? :memberuid
adapter.user(opts)
end.compact
end end
def member_uids def member_uids
if entry.respond_to? :memberuid entry.memberuid
entry.memberuid
else
member_dns.map do |dn|
dn_to_opts(dn)
end
end.compact
end end
private
def member_dns def member_dns
if entry.respond_to? :member if entry.respond_to? :member
entry.member entry.member
...@@ -49,6 +39,8 @@ module Gitlab ...@@ -49,6 +39,8 @@ module Gitlab
end end
end end
private
def entry def entry
@entry @entry
end end
...@@ -56,10 +48,6 @@ module Gitlab ...@@ -56,10 +48,6 @@ 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
...@@ -7,10 +7,12 @@ ...@@ -7,10 +7,12 @@
module Gitlab module Gitlab
module LDAP module LDAP
class Person class Person
def self.find(user_uid) def self.find_by_uid(uid)
id = user_uid.split(",").first Gitlab::LDAP::Adapter.new.user(config.uid, uid)
key, value = id.split("=") end
Gitlab::LDAP::Adapter.new.user(key => value)
def self.find_by_dn(dn)
Gitlab::LDAP::Adapter.new.user('dn', dn)
end end
def initialize(entry) def initialize(entry)
...@@ -29,9 +31,17 @@ module Gitlab ...@@ -29,9 +31,17 @@ module Gitlab
uid uid
end end
def dn
entry.dn
end
def groups def groups
adapter.groups.select do |group| adapter.groups.select do |group|
group.member_uids.include?(uid) if group.memberuid?
group.member_uids.include?(uid)
else
group.member_dns.include?(dn)
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