Class: Rails::Auth::Monitor::Middleware
- Inherits:
-
Object
- Object
- Rails::Auth::Monitor::Middleware
- Defined in:
- lib/rails/auth/monitor/middleware.rb
Overview
Fires a user-specified callback which reports on authorization success or failure. Useful for logging or monitoring systems for AuthZ failures
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, callback) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, callback) ⇒ Middleware
Returns a new instance of Middleware.
9 10 11 12 13 14 |
# File 'lib/rails/auth/monitor/middleware.rb', line 9 def initialize(app, callback) raise ArgumentError, "callback must respond to :call" unless callback.respond_to?(:call) @app = app @callback = callback end |
Instance Method Details
#call(env) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rails/auth/monitor/middleware.rb', line 16 def call(env) begin result = @app.call(env) rescue Rails::Auth::NotAuthorizedError @callback.call(env, false) raise end @callback.call(env, true) result end |