class Net::SASL::Registry

Registry for SASL mechanisms. Common usage can use the default global registry, via Net::SASL#authenticator.

Public Class Methods

new() click to toggle source

Creates a new registry, which matches enabled SASL mechanisms with their implementations.

# File lib/net/sasl/registry.rb, line 13
def initialize
  @authenticators = {}
end

Public Instance Methods

add_authenticator(mechanism, authenticator) click to toggle source

Adds an authenticator class for use with authenticator. mechanism is the SASL mechanism name supported by authenticator (for instance, “PLAIN”). The authenticator is an class which defines a #process method to handle authentication with the server. See e.g. Net::SASL::PlainAuthenticator.

If mechanism refers to an existing authenticator, it will be replaced by the new one.

# File lib/net/sasl/registry.rb, line 25
def add_authenticator(mechanism, authenticator)
  @authenticators[mechanism.upcase] = authenticator
end
authenticator(mechanism, authcid=nil, credentials=nil, authzid=nil, **kwargs) click to toggle source

Builds an authenticator in its initial state. mechanism is the SASL mechanism name. All other arguments represent the credentials and other parameters or configuration, which will be passed directly to the chosen authenticator's #new method. See Authenticator.new.

# File lib/net/sasl/registry.rb, line 39
def authenticator(mechanism, authcid=nil, credentials=nil, authzid=nil, **kwargs)
  mechanism = mechanism.upcase
  unless @authenticators.key?(mechanism)
    raise ArgumentError, 'unknown SASL mechanism - "%s"' % mechanism
  end
  @authenticators.fetch(mechanism)
    .new(authcid, credentials, authzid, **kwargs)
end
remove_authenticator(mechanism) click to toggle source

Deletes an authenticator from the registry. This can be useful to implement a policy that prohibits the use of default mechanisms.

# File lib/net/sasl/registry.rb, line 31
def remove_authenticator(mechanism)
  @authenticators.delete(mechanism.upcase)
end