auth.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
  2. class Auth
  3. include ApplicationLib
  4. =begin
  5. authenticate user via username and password
  6. result = Auth.check( username, password, user )
  7. returns
  8. result = user_model # if authentication was successfully
  9. =end
  10. def self.check(username, password, user)
  11. # use std. auth backends
  12. config = [
  13. {
  14. :adapter => 'Auth::Internal',
  15. },
  16. {
  17. :adapter => 'Auth::Test',
  18. },
  19. ]
  20. # added configured backends
  21. Setting.where( :area => 'Security::Authentication' ).each {|setting|
  22. if setting.state[:value]
  23. config.push setting.state[:value]
  24. end
  25. }
  26. # try to login against configure auth backends
  27. user_auth = nil
  28. config.each {|config_item|
  29. next if !config_item[:adapter]
  30. # load backend
  31. backend = self.load_adapter( config_item[:adapter] )
  32. return if !backend
  33. user_auth = backend.check( username, password, config_item, user )
  34. # auth ok
  35. if user_auth
  36. # remember last login date
  37. user_auth.update_last_login
  38. return user_auth
  39. end
  40. }
  41. return
  42. end
  43. end