Class: RoadForest::Authorization::AuthenticationChain
- Inherits:
-
Object
- Object
- RoadForest::Authorization::AuthenticationChain
- Defined in:
- lib/roadforest/authorization/authentication-chain.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
- #add_account(user, password, token) ⇒ Object
- #authenticate(request) ⇒ Object
- #challenge(options) ⇒ Object
- #handler_for(scheme) ⇒ Object
-
#initialize(store) ⇒ AuthenticationChain
constructor
A new instance of AuthenticationChain.
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
#store ⇒ Object (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 add_account(user,password,token) @store.add_account(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 |