From d2b1e693265b6279b1cb91b0b768e58544b192c4 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 25 May 2015 10:42:58 +0200 Subject: [PATCH] Improved error handling. --- lib/auth/developer.rb | 16 +++++++--------- lib/auth/internal.rb | 5 +++-- lib/auth/ldap.rb | 2 +- lib/auth/otrs.rb | 8 ++++---- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/auth/developer.rb b/lib/auth/developer.rb index 099fc824c..bdc26edc3 100644 --- a/lib/auth/developer.rb +++ b/lib/auth/developer.rb @@ -1,16 +1,14 @@ # Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ module Auth::Developer - def self.check( _username, password, _config, user ) + def self.check(username, password, _config, user) # development systems - if Setting.get('developer_mode') == true - if password == 'test' - Rails.logger.info "System in developer mode, authentication for user #{user.login} ok." - return user - end - end - - false + return false if !username + return false if !user + return false if Setting.get('developer_mode') != true + return false if password != 'test' + Rails.logger.info "System in developer mode, authentication for user #{user.login} ok." + user end end diff --git a/lib/auth/internal.rb b/lib/auth/internal.rb index fc3e1f0a2..d146b0c49 100644 --- a/lib/auth/internal.rb +++ b/lib/auth/internal.rb @@ -1,10 +1,11 @@ # Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/ module Auth::Internal - def self.check( _username, password, _config, user ) + def self.check(username, password, _config, user) # return if no user exists - return nil if !user + return false if !username + return false if !user # sha auth check if user.password =~ /^\{sha2\}/ diff --git a/lib/auth/ldap.rb b/lib/auth/ldap.rb index 5581defe0..b048a81d2 100644 --- a/lib/auth/ldap.rb +++ b/lib/auth/ldap.rb @@ -3,7 +3,7 @@ require 'net/ldap' module Auth::Ldap - def self.check( username, password, config, user ) + def self.check(username, password, config, user) scope = Net::LDAP::SearchScope_WholeSubtree diff --git a/lib/auth/otrs.rb b/lib/auth/otrs.rb index 1715789dc..f5785f549 100644 --- a/lib/auth/otrs.rb +++ b/lib/auth/otrs.rb @@ -3,7 +3,7 @@ require 'import/otrs' module Auth::Otrs - def self.check( username, password, config, user ) + def self.check(username, password, config, user) endpoint = Setting.get('import_otrs_endpoint') return false if !endpoint @@ -11,17 +11,17 @@ module Auth::Otrs return false if endpoint == 'http://otrs_host/otrs' # connect to OTRS - result = Import::OTRS.auth( username, password ) + result = Import::OTRS.auth(username, password) return false if !result return false if !result['groups_ro'] return false if !result['groups_rw'] return false if !result['user'] - user = User.where( login: result['user']['UserLogin'], active: true ).first + user = User.where(login: result['user']['UserLogin'], active: true).first return false if !user # sync / check permissions - Import::OTRS.permission_sync( user, result, config ) + Import::OTRS.permission_sync(user, result, config) user end