Class: Net::SASL::Registry
- Inherits:
-
Object
- Object
- Net::SASL::Registry
- Defined in:
- lib/net/sasl/registry.rb
Overview
Registry for SASL mechanisms. Common usage can use the default global registry, via Net::SASL#authenticator.
Instance Method Summary collapse
-
#add_authenticator(mechanism, authenticator) ⇒ Object
Adds an authenticator class for use with #authenticator.
-
#authenticator(mechanism, authcid = nil, credentials = nil, authzid = nil, **kwargs) ⇒ Object
Builds an authenticator in its initial state.
-
#initialize ⇒ Registry
constructor
Creates a new registry, which matches enabled SASL mechanisms with their implementations.
-
#remove_authenticator(mechanism) ⇒ Object
Deletes an authenticator from the registry.
Constructor Details
#initialize ⇒ Registry
Creates a new registry, which matches enabled SASL mechanisms with their implementations.
13 14 15 |
# File 'lib/net/sasl/registry.rb', line 13 def initialize @authenticators = {} end |
Instance Method Details
#add_authenticator(mechanism, authenticator) ⇒ Object
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.
25 26 27 |
# 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) ⇒ Object
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.
39 40 41 42 43 44 45 46 |
# 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) ⇒ Object
Deletes an authenticator from the registry. This can be useful to implement a policy that prohibits the use of default mechanisms.
31 32 33 |
# File 'lib/net/sasl/registry.rb', line 31 def remove_authenticator(mechanism) @authenticators.delete(mechanism.upcase) end |