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 |
# File 'lib/vector_mcp/security/authorization.rb', line 10 def initialize @policies = {} @enabled = false 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
28 29 30 |
# File 'lib/vector_mcp/security/authorization.rb', line 28 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
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/vector_mcp/security/authorization.rb', line 43 def (user, action, resource) return true unless @enabled resource_type = determine_resource_type(resource) policy = @policies[resource_type] # If no policy is defined, allow access (opt-in authorization) return true unless policy begin policy_result = policy.call(user, action, resource) policy_result ? true : false rescue StandardError # Log error but deny access for safety false end end |
#disable! ⇒ Object
Disable authorization (return to pass-through mode)
21 22 23 |
# File 'lib/vector_mcp/security/authorization.rb', line 21 def disable! @enabled = false end |
#enable! ⇒ Object
Enable authorization system
16 17 18 |
# File 'lib/vector_mcp/security/authorization.rb', line 16 def enable! @enabled = true end |
#policy_types ⇒ Array<Symbol>
Get list of resource types with policies
69 70 71 |
# File 'lib/vector_mcp/security/authorization.rb', line 69 def policy_types @policies.keys end |
#remove_policy(resource_type) ⇒ Object
Remove an authorization policy
34 35 36 |
# File 'lib/vector_mcp/security/authorization.rb', line 34 def remove_policy(resource_type) @policies.delete(resource_type) end |
#required? ⇒ Boolean
Check if authorization is required
63 64 65 |
# File 'lib/vector_mcp/security/authorization.rb', line 63 def required? @enabled end |