sso.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Copyright (C) 2012-2013 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. :adapter => 'Sso::Otrs',
  18. :required_group_ro => 'stats',
  19. :group_rw_role_map => {
  20. 'admin' => 'Admin',
  21. 'stats' => 'Report',
  22. },
  23. :group_ro_role_map => {
  24. 'stats' => 'Report',
  25. },
  26. :always_role => {
  27. 'Agent' => true,
  28. },
  29. },
  30. ]
  31. # added configured backends
  32. Setting.where( :area => 'Security::SSO' ).each {|setting|
  33. if setting.state[:value]
  34. config.push setting.state[:value]
  35. end
  36. }
  37. # try to login against configure auth backends
  38. user_auth = nil
  39. config.each {|config_item|
  40. next if !config_item[:adapter]
  41. # load backend
  42. backend = self.load_adapter( config_item[:adapter] )
  43. return if !backend
  44. user_auth = backend.check( params, config_item )
  45. # auth ok
  46. if user_auth
  47. # remember last login date
  48. user_auth.update_last_login
  49. return user_auth
  50. end
  51. }
  52. return
  53. end
  54. end