Commit af53aa90 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Add Gitlab::LDAP::Adapter.open

This new method is based on Net::LDAP.open, which reuses a single LDAP
connection.
parent 5a616649
...@@ -3,7 +3,17 @@ module Gitlab ...@@ -3,7 +3,17 @@ module Gitlab
class Adapter class Adapter
attr_reader :ldap attr_reader :ldap
def initialize def self.open(&block)
Net::LDAP.open(adapter_options) do |ldap|
block.call(self.new(ldap))
end
end
def self.config
Gitlab.config.ldap
end
def self.adapter_options
encryption = config['method'].to_s == 'ssl' ? :simple_tls : nil encryption = config['method'].to_s == 'ssl' ? :simple_tls : nil
options = { options = {
...@@ -23,8 +33,12 @@ module Gitlab ...@@ -23,8 +33,12 @@ module Gitlab
if config['password'] || config['bind_dn'] if config['password'] || config['bind_dn']
options.merge!(auth_options) options.merge!(auth_options)
end end
options
end
@ldap = Net::LDAP.new(options) def initialize(ldap=nil)
@ldap = ldap || Net::LDAP.new(self.class.adapter_options)
end end
def users(field, value) def users(field, value)
...@@ -65,7 +79,7 @@ module Gitlab ...@@ -65,7 +79,7 @@ module Gitlab
private private
def config def config
@config ||= Gitlab.config.ldap @config ||= self.class.config
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