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.
-
#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_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
194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 194 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
136 137 138 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 136 def @cached_permissions_ttl end |
#circuit_breaker_cooldown_seconds ⇒ Integer
Seconds to fail fast before allowing another request attempt
76 77 78 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 76 def circuit_breaker_cooldown_seconds @circuit_breaker_cooldown_seconds end |
#circuit_breaker_enabled ⇒ Boolean
Whether unexpected errors should trip a fail-fast circuit breaker
68 69 70 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 68 def circuit_breaker_enabled @circuit_breaker_enabled end |
#circuit_breaker_failure_threshold ⇒ Integer
Number of unexpected failures before the circuit opens
72 73 74 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 72 def circuit_breaker_failure_threshold @circuit_breaker_failure_threshold end |
#custom_payload_validator ⇒ Proc
Custom payload validation proc
146 147 148 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 146 def custom_payload_validator @custom_payload_validator end |
#debug_mode ⇒ Boolean
Whether debug mode is enabled for additional logging
170 171 172 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 170 def debug_mode @debug_mode end |
#forbidden_response ⇒ Hash
Custom response for forbidden requests (403)
162 163 164 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 162 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
96 97 98 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 96 def pathname_slug_pattern @pathname_slug_pattern end |
#payload_mapping ⇒ Hash
Mapping of standard payload keys to custom JWT claim names
102 103 104 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 102 def payload_mapping @payload_mapping end |
#permissions_cache_store ⇒ Symbol
The permission cache store adapter type
128 129 130 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 128 def @permissions_cache_store end |
#permissions_cache_store_options ⇒ Hash
Options for the permission cache store
132 133 134 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 132 def @permissions_cache_store_options end |
#rbac_cache_store ⇒ Symbol
The RBAC cache store adapter type (separate from main cache)
120 121 122 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 120 def rbac_cache_store @rbac_cache_store end |
#rbac_cache_store_options ⇒ Hash
Options for the RBAC cache store
124 125 126 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 124 def @rbac_cache_store_options end |
#rbac_enabled ⇒ Boolean
Whether RBAC (Role-Based Access Control) is enabled
64 65 66 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 64 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
60 61 62 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 60 def require_expiration_claims @require_expiration_claims end |
#skip_paths ⇒ Array<String, Regexp, Hash>
Array of routes that should skip JWT authentication
113 114 115 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 113 def skip_paths @skip_paths end |
#skip_routes ⇒ Array<String, Regexp, Hash>
Array of routes that should skip JWT authentication
113 114 115 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 113 def skip_routes @skip_routes end |
#tenant_id_header_name ⇒ String
The HTTP header name containing the tenant ID
84 85 86 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 84 def tenant_id_header_name @tenant_id_header_name end |
#tenant_slug_header_name ⇒ String
The HTTP header name containing the tenant slug
88 89 90 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 88 def tenant_slug_header_name @tenant_slug_header_name end |
#unauthorized_response ⇒ Hash
Custom response for unauthorized requests (401)
156 157 158 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 156 def @unauthorized_response end |
#user_id_header_name ⇒ String
The HTTP header name containing the user ID
92 93 94 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 92 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
217 218 219 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 217 def circuit_breaker_enabled? config_boolean?(circuit_breaker_enabled) end |
#debug_mode? ⇒ Boolean
Check if debug mode is enabled
253 254 255 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 253 def debug_mode? config_boolean?(debug_mode) end |
#payload_key(standard_key) ⇒ Symbol
Get the mapped payload key for a standard key
292 293 294 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 292 def payload_key(standard_key) payload_mapping&.fetch(standard_key, standard_key) || standard_key end |
#rbac_enabled? ⇒ Boolean
Check if RBAC is enabled
211 212 213 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 211 def rbac_enabled? config_boolean?(rbac_enabled) end |
#require_authentication_headers? ⇒ Boolean
Check if strict authenticated request headers are required
241 242 243 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 241 def require_authentication_headers? config_boolean?(require_authentication_headers) end |
#require_expiration_claims? ⇒ Boolean
Check if exp and iat claims are required
247 248 249 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 247 def require_expiration_claims? config_boolean?(require_expiration_claims) end |
#skip_path?(path) ⇒ Boolean
Check if the given path should skip JWT authentication
270 271 272 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 270 def skip_path?(path) skip_request?(path) end |
#skip_request?(path, request_method = nil) ⇒ Boolean
Check if the given request should skip JWT authentication
278 279 280 281 282 283 284 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 278 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
229 230 231 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 229 def validate_pathname_slug? config_boolean?(validate_pathname_slug) end |
#validate_subdomain? ⇒ Boolean
Check if subdomain validation is enabled
223 224 225 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 223 def validate_subdomain? config_boolean?(validate_subdomain) end |
#validate_tenant_id? ⇒ Boolean
Check if tenant id validation is enabled
235 236 237 |
# File 'lib/rack_jwt_aegis/configuration.rb', line 235 def validate_tenant_id? config_boolean?(validate_tenant_id) end |