Module: DRbService::PasswordAuthentication
- Defined in:
- lib/drbservice/passwordauth.rb
Overview
An authentication strategy for DRbService – set a password via a class method.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(klass) ⇒ Object
Overridden mixin callback – add the ClassMethods to the including class.
Instance Method Summary collapse
-
#authenticate(password) ⇒ Object
authentication succeeds.
Class Method Details
.included(klass) ⇒ Object
Overridden mixin callback – add the ClassMethods to the including class
30 31 32 33 |
# File 'lib/drbservice/passwordauth.rb', line 30 def self::included( klass ) super klass.extend( ClassMethods ) end |
Instance Method Details
#authenticate(password) ⇒ Object
authentication succeeds. Raises a SecurityError if authentication fails. If no password is set, the block is called regardless of what the password
is.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/drbservice/passwordauth.rb', line 39 def authenticate( password ) if digest = self.class.password_digest if Digest::SHA2.hexdigest( password ) == digest self.log.info "authentication successful" @authenticated = true yield else super end else self.log.error "no password set -- authentication will always fail" super end ensure @authenticated = false end |