Class: Rails::Auth::ACL::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/auth/acl/middleware.rb

Overview

Authorizes requests by matching them against the given ACL

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, acl: nil) ⇒ Rails::Auth::ACL::Middleware

Create a new ACL Middleware object

Parameters:

  • app (Object)

    next app in the Rack middleware chain

  • acl (Hash) (defaults to: nil)

    Rails::Auth::ACL object to authorize the request with

Raises:

  • (ArgumentError)


17
18
19
20
21
22
# File 'lib/rails/auth/acl/middleware.rb', line 17

def initialize(app, acl: nil)
  raise ArgumentError, "no acl given" unless acl

  @app = app
  @acl = acl
end

Class Method Details

.from_acl_config(app, **args) ⇒ Object

Create Rails::Auth::ACL::Middleware from the args you’d pass to Rails::Auth::ACL’s constructor



7
8
9
# File 'lib/rails/auth/acl/middleware.rb', line 7

def self.from_acl_config(app, **args)
  new(app, acl: Rails::Auth::ACL.new(**args))
end

Instance Method Details

#call(env) ⇒ Object

Raises:



24
25
26
27
# File 'lib/rails/auth/acl/middleware.rb', line 24

def call(env)
  raise NotAuthorizedError, "unauthorized request" unless Rails::Auth.authorized?(env) || @acl.match(env)
  @app.call(env)
end