sso.rb 1.1 KB

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