Class: Net::SASL::PlainAuthenticator

Inherits:
Authenticator show all
Defined in:
lib/net/sasl/plain_authenticator.rb

Overview

Authenticator for the “PLAIN” SASL mechanism, specified in RFC4616. The authentication credentials are transmitted in cleartext, so this mechanism should only be used over an encrypted link.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, password, authzid = nil, **_options) ⇒ PlainAuthenticator

username is the authentication identity, the identity whose password is used. username is referred to as authcid by RFC4616.

authzid is the authorization identity (identity to act as). It can usually be left blank. When authzid is left blank (nil or empty string) the server will derive an identity from the credentials and use that as the authorization identity.

This should generally be instantiated via Net::SASL.authenticator.

Raises:

  • (ArgumentError)


31
32
33
34
35
36
37
# File 'lib/net/sasl/plain_authenticator.rb', line 31

def initialize(username, password, authzid = nil, **_options)
  raise ArgumentError, "username contains NULL" if username&.include?(NULL)
  raise ArgumentError, "password contains NULL" if password&.include?(NULL)
  raise ArgumentError, "authzid  contains NULL" if authzid&.include?(NULL)
  super
  @done = false
end

Instance Attribute Details

#authzidObject (readonly)

Returns the value of attribute authzid.



16
17
18
# File 'lib/net/sasl/plain_authenticator.rb', line 16

def authzid
  @authzid
end

#passwordObject (readonly)

Returns the value of attribute password.



16
17
18
# File 'lib/net/sasl/plain_authenticator.rb', line 16

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



16
17
18
# File 'lib/net/sasl/plain_authenticator.rb', line 16

def username
  @username
end

Instance Method Details

#process(data) ⇒ Object

returns the SASL response for PLAIN



45
46
47
48
# File 'lib/net/sasl/plain_authenticator.rb', line 45

def process(data)
  @done = true
  "#{@authzid}\0#{@username}\0#{@password}"
end

#supports_initial_response?Boolean

PLAIN does support SASL-IR

Returns:

  • (Boolean)


40
41
42
# File 'lib/net/sasl/plain_authenticator.rb', line 40

def supports_initial_response?
  true
end