lib/net/ldap.rb in net-ldap-0.11 vs lib/net/ldap.rb in net-ldap-0.12.0
- old
+ new
@@ -25,11 +25,17 @@
require 'net/ldap/entry'
require 'net/ldap/instrumentation'
require 'net/ldap/connection'
require 'net/ldap/version'
require 'net/ldap/error'
+require 'net/ldap/auth_adapter'
+require 'net/ldap/auth_adapter/simple'
+require 'net/ldap/auth_adapter/sasl'
+Net::LDAP::AuthAdapter.register([:simple, :anon, :anonymous], Net::LDAP::AuthAdapter::Simple)
+Net::LDAP::AuthAdapter.register(:sasl, Net::LDAP::AuthAdapter::Sasl)
+
# == Quick-start for the Impatient
# === Quick Example of a user-authentication against an LDAP directory:
#
# require 'rubygems'
# require 'net/ldap'
@@ -430,18 +436,21 @@
ResultStrings[code] || "unknown result (#{code})"
end
attr_accessor :host
attr_accessor :port
+ attr_accessor :hosts
attr_accessor :base
# 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)
+ # * :hosts => an enumerable of pairs of hosts and corresponding ports with
+ # which to attempt opening connections (default [[host, port]])
# * :auth => a Hash containing authorization parameters. Currently
# supported values include: {:method => :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
@@ -466,10 +475,11 @@
# traffic to the LDAP server. It simply stores the connection and binding
# parameters in the object.
def initialize(args = {})
@host = args[:host] || DefaultHost
@port = args[:port] || DefaultPort
+ @hosts = args[:hosts]
@verbose = false # Make this configurable with a switch on the class.
@auth = args[:auth] || DefaultAuth
@base = args[:base] || DefaultTreebase
@force_no_page = args[:force_no_page] || DefaultForceNoPage
encryption args[:encryption] # may be nil
@@ -1193,10 +1203,17 @@
return false if @force_no_page
@server_caps ||= search_root_dse
@server_caps[:supportedcontrol].include?(Net::LDAP::LDAPControls::PAGED_RESULTS)
end
+ # Mask auth password
+ def inspect
+ inspected = super
+ inspected.gsub! @auth[:password], "*******" if @auth[:password]
+ inspected
+ end
+
private
# Yields an open connection if there is one, otherwise establishes a new
# connection, binds, and yields it. If binding fails, it will return the
# result from that, and :use_connection: will not yield at all. If not
@@ -1221,9 +1238,10 @@
# Establish a new connection to the LDAP server
def new_connection
Net::LDAP::Connection.new \
:host => @host,
:port => @port,
+ :hosts => @hosts,
:encryption => @encryption,
:instrumentation_service => @instrumentation_service
end
end # class LDAP