Class: Bunny::Authentication::CredentialsEncoder

Inherits:
Object
  • Object
show all
Defined in:
lib/bunny/authentication/credentials_encoder.rb

Overview

Base credentials encoder. Subclasses implement credentials encoding for a particular authentication mechanism (PLAIN, EXTERNAL, etc).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#sessionBunny::Session (readonly)

Session that uses this encoder

Returns:



17
18
19
# File 'lib/bunny/authentication/credentials_encoder.rb', line 17

def session
  @session
end

Class Method Details

.auth_mechanism(*mechanisms) ⇒ Object

Registers an encoder for authentication mechanism



34
35
36
37
38
# File 'lib/bunny/authentication/credentials_encoder.rb', line 34

def self.auth_mechanism(*mechanisms)
  mechanisms.each do |m|
    registry[m] = self
  end
end

.for_session(session) ⇒ Bunny::CredentialsEncoder

Instantiates a new encoder for the authentication mechanism used by the provided session.

Returns:

  • (Bunny::CredentialsEncoder)


23
24
25
# File 'lib/bunny/authentication/credentials_encoder.rb', line 23

def self.for_session(session)
  registry[session.mechanism].new(session)
end

.registryObject



28
29
30
# File 'lib/bunny/authentication/credentials_encoder.rb', line 28

def self.registry
  @@registry ||= Hash.new { raise NotImplementedError }
end

Instance Method Details

#encode_credentials(username, challenge) ⇒ String

Encodes provided credentials according to the specific authentication mechanism

Returns:

  • (String)

    Encoded credentials

Raises:

  • (NotImplementedError)


43
44
45
# File 'lib/bunny/authentication/credentials_encoder.rb', line 43

def encode_credentials(username, challenge)
  raise NotImplementedError.new("Subclasses must override this method")
end