Method: Net::LDAP#initialize

Defined in:
lib/net/ldap.rb

#initialize(args = {}) ⇒ LDAP

Instantiate an object of type Net::LDAP to perform directory operations. This constructor takes a Hash containing arguments, all of which are either optional or may be specified later with other methods as described below. The following arguments are supported:

  • :host => the LDAP server’s IP-address (default 127.0.0.1)

  • :port => the LDAP server’s TCP port (default 389)

  • :auth => a Hash containing authorization parameters. Currently supported values include: => :anonymous and {:method => :simple, :username => your_user_name, :password => your_password } The password parameter may be a Proc that returns a String.

  • :base => a default treebase parameter for searches performed against the LDAP server. If you don’t give this value, then each call to #search must specify a treebase parameter. If you do give this value, then it will be used in subsequent calls to #search that do not specify a treebase. If you give a treebase value in any particular call to #search, that value will override any treebase value you give here.

  • :encryption => specifies the encryption to be used in communicating with the LDAP server. The value is either a Hash containing additional parameters, or the Symbol :simple_tls, which is equivalent to specifying the Hash => :simple_tls. There is a fairly large range of potential values that may be given for this parameter. See #encryption for details.

Instantiating a Net::LDAP object does not result in network traffic to the LDAP server. It simply stores the connection and binding parameters in the object.



373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
# File 'lib/net/ldap.rb', line 373

def initialize args = {}
  @host = args[:host] || DefaultHost
  @port = args[:port] || DefaultPort
  @verbose = false # Make this configurable with a switch on the class.
  @auth = args[:auth] || DefaultAuth
  @base = args[:base] || DefaultTreebase
  encryption args[:encryption] # may be nil

  if pr = @auth[:password] and pr.respond_to?(:call)
    @auth[:password] = pr.call
  end

  # This variable is only set when we are created with LDAP::open.
  # All of our internal methods will connect using it, or else
  # they will create their own.
  @open_connection = nil
end