Class: Resourceful::SSBEAuthenticator
- Inherits:
-
Object
- Object
- Resourceful::SSBEAuthenticator
- Defined in:
- lib/collectd_server/ssbe_authenticator.rb
Instance Attribute Summary collapse
-
#challenge ⇒ Object
readonly
Returns the value of attribute challenge.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#realm ⇒ Object
readonly
Returns the value of attribute realm.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #add_credentials_to(request) ⇒ Object
- #can_handle?(request) ⇒ Boolean
- #credentials_for(request) ⇒ Object
-
#initialize(username, password) ⇒ SSBEAuthenticator
constructor
A new instance of SSBEAuthenticator.
- #update_credentials(challenge_response) ⇒ Object
- #valid_for?(challenge_response) ⇒ Boolean
Constructor Details
#initialize(username, password) ⇒ SSBEAuthenticator
Returns a new instance of SSBEAuthenticator.
10 11 12 13 14 |
# File 'lib/collectd_server/ssbe_authenticator.rb', line 10 def initialize(username, password) @username, @password = username, password @realm = 'SystemShepherd' @domain = nil end |
Instance Attribute Details
#challenge ⇒ Object (readonly)
Returns the value of attribute challenge.
8 9 10 |
# File 'lib/collectd_server/ssbe_authenticator.rb', line 8 def challenge @challenge end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
8 9 10 |
# File 'lib/collectd_server/ssbe_authenticator.rb', line 8 def domain @domain end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
8 9 10 |
# File 'lib/collectd_server/ssbe_authenticator.rb', line 8 def password @password end |
#realm ⇒ Object (readonly)
Returns the value of attribute realm.
8 9 10 |
# File 'lib/collectd_server/ssbe_authenticator.rb', line 8 def realm @realm end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
8 9 10 |
# File 'lib/collectd_server/ssbe_authenticator.rb', line 8 def username @username end |
Instance Method Details
#add_credentials_to(request) ⇒ Object
35 36 37 |
# File 'lib/collectd_server/ssbe_authenticator.rb', line 35 def add_credentials_to(request) request.header['Authorization'] = credentials_for(request) end |
#can_handle?(request) ⇒ Boolean
31 32 33 |
# File 'lib/collectd_server/ssbe_authenticator.rb', line 31 def can_handle?(request) Addressable::URI.parse(request.uri).host == @domain end |
#credentials_for(request) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/collectd_server/ssbe_authenticator.rb', line 39 def credentials_for(request) HTTPAuth::Digest::Credentials.from_challenge(@challenge, :username => @username, :password => @password, :method => request.method.to_s.upcase, :uri => Addressable::URI.parse(request.uri).path).to_header end |
#update_credentials(challenge_response) ⇒ Object
16 17 18 19 |
# File 'lib/collectd_server/ssbe_authenticator.rb', line 16 def update_credentials(challenge_response) @domain = Addressable::URI.parse(challenge_response.uri).host @challenge = HTTPAuth::Digest::Challenge.from_header(challenge_response.header['WWW-Authenticate'].first) end |
#valid_for?(challenge_response) ⇒ Boolean
21 22 23 24 25 26 27 28 29 |
# File 'lib/collectd_server/ssbe_authenticator.rb', line 21 def valid_for?(challenge_response) return false unless challenge_header = challenge_response.header['WWW-Authenticate'] begin challenge = HTTPAuth::Digest::Challenge.from_header(challenge_header.first) rescue HTTPAuth::UnwellformedHeader return false end challenge.realm == @realm end |