Class: RoadForest::Authorization::AuthenticationChain

Inherits:
Object
  • Object
show all
Defined in:
lib/roadforest/authorization/authentication-chain.rb

Defined Under Namespace

Classes: Basic, Scheme

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store) ⇒ AuthenticationChain

Returns a new instance of AuthenticationChain.



35
36
37
# File 'lib/roadforest/authorization/authentication-chain.rb', line 35

def initialize(store)
  @store = store
end

Instance Attribute Details

#storeObject (readonly)

Returns the value of attribute store.



38
39
40
# File 'lib/roadforest/authorization/authentication-chain.rb', line 38

def store
  @store
end

Instance Method Details

#add_account(user, password, token) ⇒ Object



52
53
54
# File 'lib/roadforest/authorization/authentication-chain.rb', line 52

def (user,password,token)
  @store.(user,password,token)
end

#authenticate(request) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# 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) ⇒ Object



46
47
48
49
50
# 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) ⇒ Object



40
41
42
43
44
# File 'lib/roadforest/authorization/authentication-chain.rb', line 40

def handler_for(scheme)
  Scheme.get(scheme)
rescue
  nil
end