Defect #8978 » ldap_timeout-v2.0.3.patch
config/locales/en.yml (working copy) | ||
---|---|---|
142 | 142 | |
143 | 143 |
notice_account_updated: Account was successfully updated. |
144 | 144 |
notice_account_invalid_creditentials: Invalid user or password |
145 |
notice_account_authentication_timeout: Connection to authentication server timed out |
|
145 | 146 |
notice_account_password_updated: Password was successfully updated. |
146 | 147 |
notice_account_wrong_password: Wrong password |
147 | 148 |
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) | ||
---|---|---|
18 | 18 |
require 'iconv' |
19 | 19 |
require 'net/ldap' |
20 | 20 |
require 'net/ldap/dn' |
21 |
require 'timeout' |
|
21 | 22 | |
22 | 23 |
class AuthSourceLdap < AuthSource |
23 | 24 |
validates_presence_of :host, :port, :attr_login |
... | ... | |
44 | 45 | |
45 | 46 |
def authenticate(login, password) |
46 | 47 |
return nil if login.blank? || password.blank? |
47 |
attrs = get_user_dn(login, password) |
|
48 | 48 | |
49 |
timeout = 30 # TODO: Convert to setting |
|
50 |
timoutStatus = nil |
|
51 |
begin |
|
52 |
timoutStatus = Timeout::timeout(timeout) do |
|
53 |
attrs = get_user_dn(login, password) |
|
54 |
end |
|
55 |
rescue Timeout::Error => e |
|
56 |
raise Timeout::Error.new(e.message) |
|
57 |
end |
|
58 | ||
49 | 59 |
if attrs && attrs[:dn] && authenticate_dn(attrs[:dn], password) |
50 | 60 |
logger.debug "Authentication successful for '#{login}'" if logger && logger.debug? |
51 | 61 |
return attrs.except(:dn) |
app/controllers/account_controller.rb (working copy) | ||
---|---|---|
150 | 150 |
# Valid user |
151 | 151 |
successful_authentication(user) |
152 | 152 |
end |
153 |
rescue Timeout::Error => e |
|
154 |
auth_source_timeout |
|
153 | 155 |
end |
154 | 156 | |
155 | 157 |
def open_id_authenticate(openid_url) |
... | ... | |
229 | 231 |
flash.now[:error] = l(:notice_account_invalid_creditentials) |
230 | 232 |
end |
231 | 233 | |
234 |
def auth_source_timeout |
|
235 |
logger.warn "Failed to authenticate user '#{params[:username]}' at #{Time.now.utc} because the authentication source connection timed out" |
|
236 |
flash.now[:error] = l(:notice_account_authentication_timeout) |
|
237 |
end |
|
238 | ||
232 | 239 |
# Register a user for email activation. |
233 | 240 |
# |
234 | 241 |
# Pass a block for behavior when a user fails to save |