Method: Net::LDAP#authenticate
- Defined in:
- lib/net/ldap.rb
#authenticate(username, password) ⇒ Object Also known as: auth
Convenience method to specify authentication credentials to the LDAP server. Currently supports simple authentication requiring a username and password.
Observe that on most LDAP servers, the username is a complete DN. However, with A/D, it’s often possible to give only a user-name rather than a complete DN. In the latter case, beware that many A/D servers are configured to permit anonymous (uncredentialled) binding, and will silently accept your binding as anonymous if you give an unrecognized username. This is not usually what you want. (See #get_operation_result.)
Important: The password argument may be a Proc that returns a string. This makes it possible for you to write client programs that solicit passwords from users or from other data sources without showing them in your code or on command lines.
require 'net/ldap'
ldap = Net::LDAP.new
ldap.host = server_ip_address
ldap.authenticate "cn=Your Username,cn=Users,dc=example,dc=com", "your_psw"
Alternatively (with a password block):
require 'net/ldap'
ldap = Net::LDAP.new
ldap.host = server_ip_address
psw = proc { your_psw_function }
ldap.authenticate "cn=Your Username,cn=Users,dc=example,dc=com", psw
423 424 425 426 |
# File 'lib/net/ldap.rb', line 423 def authenticate username, password password = password.call if password.respond_to?(:call) @auth = {:method => :simple, :username => username, :password => password} end |