Project

General

Profile

Defect #8978 » ldap_timeout_v2-redmine2.0.3.patch

LDAP Timeout patch - v2 - redmine 2.0.3 - Brett Patterson, 2012-06-30 04:10

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.
......
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
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
......
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
......
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)
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
app/views/auth_sources/_form_auth_source_ldap.html.erb (working copy)
<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>
(2-2/2)