Class: Tasker::Authorization::BaseCoordinator
- Inherits:
-
Object
- Object
- Tasker::Authorization::BaseCoordinator
- Defined in:
- lib/tasker/authorization/base_coordinator.rb
Overview
Base authorization coordinator providing the foundation for authorization logic.
This class implements the core authorization interface that can be extended by host applications to provide custom authorization logic. It follows the same dependency injection pattern as the authentication system.
Host applications should inherit from this class and implement the
authorized?
method to provide their authorization logic.
Instance Attribute Summary collapse
-
#user ⇒ Object?
readonly
protected
The user object for authorization checks.
Instance Method Summary collapse
-
#authorization_enabled? ⇒ Boolean
protected
Check if authorization is enabled in the configuration.
-
#authorize!(resource, action, context = {}) ⇒ true
Authorize an action and raise an exception if not permitted.
-
#authorized?(_resource, _action, _context = {}) ⇒ Boolean
protected
Authorization logic to be implemented by subclasses.
-
#can?(resource, action, context = {}) ⇒ Boolean
Check if an action is authorized.
-
#initialize(user = nil) ⇒ BaseCoordinator
constructor
Initialize the authorization coordinator.
Constructor Details
#initialize(user = nil) ⇒ BaseCoordinator
Initialize the authorization coordinator
35 36 37 |
# File 'lib/tasker/authorization/base_coordinator.rb', line 35 def initialize(user = nil) @user = user end |
Instance Attribute Details
#user ⇒ Object? (readonly, protected)
The user object for authorization checks
109 110 111 |
# File 'lib/tasker/authorization/base_coordinator.rb', line 109 def user @user end |
Instance Method Details
#authorization_enabled? ⇒ Boolean (protected)
Check if authorization is enabled in the configuration
102 103 104 |
# File 'lib/tasker/authorization/base_coordinator.rb', line 102 def Tasker::Configuration.configuration.auth. end |
#authorize!(resource, action, context = {}) ⇒ true
Authorize an action and raise an exception if not permitted
This method checks authorization and raises an UnauthorizedError if the action is not permitted.
49 50 51 52 53 54 55 56 |
# File 'lib/tasker/authorization/base_coordinator.rb', line 49 def (resource, action, context = {}) unless can?(resource, action, context) raise UnauthorizedError, "Not authorized to #{action} on #{resource}" end true end |
#authorized?(_resource, _action, _context = {}) ⇒ Boolean (protected)
Authorization logic to be implemented by subclasses
This method should be overridden by host applications to provide their specific authorization logic. The default implementation denies all access.
93 94 95 96 97 |
# File 'lib/tasker/authorization/base_coordinator.rb', line 93 def (_resource, _action, _context = {}) # Default implementation: deny all access # Subclasses should override this method false end |
#can?(resource, action, context = {}) ⇒ Boolean
Check if an action is authorized
This method performs the authorization check without raising an exception.
It validates the resource and action exist, then delegates to the
authorized?
method for the actual authorization logic.
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/tasker/authorization/base_coordinator.rb', line 68 def can?(resource, action, context = {}) # Allow all actions if authorization is disabled return true unless # Validate resource and action exist in the registry unless ResourceRegistry.action_exists?(resource, action) raise ArgumentError, "Unknown resource:action '#{resource}:#{action}'" end # Delegate to subclass implementation (resource, action, context) end |