Module: CloudCrowd::Helpers::Authorization

Included in:
CloudCrowd::Helpers
Defined in:
lib/cloud_crowd/helpers/authorization.rb

Overview

Authorization takes after sinatra-authorization… See github.com/integrity/sinatra-authorization for the original.

Instance Method Summary collapse

Instance Method Details

#authorize(login, password) ⇒ Object

A request is authorized if its login and password match those stored in config.yml, or if authentication is disabled. If authentication is turned on, then every request is authenticated, including between the nodes and the central server.



27
28
29
30
31
# File 'lib/cloud_crowd/helpers/authorization.rb', line 27

def authorize(, password)
  return true unless CloudCrowd.config[:http_authentication]
  return CloudCrowd.config[:login] ==  &&
         CloudCrowd.config[:password] == password
end

#authorized?Boolean

Has the request been authenticated?

Returns:

  • (Boolean)


19
20
21
# File 'lib/cloud_crowd/helpers/authorization.rb', line 19

def authorized?
  !!request.env['REMOTE_USER']
end

#login_requiredObject

Ensure that the request includes the correct credentials.



10
11
12
13
14
15
16
# File 'lib/cloud_crowd/helpers/authorization.rb', line 10

def 
  return if authorized?
  unauthorized! unless auth.provided?
  bad_request!  unless auth.basic?
  unauthorized! unless authorize(*auth.credentials)
  request.env['REMOTE_USER'] = auth.username
end