class RoadForest::Authorization::AuthenticationChain

Attributes

store[R]

Public Class Methods

new(store) click to toggle source
# File lib/roadforest/authorization/authentication-chain.rb, line 35
def initialize(store)
  @store = store
end

Public Instance Methods

add_account(user,password,token) click to toggle source
# File lib/roadforest/authorization/authentication-chain.rb, line 52
def add_account(user,password,token)
  @store.add_account(user,password,token)
end
authenticate(request) click to toggle source
# File lib/roadforest/authorization/authentication-chain.rb, line 56
def authenticate(request)
  if request.respond_to?(:client_cert)
    subject = request.client_cert.subject
    name = subject.to_a.find{|entry| entry[0] == "CN"}[1]
    entity = @store.by_username(name)
    entity.authenticate!
    return entity
  end

  header = request.headers["Authorization"]
  return nil if header.nil?
  scheme, credentials = header.split(/\s+/, 2)

  handler = handler_for(scheme)
  return nil if handler.nil?

  entity = handler.authenticated_entity(credentials, store)
  return nil if entity.nil?
  return nil unless entity.authenticated?
  return entity
end
challenge(options) click to toggle source
# File lib/roadforest/authorization/authentication-chain.rb, line 46
def challenge(options)
  (Scheme.registry.names.map do |scheme_name|
    handler_for(scheme_name).challenge(options)
  end).join(", ")
end
handler_for(scheme) click to toggle source
# File lib/roadforest/authorization/authentication-chain.rb, line 40
def handler_for(scheme)
  Scheme.get(scheme)
rescue
  nil
end