@@ -34,6 +34,7 @@ class Ldap
3434 def_delegator :@connection , :open
3535
3636 attr_reader :uid , :search_domains , :virtual_attributes ,
37+ :membership_validator ,
3738 :instrumentation_service
3839
3940 # Build a new GitHub::Ldap instance
@@ -87,6 +88,9 @@ def initialize(options = {})
8788 # when a base is not explicitly provided.
8889 @search_domains = Array ( options [ :search_domains ] )
8990
91+ # configure which strategy should be used to validate user membership
92+ configure_membership_validation_strategy ( options [ :membership_validator ] )
93+
9094 # enables instrumenting queries
9195 @instrumentation_service = options [ :instrumentation_service ]
9296 end
@@ -182,6 +186,23 @@ def search(options, &block)
182186 end
183187 end
184188
189+ # Internal: Searches the host LDAP server's Root DSE for capabilities and
190+ # extensions.
191+ #
192+ # Returns a Net::LDAP::Entry object.
193+ def capabilities
194+ @capabilities ||=
195+ instrument "capabilities.github_ldap" do |payload |
196+ begin
197+ @connection . search_root_dse
198+ rescue Net ::LDAP ::LdapError => error
199+ payload [ :error ] = error
200+ # stubbed result
201+ Net ::LDAP ::Entry . new
202+ end
203+ end
204+ end
205+
185206 # Internal - Determine whether to use encryption or not.
186207 #
187208 # encryption: is the encryption method, either 'ssl', 'tls', 'simple_tls' or 'start_tls'.
@@ -214,5 +235,24 @@ def configure_virtual_attributes(attributes)
214235 VirtualAttributes . new ( false )
215236 end
216237 end
238+
239+ # Internal: Configure the membership validation strategy.
240+ #
241+ # Used by GitHub::Ldap::MembershipValidators::Detect to force a specific
242+ # strategy (instead of detecting host capabilities and deciding at runtime).
243+ #
244+ # If `strategy` is not provided, or doesn't match a known strategy,
245+ # defaults to `:detect`. Otherwise the configured strategy is selected.
246+ #
247+ # Returns the selected membership validator strategy Symbol.
248+ def configure_membership_validation_strategy ( strategy = nil )
249+ @membership_validator =
250+ case strategy . to_s
251+ when "classic" , "recursive" , "active_directory"
252+ strategy . to_sym
253+ else
254+ :detect
255+ end
256+ end
217257 end
218258end
0 commit comments