sso.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 do |setting|
  19. if setting.state_current[:value]
  20. config.push setting.state_current[:value]
  21. end
  22. end
  23. # try to login against configure auth backends
  24. user_auth = nil
  25. config.each do |config_item|
  26. next if !config_item[:adapter]
  27. user_auth = config_item[:adapter].constantize.check( params, config_item )
  28. # auth not ok
  29. next if !user_auth
  30. Rails.logger.info "Authentication against #{config_item[:adapter]} for user #{user_auth.login} ok."
  31. # remember last login date
  32. user_auth.update_last_login
  33. return user_auth
  34. end
  35. nil
  36. end
  37. end