Skip to content

Commit 39ec12a

Browse files
author
blackhedd
committed
supported Proc objects as passwords.
1 parent d4c19ee commit 39ec12a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/net/ldap.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ def LDAP::result2string code # :nodoc:
335335
# * :auth => a Hash containing authorization parameters. Currently supported values include:
336336
# {:method => :anonymous} and
337337
# {:method => :simple, :username => your_user_name, :password => your_password }
338+
# The password parameter may be a Proc that returns a String.
338339
#
339340
# Instantiating a Net::LDAP object does <i>not</i> result in network traffic to
340341
# the LDAP server. It simply stores the connection and binding parameters in the
@@ -347,6 +348,10 @@ def initialize args = {}
347348
@auth = args[:auth] || DefaultAuth
348349
@base = args[:base] || DefaultTreebase
349350

351+
if pr = @auth[:password] and pr.respond_to?(:call)
352+
@auth[:password] = pr.call
353+
end
354+
350355
# This variable is only set when we are created with LDAP::open.
351356
# All of our internal methods will connect using it, or else
352357
# they will create their own.
@@ -357,13 +362,15 @@ def initialize args = {}
357362
# server. Currently supports simple authentication requiring
358363
# a username and password. Observe that on most LDAP servers,
359364
# including A/D, the username is a complete DN.
365+
# The password argument may be a Proc that returns a string.
360366
# require 'net/ldap'
361367
#
362368
# ldap = Net::LDAP.new
363369
# ldap.host = server_ip_address
364370
# ldap.authenticate "cn=Your Username,cn=Users,dc=example,dc=com", "your_psw"
365371
#
366372
def authenticate username, password
373+
password = password.call if password.respond_to?(:call)
367374
@auth = {:method => :simple, :username => username, :password => password}
368375
end
369376

0 commit comments

Comments
 (0)