Class: RackJwtAegis::Configuration
- Inherits:
-
Object
- Object
- RackJwtAegis::Configuration
- Defined in:
- lib/rack_jwt_aegis/configuration.rb
Overview
Configuration class for RackJwtAegis middleware
Manages all configuration options for JWT authentication, multi-tenant validation, RBAC authorization, and caching behavior.
Core JWT Settings collapse
-
#jwt_algorithm ⇒ String
The JWT algorithm to use for token verification.
-
#jwt_secret ⇒ String
The secret key used for JWT signature verification.
Feature Toggles collapse
-
#circuit_breaker_cooldown_seconds ⇒ Integer
Seconds to fail fast before allowing another request attempt.
-
#circuit_breaker_enabled ⇒ Boolean
Whether unexpected errors should trip a fail-fast circuit breaker.
-
#circuit_breaker_failure_threshold ⇒ Integer
Number of unexpected failures before the circuit opens.
-
#rbac_enabled ⇒ Boolean
Whether RBAC (Role-Based Access Control) is enabled.
-
#require_authentication_headers ⇒ Boolean
Whether authenticated requests must include all identity/tenant headers.
-
#require_expiration_claims ⇒ Boolean
Whether JWTs must include expiration-related claims.
-
#skip_options_requests ⇒ Boolean
Whether HTTP OPTIONS preflight requests should bypass JWT authentication.
-
#validate_pathname_slug ⇒ Boolean
Whether to validate pathname slug-based multi-tenancy.
-
#validate_subdomain ⇒ Boolean
Whether to validate subdomain-based multi-tenancy.
-
#validate_tenant_id ⇒ Boolean
Whether to validate tenant id from request header against the tenant id from JWT payload.
Multi-tenant Settings collapse
-
#pathname_slug_pattern ⇒ Regexp
The regular expression pattern to extract pathname slugs.
-
#payload_mapping ⇒ Hash
Mapping of standard payload keys to custom JWT claim names.
-
#tenant_id_header_name ⇒ String
The HTTP header name containing the tenant ID.
-
#tenant_slug_header_name ⇒ String
The HTTP header name containing the tenant slug.
-
#user_id_header_name ⇒ String
The HTTP header name containing the user ID.
Path Management collapse
-
#skip_paths ⇒ Array<String, Regexp, Hash>
Array of routes that should skip JWT authentication.
-
#skip_routes ⇒ Array<String, Regexp, Hash>
Array of routes that should skip JWT authentication.
Cache Configuration collapse
-
#cached_permissions_ttl ⇒ Integer
Time-to-live for user permissions cache in seconds.
-
#permissions_cache_store ⇒ Symbol
The permission cache store adapter type.
-
#permissions_cache_store_options ⇒ Hash
Options for the permission cache store.
-
#rbac_cache_store ⇒ Symbol
The RBAC cache store adapter type (separate from main cache).
-
#rbac_cache_store_options ⇒ Hash
Options for the RBAC cache store.
Custom Validators collapse
-
#custom_payload_validator ⇒ Proc
Custom payload validation proc.
Response Customization collapse
-
#forbidden_response ⇒ Hash
Custom response for forbidden requests (403).
-
#unauthorized_response ⇒ Hash
Custom response for unauthorized requests (401).
Development Settings collapse
-
#debug_mode ⇒ Boolean
Whether debug mode is enabled for additional logging.
Instance Method Summary collapse
-
#circuit_breaker_enabled? ⇒ Boolean
Check if circuit breaker is enabled.
-
#debug_mode? ⇒ Boolean
Check if debug mode is enabled.
-
#initialize(options = {}) ⇒ Configuration
constructor
Initialize a new Configuration instance.
-
#payload_key(standard_key) ⇒ Symbol
Get the mapped payload key for a standard key.
-
#rbac_enabled? ⇒ Boolean
Check if RBAC is enabled.
-
#require_authentication_headers? ⇒ Boolean
Check if strict authenticated request headers are required.
-
#require_expiration_claims? ⇒ Boolean
Check if exp and iat claims are required.
-
#skip_options_requests? ⇒ Boolean
Check if OPTIONS requests bypass JWT authentication.
-
#skip_path?(path) ⇒ Boolean
Check if the given path should skip JWT authentication.
-
#skip_request?(path, request_method = nil) ⇒ Boolean
Check if the given request should skip JWT authentication.
-
#validate_pathname_slug? ⇒ Boolean
Check if pathname slug validation is enabled.
-
#validate_subdomain? ⇒ Boolean
Check if subdomain validation is enabled.
-
#validate_tenant_id? ⇒ Boolean
Check if tenant id validation is enabled.
Constructor Details
#initialize(options = {}) ⇒ Configuration
Initialize a new Configuration instance
199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 199 def initialize( = {}) # Set defaults set_defaults # Merge user options .each do |key, value| raise ConfigurationError, "Unknown configuration option: #{key}" unless respond_to?("#{key}=") public_send("#{key}=", value) end # Validate configuration validate! end |
Instance Attribute Details
#cached_permissions_ttl ⇒ Integer
Time-to-live for user permissions cache in seconds
140 141 142 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 140 def @cached_permissions_ttl end |
#circuit_breaker_cooldown_seconds ⇒ Integer
Seconds to fail fast before allowing another request attempt
80 81 82 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 80 def circuit_breaker_cooldown_seconds @circuit_breaker_cooldown_seconds end |
#circuit_breaker_enabled ⇒ Boolean
Whether unexpected errors should trip a fail-fast circuit breaker
72 73 74 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 72 def circuit_breaker_enabled @circuit_breaker_enabled end |
#circuit_breaker_failure_threshold ⇒ Integer
Number of unexpected failures before the circuit opens
76 77 78 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 76 def circuit_breaker_failure_threshold @circuit_breaker_failure_threshold end |
#custom_payload_validator ⇒ Proc
Custom payload validation proc
150 151 152 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 150 def custom_payload_validator @custom_payload_validator end |
#debug_mode ⇒ Boolean
Whether debug mode is enabled for additional logging
174 175 176 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 174 def debug_mode @debug_mode end |
#forbidden_response ⇒ Hash
Custom response for forbidden requests (403)
166 167 168 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 166 def forbidden_response @forbidden_response end |
#jwt_algorithm ⇒ String
Supported algorithms: HS256, HS384, HS512, RS256, RS384, RS512, ES256, ES384, ES512
The JWT algorithm to use for token verification
36 37 38 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 36 def jwt_algorithm @jwt_algorithm end |
#jwt_secret ⇒ String
This is required and must not be empty
The secret key used for JWT signature verification
31 32 33 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 31 def jwt_secret @jwt_secret end |
#pathname_slug_pattern ⇒ Regexp
The regular expression pattern to extract pathname slugs
100 101 102 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 100 def pathname_slug_pattern @pathname_slug_pattern end |
#payload_mapping ⇒ Hash
Mapping of standard payload keys to custom JWT claim names
106 107 108 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 106 def payload_mapping @payload_mapping end |
#permissions_cache_store ⇒ Symbol
The permission cache store adapter type
132 133 134 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 132 def @permissions_cache_store end |
#permissions_cache_store_options ⇒ Hash
Options for the permission cache store
136 137 138 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 136 def @permissions_cache_store_options end |
#rbac_cache_store ⇒ Symbol
The RBAC cache store adapter type (separate from main cache)
124 125 126 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 124 def rbac_cache_store @rbac_cache_store end |
#rbac_cache_store_options ⇒ Hash
Options for the RBAC cache store
128 129 130 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 128 def @rbac_cache_store_options end |
#rbac_enabled ⇒ Boolean
Whether RBAC (Role-Based Access Control) is enabled
68 69 70 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 68 def rbac_enabled @rbac_enabled end |
#require_authentication_headers ⇒ Boolean
Whether authenticated requests must include all identity/tenant headers
56 57 58 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 56 def require_authentication_headers @require_authentication_headers end |
#require_expiration_claims ⇒ Boolean
Whether JWTs must include expiration-related claims
64 65 66 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 64 def require_expiration_claims @require_expiration_claims end |
#skip_options_requests ⇒ Boolean
Whether HTTP OPTIONS preflight requests should bypass JWT authentication
60 61 62 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 60 def @skip_options_requests end |
#skip_paths ⇒ Array<String, Regexp, Hash>
Array of routes that should skip JWT authentication
117 118 119 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 117 def skip_paths @skip_paths end |
#skip_routes ⇒ Array<String, Regexp, Hash>
Array of routes that should skip JWT authentication
117 118 119 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 117 def skip_routes @skip_routes end |
#tenant_id_header_name ⇒ String
The HTTP header name containing the tenant ID
88 89 90 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 88 def tenant_id_header_name @tenant_id_header_name end |
#tenant_slug_header_name ⇒ String
The HTTP header name containing the tenant slug
92 93 94 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 92 def tenant_slug_header_name @tenant_slug_header_name end |
#unauthorized_response ⇒ Hash
Custom response for unauthorized requests (401)
160 161 162 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 160 def @unauthorized_response end |
#user_id_header_name ⇒ String
The HTTP header name containing the user ID
96 97 98 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 96 def user_id_header_name @user_id_header_name end |
#validate_pathname_slug ⇒ Boolean
Whether to validate pathname slug-based multi-tenancy
48 49 50 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 48 def validate_pathname_slug @validate_pathname_slug end |
#validate_subdomain ⇒ Boolean
Whether to validate subdomain-based multi-tenancy
44 45 46 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 44 def validate_subdomain @validate_subdomain end |
#validate_tenant_id ⇒ Boolean
Whether to validate tenant id from request header against the tenant id from JWT payload
52 53 54 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 52 def validate_tenant_id @validate_tenant_id end |
Instance Method Details
#circuit_breaker_enabled? ⇒ Boolean
Check if circuit breaker is enabled
222 223 224 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 222 def circuit_breaker_enabled? config_boolean?(circuit_breaker_enabled) end |
#debug_mode? ⇒ Boolean
Check if debug mode is enabled
264 265 266 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 264 def debug_mode? config_boolean?(debug_mode) end |
#payload_key(standard_key) ⇒ Symbol
Get the mapped payload key for a standard key
303 304 305 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 303 def payload_key(standard_key) payload_mapping&.fetch(standard_key, standard_key) || standard_key end |
#rbac_enabled? ⇒ Boolean
Check if RBAC is enabled
216 217 218 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 216 def rbac_enabled? config_boolean?(rbac_enabled) end |
#require_authentication_headers? ⇒ Boolean
Check if strict authenticated request headers are required
246 247 248 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 246 def require_authentication_headers? config_boolean?(require_authentication_headers) end |
#require_expiration_claims? ⇒ Boolean
Check if exp and iat claims are required
258 259 260 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 258 def require_expiration_claims? config_boolean?(require_expiration_claims) end |
#skip_options_requests? ⇒ Boolean
Check if OPTIONS requests bypass JWT authentication
252 253 254 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 252 def config_boolean?() end |
#skip_path?(path) ⇒ Boolean
Check if the given path should skip JWT authentication
281 282 283 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 281 def skip_path?(path) skip_request?(path) end |
#skip_request?(path, request_method = nil) ⇒ Boolean
Check if the given request should skip JWT authentication
289 290 291 292 293 294 295 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 289 def skip_request?(path, request_method = nil) return false if normalized_skip_routes.empty? normalized_skip_routes.any? do |skip_route| route_matches?(skip_route, path, request_method) end end |
#validate_pathname_slug? ⇒ Boolean
Check if pathname slug validation is enabled
234 235 236 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 234 def validate_pathname_slug? config_boolean?(validate_pathname_slug) end |
#validate_subdomain? ⇒ Boolean
Check if subdomain validation is enabled
228 229 230 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 228 def validate_subdomain? config_boolean?(validate_subdomain) end |
#validate_tenant_id? ⇒ Boolean
Check if tenant id validation is enabled
240 241 242 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 240 def validate_tenant_id? config_boolean?(validate_tenant_id) end |