Class: Conjur::Rack::Authenticator

Inherits:
Object
  • Object
show all
Defined in:
lib/conjur/rack/authenticator.rb

Defined Under Namespace

Classes: AuthorizationError, Forbidden, SignatureError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Authenticator

options:

:except

a list of request path patterns for which to skip authentication.

:optional

request path patterns for which authentication is optional.



50
51
52
53
# File 'lib/conjur/rack/authenticator.rb', line 50

def initialize app, options = {}
  @app = app
  @options = options
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



45
46
47
# File 'lib/conjur/rack/authenticator.rb', line 45

def app
  @app
end

#optionsObject (readonly)

Returns the value of attribute options.



45
46
47
# File 'lib/conjur/rack/authenticator.rb', line 45

def options
  @options
end

Instance Method Details

#call(rackenv) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/conjur/rack/authenticator.rb', line 65

def call rackenv
  # never store request-specific variables as application attributes 
  Thread.current[:rack_env] = rackenv
  if authenticate?
    begin
      identity = verify_authorization_and_get_identity # [token, account]
      
      if identity
        conjur_rack[:token] = identity[0]
        conjur_rack[:account] = identity[1]
        conjur_rack[:identity] = identity
        conjur_rack[:privilege] = http_privilege
        conjur_rack[:remote_ip] = http_remote_ip
        conjur_rack[:audit_roles] = http_audit_roles
        conjur_rack[:audit_resources] = http_audit_resources
      end

    rescue Forbidden
      return error 403, $!.message
    rescue SecurityError, RestClient::Exception
      return error 401, $!.message
    end
  end
  begin
    @app.call rackenv
  ensure
    Thread.current[:rack_env] = nil
    Thread.current[:conjur_rack] = {}
  end
end

#envObject

threadsafe accessors, values are established explicitly below



56
# File 'lib/conjur/rack/authenticator.rb', line 56

def env; Thread.current[:rack_env] ; end