Commit d8ca6ed2 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 f41d277d
...@@ -9,7 +9,17 @@ module Gitlab ...@@ -9,7 +9,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 = {
...@@ -29,8 +39,12 @@ module Gitlab ...@@ -29,8 +39,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
# Get LDAP groups from ou=Groups # Get LDAP groups from ou=Groups
...@@ -95,7 +109,7 @@ module Gitlab ...@@ -95,7 +109,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