@@ -707,15 +707,50 @@ def bind auth=@auth
707707
708708 #
709709 # #bind_as is for testing authentication credentials.
710- # Most likely a "standard" name (like a CN or an email
711- # address) will be presented along with a password.
712- # We'll bind with the main credential given in the
713- # constructor, query the full DN of the user given
714- # to us as a parameter, then unbind and rebind as the
715- # new user.
716710 #
717- # <i>This method is currently an unimplemented stub.</i>
711+ # As described under #bind, most LDAP servers require that you supply a complete DN
712+ # as a binding-credential, along with an authenticator such as a password.
713+ # But for many applications (such as authenticating users to a Rails application),
714+ # you often don't have a full DN to identify the user. You usually get a simple
715+ # identifier like a username or an email address, along with a password.
716+ # #bind_as allows you to authenticate these user-identifiers.
717+ #
718+ # #bind_as is a combination of a search and an LDAP binding. First, it connects and
719+ # binds to the directory as normal. Then it searches the directory for an entry
720+ # corresponding to the email address, username, or other string that you supply.
721+ # If the entry exists, then #bind_as will <b>re-bind</b> as that user with the
722+ # password (or other authenticator) that you supply.
723+ #
724+ # #bind_as takes the same parameters as #search, <i>with the addition of an
725+ # authenticator.</i> Currently, this authenticator must be <tt>:password</tt>.
726+ # Its value may be either a String, or a +proc+ that returns a String.
727+ # #bind_as returns +false+ on failure. On success, it returns a result set,
728+ # just as #search does. This result set is an Array of objects of
729+ # type Net::LDAP::Entry. It contains the directory attributes corresponding to
730+ # the user. (Just test whether the return value is logically true, if you don't
731+ # need this additional information.)
732+ #
733+ # Here's how you would use #bind_as to authenticate an email address and password:
718734 #
735+ # require 'net/ldap'
736+ #
737+ # user,psw = "joe_user@yourcompany.com", "joes_psw"
738+ #
739+ # ldap = Net::LDAP.new
740+ # ldap.host = "192.168.0.100"
741+ # ldap.port = 389
742+ # ldap.auth "cn=manager,dc=yourcompany,dc=com", "topsecret"
743+ #
744+ # result = ldap.bind_as(
745+ # :base => "dc=yourcompany,dc=com",
746+ # :filter => "(mail=#{user})",
747+ # :password => psw
748+ # )
749+ # if result
750+ # puts "Authenticated #{result.first.dn}"
751+ # else
752+ # puts "Authentication FAILED."
753+ # end
719754 def bind_as args = { }
720755 result = false
721756 open { |me |
0 commit comments