2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-08-16 06:49:32 +00:00
|
|
|
|
|
|
|
class Auth
|
|
|
|
class Backend
|
|
|
|
class Base
|
|
|
|
|
|
|
|
delegate :user, :password, to: :auth
|
|
|
|
|
|
|
|
attr_reader :config, :auth
|
|
|
|
|
|
|
|
# Base initialization for Auth backend object.
|
|
|
|
#
|
|
|
|
# @param config [Hash] backend configuration hash.
|
|
|
|
# @param auth [Auth] the Auth object for the authentication.
|
|
|
|
#
|
|
|
|
# @example
|
2021-08-17 12:10:02 +00:00
|
|
|
# auth = Auth::Backend::Internal.new('admin@example.com', auth)
|
2021-08-16 06:49:32 +00:00
|
|
|
def initialize(config, auth)
|
|
|
|
@config = config
|
|
|
|
@auth = auth
|
|
|
|
end
|
|
|
|
|
|
|
|
def valid?
|
2021-10-27 18:10:17 +00:00
|
|
|
return false if password.blank? && password_required?
|
2021-08-16 06:49:32 +00:00
|
|
|
return false if !perform?
|
|
|
|
|
|
|
|
authenticated?
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-10-27 18:10:17 +00:00
|
|
|
def password_required?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2021-08-16 06:49:32 +00:00
|
|
|
def perform?
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
def authenticated?
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|