Module: SourceMonitor::Security::Authentication

Defined in:
lib/source_monitor/security/authentication.rb

Class Method Summary collapse

Class Method Details

.access_denied_by_default?(_controller = nil) ⇒ Boolean

Fail-closed predicate. The engine denies access when the host app has configured no authentication/authorization handler AND has not explicitly opted into open access. Configured handlers always win: when a handler is present the handler decides and this returns false.

Returns:

  • (Boolean)


38
39
40
41
42
# File 'lib/source_monitor/security/authentication.rb', line 38

def self.access_denied_by_default?(_controller = nil)
  return false if authentication_configured?

  !SourceMonitor.config.authentication.open_access
end

.authenticate!(controller) ⇒ Object



6
7
8
# File 'lib/source_monitor/security/authentication.rb', line 6

def self.authenticate!(controller)
  call_handler(SourceMonitor.config.authentication.authenticate_handler, controller)
end

.authenticate_configured?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/source_monitor/security/authentication.rb', line 48

def self.authenticate_configured?
  SourceMonitor.config.authentication.authenticate_handler.present?
end

.authentication_configured?Boolean

Returns:

  • (Boolean)


29
30
31
32
# File 'lib/source_monitor/security/authentication.rb', line 29

def self.authentication_configured?
  config = SourceMonitor.config.authentication
  config.authenticate_handler.present? || config.authorize_handler.present?
end

.authorize!(controller) ⇒ Object



10
11
12
# File 'lib/source_monitor/security/authentication.rb', line 10

def self.authorize!(controller)
  call_handler(SourceMonitor.config.authentication.authorize_handler, controller)
end

.authorize_configured?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/source_monitor/security/authentication.rb', line 44

def self.authorize_configured?
  SourceMonitor.config.authentication.authorize_handler.present?
end

.current_user(controller) ⇒ Object



14
15
16
17
# File 'lib/source_monitor/security/authentication.rb', line 14

def self.current_user(controller)
  method_name = preferred_current_user_method(controller)
  safe_public_send(controller, method_name)
end

.user_signed_in?(controller) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
# File 'lib/source_monitor/security/authentication.rb', line 19

def self.user_signed_in?(controller)
  method_name = preferred_user_signed_in_method(controller)

  if method_name
    safe_public_send(controller, method_name)
  else
    !!current_user(controller)
  end
end