From a70737ad592cb6c695db29dc1c3579f616877175 Mon Sep 17 00:00:00 2001
From: Jean-Philippe Lang <jp_lang@yahoo.fr>
Date: Wed, 5 Mar 2008 12:43:14 +0000
Subject: [PATCH] Fixed "LdapError: invalid binding information" when no
 username/password are set on the LDAP account (#764).

git-svn-id: http://redmine.rubyforge.org/svn/trunk@1194 e93f8b46-1217-0410-a6f0-8f06a7374b81
---
 app/models/auth_source_ldap.rb | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/app/models/auth_source_ldap.rb b/app/models/auth_source_ldap.rb
index 5a6789a3b..b4966c1e8 100644
--- a/app/models/auth_source_ldap.rb
+++ b/app/models/auth_source_ldap.rb
@@ -70,11 +70,12 @@ class AuthSourceLdap < AuthSource
   
 private
   def initialize_ldap_con(ldap_user, ldap_password)
-    Net::LDAP.new( {:host => self.host, 
-                    :port => self.port, 
-                    :auth => { :method => :simple, :username => ldap_user, :password => ldap_password },
-                    :encryption => (self.tls ? :simple_tls : nil)} 
-    ) 
+    options = { :host => self.host,
+                :port => self.port,
+                :encryption => (self.tls ? :simple_tls : nil)
+              }
+    options.merge(:auth => { :method => :simple, :username => ldap_user, :password => ldap_password }) unless ldap_user.blank? && ldap_password.blank?
+    Net::LDAP.new options
   end
   
   def self.get_attr(entry, attr_name)
-- 
GitLab