Class: Ldap::LdapConnection
- Inherits:
-
Object
- Object
- Ldap::LdapConnection
- Includes:
- Slf4r::Logger
- Defined in:
- lib/adapters/ldap_adapter.rb
Overview
the class provides two ways of getting a LdapFacade. either one which is put on the current Thread or a new one
Instance Method Summary collapse
-
#current ⇒ Ldap::LdapFacade
Either the one from the current Thread or a new one.
-
#initialize(options) ⇒ LdapConnection
constructor
A new instance of LdapConnection.
-
#open ⇒ Object
puts a LdapFacade into the current thread and executes the given block.
Constructor Details
#initialize(options) ⇒ LdapConnection
Returns a new instance of LdapConnection.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/adapters/ldap_adapter.rb', line 13 def initialize() if [:facade].nil? require 'ldap/net_ldap_facade' @facade = ::Ldap::NetLdapFacade else case [:facade].to_sym when :ruby_ldap require 'ldap/ruby_ldap_facade' @facade = ::Ldap::RubyLdapFacade when :net_ldap require 'ldap/net_ldap_facade' @facade = ::Ldap::NetLdapFacade else "please add a :facade parameter to the adapter setup. possible values are :ruby_ldap or net_ldap" end end logger.info("using #{@facade}") @ldaps = { } @config = { :host => [:host], :port => [:port].to_i, :base => [:base] } if not [:bind_name].nil? then @config.update({ :auth => { :method => :simple, :username => [:bind_name], :password => [:password] } }) end if not [:adapter_options].nil? then [:adapter_options].each do |k,v| @config[k.to_sym] = v end end end |
Instance Method Details
#current ⇒ Ldap::LdapFacade
Returns either the one from the current Thread or a new one.
69 70 71 72 73 74 75 76 |
# File 'lib/adapters/ldap_adapter.rb', line 69 def current ldap = @ldaps[Thread.current] if ldap ldap else @facade.new(@config) end end |
#open ⇒ Object
puts a LdapFacade into the current thread and executes the given block.
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/adapters/ldap_adapter.rb', line 56 def open begin @facade.open(@config) do |ldap| @ldaps[Thread.current] = @facade.new(ldap) yield end ensure @ldaps[Thread.current] = nil end end |