base.rb 940 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Auth
  3. class Backend
  4. class Base
  5. delegate :user, :password, to: :auth
  6. attr_reader :config, :auth
  7. # Base initialization for Auth backend object.
  8. #
  9. # @param config [Hash] backend configuration hash.
  10. # @param auth [Auth] the Auth object for the authentication.
  11. #
  12. # @example
  13. # auth = Auth::Backend::Internal.new('admin@example.com', auth)
  14. def initialize(config, auth)
  15. @config = config
  16. @auth = auth
  17. end
  18. def valid?
  19. return false if password.blank? && password_required?
  20. return false if !perform?
  21. authenticated?
  22. end
  23. private
  24. def password_required?
  25. true
  26. end
  27. def perform?
  28. raise NotImplementedError
  29. end
  30. def authenticated?
  31. raise NotImplementedError
  32. end
  33. end
  34. end
  35. end