backend.rb 1022 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Auth
  3. class Backend
  4. attr_reader :auth
  5. def initialize(auth)
  6. @auth = auth
  7. end
  8. def valid?
  9. instances.any? do |instance|
  10. next if !instance.valid?
  11. Rails.logger.info "Authentication against #{instance.class.name} for user #{auth.user.login} ok."
  12. true
  13. end
  14. end
  15. private
  16. def instances
  17. configs.filter_map do |config|
  18. config[:adapter].constantize.new(config, auth)
  19. rescue => e
  20. Rails.logger.error "Failed to load Auth::Backend from Setting '#{config}'"
  21. Rails.logger.error e
  22. nil
  23. end
  24. end
  25. def configs
  26. Setting.where(area: 'Security::Authentication')
  27. .map { |setting| setting.state_current[:value] } # extract current Setting value as config
  28. .compact_blank
  29. .sort { |a, b| a.fetch(:priority, 999) <=> b.fetch(:priority, 999) } # sort by priority and fallback to append if not set
  30. end
  31. end
  32. end