Project

General

Profile

Defect #8978 » ldap_timeout-v2.0.3.patch

Brett Patterson, 2012-06-29 04:32

View differences:

config/locales/en.yml (working copy)
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.
app/models/auth_source_ldap.rb (working copy)
require 'iconv'
require 'net/ldap'
require 'net/ldap/dn'
require 'timeout'
class AuthSourceLdap < AuthSource
validates_presence_of :host, :port, :attr_login
......
def authenticate(login, password)
return nil if login.blank? || password.blank?
attrs = get_user_dn(login, password)
timeout = 30 # TODO: Convert to setting
timoutStatus = nil
begin
timoutStatus = Timeout::timeout(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)
app/controllers/account_controller.rb (working copy)
# Valid user
successful_authentication(user)
end
rescue Timeout::Error => e
auth_source_timeout
end
def open_id_authenticate(openid_url)
......
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
(1-1/2)