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

Constructor Details

#initialize(session) ⇒ CredentialsEncoder (protected)

Returns a new instance of CredentialsEncoder.



51
52
53
# File 'lib/bunny/authentication/credentials_encoder.rb', line 51

def initialize(session)
  @session = session
end

Instance Attribute Details

#sessionBunny::Session (readonly)

Session that uses this encoder

Returns:



19
20
21
# File 'lib/bunny/authentication/credentials_encoder.rb', line 19

def session
  @session
end

Class Method Details

.auth_mechanism(*mechanisms) ⇒ Object

Registers an encoder for authentication mechanism



36
37
38
39
40
# File 'lib/bunny/authentication/credentials_encoder.rb', line 36

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)


25
26
27
# File 'lib/bunny/authentication/credentials_encoder.rb', line 25

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

Instance Method Details

#encode_credentials(username, challenge) ⇒ String

Encodes provided credentials according to the specific authentication mechanism

Returns:

  • (String)

    Encoded credentials

Raises:

  • (NotImplementedError)


45
46
47
# File 'lib/bunny/authentication/credentials_encoder.rb', line 45

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