Skip to content

Commit 22333a0

Browse files
committed
Search directly against directory, simplify match check
Using GitHub::Ldap::Domain#search forces the base to the domain base (unsurprising yet surprising).
1 parent 9e008b7 commit 22333a0

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

lib/github/ldap/membership_validators/active_directory.rb

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,20 @@ module MembershipValidators
1515
# nested groups, performed on the server side.
1616
class ActiveDirectory < Base
1717
def perform(entry)
18-
domains.each do |domain|
19-
# search for the entry on the condition that the entry is a member
20-
# of one of the groups or their subgroups.
21-
#
22-
# Sets the entry to the base and scopes the search to the base,
23-
# according to the source documentation, found here:
24-
# http://msdn.microsoft.com/en-us/library/aa746475(v=vs.85).aspx
25-
matched = domain.search \
26-
filter: membership_in_chain_filter(entry),
27-
base: entry.dn,
28-
scope: Net::LDAP::SearchScope_BaseObject,
29-
attributes: ATTRS
18+
# search for the entry on the condition that the entry is a member
19+
# of one of the groups or their subgroups.
20+
#
21+
# Sets the entry to the base and scopes the search to the base,
22+
# according to the source documentation, found here:
23+
# http://msdn.microsoft.com/en-us/library/aa746475(v=vs.85).aspx
24+
matched = ldap.search \
25+
filter: membership_in_chain_filter(entry),
26+
base: entry.dn,
27+
scope: Net::LDAP::SearchScope_BaseObject,
28+
attributes: ATTRS
3029

31-
return true unless matched.empty?
32-
end
33-
34-
false
30+
# membership validated if entry was matched and returned as a result
31+
matched.map(&:dn).include?(entry.dn)
3532
end
3633

3734
# Internal: Constructs a membership filter using the "in chain"

0 commit comments

Comments
 (0)