Index: config/locales/en.yml
===================================================================
--- config/locales/en.yml	(revision 9903)
+++ config/locales/en.yml	(working copy)
@@ -142,6 +142,7 @@
 
   notice_account_updated: Account was successfully updated.
   notice_account_invalid_creditentials: Invalid user or password
+  notice_account_authentication_timeout: Connection to authentication server timed out
   notice_account_password_updated: Password was successfully updated.
   notice_account_wrong_password: Wrong password
   notice_account_register_done: Account was successfully created. To activate your account, click on the link that was emailed to you.
@@ -323,6 +324,7 @@
   field_repository_is_default: Main repository
   field_multiple: Multiple values
   field_ldap_filter: LDAP filter
+  field_ldap_timeout: "Timeout (in seconds)"
 
   setting_app_title: Application title
   setting_app_subtitle: Application subtitle
Index: app/models/auth_source_ldap.rb
===================================================================
--- app/models/auth_source_ldap.rb	(revision 9903)
+++ app/models/auth_source_ldap.rb	(working copy)
@@ -18,6 +18,7 @@
 require 'iconv'
 require 'net/ldap'
 require 'net/ldap/dn'
+require 'timeout'
 
 class AuthSourceLdap < AuthSource
   validates_presence_of :host, :port, :attr_login
@@ -25,6 +26,7 @@
   validates_length_of :account, :account_password, :base_dn, :filter, :maximum => 255, :allow_blank => true
   validates_length_of :attr_login, :attr_firstname, :attr_lastname, :attr_mail, :maximum => 30, :allow_nil => true
   validates_numericality_of :port, :only_integer => true
+  validates_numericality_of :timeout, :only_integer => true, :allow_blank => true
   validate :validate_filter
 
   before_validation :strip_ldap_attributes
@@ -44,8 +46,17 @@
 
   def authenticate(login, password)
     return nil if login.blank? || password.blank?
-    attrs = get_user_dn(login, password)
 
+	begin
+		self.timeout = 20 if self.timeout.nil?
+		logger.error "LDAP Authentication timeout is set to '#{self.timeout}'"
+		Timeout::timeout(self.timeout) do
+	    	attrs = get_user_dn(login, password)
+		end
+	rescue Timeout::Error => e
+		raise Timeout::Error.new(e.message)
+	end
+
     if attrs && attrs[:dn] && authenticate_dn(attrs[:dn], password)
       logger.debug "Authentication successful for '#{login}'" if logger && logger.debug?
       return attrs.except(:dn)
Index: app/controllers/account_controller.rb
===================================================================
--- app/controllers/account_controller.rb	(revision 9903)
+++ app/controllers/account_controller.rb	(working copy)
@@ -150,6 +150,8 @@
       # Valid user
       successful_authentication(user)
     end
+  rescue Timeout::Error => e
+  	auth_source_timeout
   end
 
   def open_id_authenticate(openid_url)
@@ -229,6 +231,11 @@
     flash.now[:error] = l(:notice_account_invalid_creditentials)
   end
 
+  def auth_source_timeout
+  	logger.warn "Failed to authenticate user '#{params[:username]}' at #{Time.now.utc} because the authentication source connection timed out"
+	flash.now[:error] = l(:notice_account_authentication_timeout)
+  end
+
   # Register a user for email activation.
   #
   # Pass a block for behavior when a user fails to save
Index: app/views/auth_sources/_form_auth_source_ldap.html.erb
===================================================================
--- app/views/auth_sources/_form_auth_source_ldap.html.erb	(revision 9903)
+++ app/views/auth_sources/_form_auth_source_ldap.html.erb	(working copy)
@@ -26,6 +26,9 @@
 <p><label for="auth_source_custom_filter"><%=l(:field_ldap_filter)%></label>
 <%= text_field 'auth_source', 'filter', :size => 60 %></p>
 
+<p><label for="auth_source_timeout"><%=l(:field_ldap_timeout)%></label>
+<%= text_field 'auth_source', 'timeout', :size => 4 %></p>
+
 <p><label for="auth_source_onthefly_register"><%=l(:field_onthefly)%></label>
 <%= check_box 'auth_source', 'onthefly_register' %></p>
 </div>
