Class: VectorMCP::Security::Authorization
- Inherits:
-
Object
- Object
- VectorMCP::Security::Authorization
- Defined in:
- lib/vector_mcp/security/authorization.rb
Overview
Manages authorization policies for VectorMCP servers Provides fine-grained access control for tools and resources
Instance Attribute Summary collapse
-
#enabled ⇒ Object
readonly
Returns the value of attribute enabled.
-
#policies ⇒ Object
readonly
Returns the value of attribute policies.
Instance Method Summary collapse
-
#add_policy(resource_type, &block) ⇒ Object
Add an authorization policy for a resource type.
-
#authorize(user, action, resource) ⇒ Boolean
Check if a user is authorized to perform an action on a resource.
-
#disable! ⇒ Object
Disable authorization (return to pass-through mode).
-
#enable! ⇒ Object
Enable authorization system.
-
#initialize ⇒ Authorization
constructor
A new instance of Authorization.
-
#policy_types ⇒ Array<Symbol>
Get list of resource types with policies.
-
#remove_policy(resource_type) ⇒ Object
Remove an authorization policy.
-
#required? ⇒ Boolean
Check if authorization is required.
Constructor Details
#initialize ⇒ Authorization
Returns a new instance of Authorization.
10 11 12 13 14 |
# File 'lib/vector_mcp/security/authorization.rb', line 10 def initialize @policies = {} @enabled = false @logger = VectorMCP.logger_for("authorization") end |
Instance Attribute Details
#enabled ⇒ Object (readonly)
Returns the value of attribute enabled.
8 9 10 |
# File 'lib/vector_mcp/security/authorization.rb', line 8 def enabled @enabled end |
#policies ⇒ Object (readonly)
Returns the value of attribute policies.
8 9 10 |
# File 'lib/vector_mcp/security/authorization.rb', line 8 def policies @policies end |
Instance Method Details
#add_policy(resource_type, &block) ⇒ Object
Add an authorization policy for a resource type
29 30 31 |
# File 'lib/vector_mcp/security/authorization.rb', line 29 def add_policy(resource_type, &block) @policies[resource_type] = block end |
#authorize(user, action, resource) ⇒ Boolean
Check if a user is authorized to perform an action on a resource
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/vector_mcp/security/authorization.rb', line 44 def (user, action, resource) return true unless @enabled resource_type = determine_resource_type(resource) policy = @policies[resource_type] return true unless policy !!policy.call(user, action, resource) rescue StandardError => e @logger.error("Authorization policy error for #{resource_type}: #{e.}") false end |
#disable! ⇒ Object
Disable authorization (return to pass-through mode)
22 23 24 |
# File 'lib/vector_mcp/security/authorization.rb', line 22 def disable! @enabled = false end |
#enable! ⇒ Object
Enable authorization system
17 18 19 |
# File 'lib/vector_mcp/security/authorization.rb', line 17 def enable! @enabled = true end |
#policy_types ⇒ Array<Symbol>
Get list of resource types with policies
65 66 67 |
# File 'lib/vector_mcp/security/authorization.rb', line 65 def policy_types @policies.keys end |
#remove_policy(resource_type) ⇒ Object
Remove an authorization policy
35 36 37 |
# File 'lib/vector_mcp/security/authorization.rb', line 35 def remove_policy(resource_type) @policies.delete(resource_type) end |
#required? ⇒ Boolean
Check if authorization is required
59 60 61 |
# File 'lib/vector_mcp/security/authorization.rb', line 59 def required? @enabled end |