Class: Castronaut::Adapters::RestfulAuthentication::User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Castronaut::Adapters::RestfulAuthentication::User
- Defined in:
- lib/castronaut/adapters/restful_authentication/user.rb
Class Method Summary collapse
- .authenticate(username, password) ⇒ Object
- .digest(password, salt) ⇒ Object
- .find_by_login(login) ⇒ Object
- .secure_digest(*args) ⇒ Object
Class Method Details
.authenticate(username, password) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/castronaut/adapters/restful_authentication/user.rb', line 32 def self.authenticate(username, password) if user = find_by_login(username) if user.crypted_password == Castronaut::Adapters::RestfulAuthentication::User.digest(password, user.salt) Castronaut::AuthenticationResult.new(username, nil) else Castronaut.config.logger.info "#{self} - Unable to authenticate username #{username} due to invalid authentication information" Castronaut::AuthenticationResult.new(username, "Unable to authenticate the username #{username}") end else Castronaut.config.logger.info "#{self} - Unable to authenticate username #{username} because it could not be found" Castronaut::AuthenticationResult.new(username, "Unable to authenticate the username #{username}") end end |
.digest(password, salt) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/castronaut/adapters/restful_authentication/user.rb', line 9 def self.digest(password, salt) site_key = Castronaut.config.cas_adapter['site_key'] digest_value = site_key Castronaut.config.cas_adapter['digest_stretches'].times do digest_value = secure_digest(digest_value, salt, password, site_key) end digest_value end |
.find_by_login(login) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/castronaut/adapters/restful_authentication/user.rb', line 24 def self.find_by_login(login) if Castronaut.config.cas_adapter.has_key?('extra_authentication_conditions') find(:first, :conditions => ["login = ? AND #{Castronaut.config.cas_adapter['extra_authentication_conditions']}", login]) else find(:first, :conditions => { :login => login }) end end |
.secure_digest(*args) ⇒ Object
20 21 22 |
# File 'lib/castronaut/adapters/restful_authentication/user.rb', line 20 def self.secure_digest(*args) Digest::SHA1.hexdigest(args.flatten.join('--')) end |