module DRbService::PasswordAuthentication

An authentication strategy for DRbService – set a password via a class method.

Public Class Methods

included( klass ) click to toggle source

Overridden mixin callback – add the ClassMethods to the including class

Calls superclass method
# File lib/drbservice/passwordauth.rb, line 30
def self::included( klass )
        super
        klass.extend( ClassMethods )
end

Public Instance Methods

authenticate( password ) { || ... } click to toggle source

Authenticate using the specified password, calling the provided block if authentication succeeds. Raises a SecurityError if authentication fails. If no password is set, the block is called regardless of what the password is.

Calls superclass method
# 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