class UnauthorizedController

Special controller handling requests routed from Warden. Responds with HTTP 401 and, optionally, with a Keystone URI in the WWW-Authenticate header.

Public Class Methods

call(env) click to toggle source
# File app/controllers/unauthorized_controller.rb, line 7
def self.call(env)
  @respond ||= action(:respond)
  @respond.call(env)
end
default_url_options(*args) click to toggle source
# File app/controllers/unauthorized_controller.rb, line 18
def self.default_url_options(*args)
  defined?(ApplicationController) ? ApplicationController.default_url_options(*args) : {}
end

Public Instance Methods

respond() click to toggle source
# File app/controllers/unauthorized_controller.rb, line 12
def respond
  Rails.logger.warn "[AuthN] [#{self.class}] Authentication failed: #{warden_message}"
  set_unauth
  Rails.logger.warn "[AuthN] [#{self.class}] Responding with #{status} #{headers.inspect}"
end

Protected Instance Methods

attempted_path() click to toggle source
# File app/controllers/unauthorized_controller.rb, line 53
def attempted_path
  warden_options[:attempted_path]
end
scope() click to toggle source
# File app/controllers/unauthorized_controller.rb, line 49
def scope
  @scope ||= warden_options[:scope]
end
set_unauth() click to toggle source
# File app/controllers/unauthorized_controller.rb, line 24
def set_unauth
  self.status = 401

  # Include Keystone URI in the response, if applicable
  if ROCCI_SERVER_CONFIG.common.authn_strategies.include?('keystone')
    headers['WWW-Authenticate'] = %Q(Keystone uri='#{ROCCI_SERVER_CONFIG.authn_strategies.keystone_.keystone_uri || "http://localhost:5000/v2.0/"}')
  end

  self.content_type = 'text/plain'
  self.response_body = warden_message
end
warden() click to toggle source
# File app/controllers/unauthorized_controller.rb, line 36
def warden
  request.env['warden']
end
warden_message() click to toggle source
# File app/controllers/unauthorized_controller.rb, line 44
def warden_message
  @message ||= warden.message || warden_options[:message] || "Authentication failed!"                   " The following strategies are supported #{ROCCI_SERVER_CONFIG.common.authn_strategies.join(', ').inspect}!"
end
warden_options() click to toggle source
# File app/controllers/unauthorized_controller.rb, line 40
def warden_options
  request.env['warden.options']
end