Class: Net::IMAP::SASL::ClientAdapter
- Inherits:
-
Object
- Object
- Net::IMAP::SASL::ClientAdapter
- Includes:
- ProtocolAdapters::Generic
- Defined in:
- lib/net/imap/sasl/client_adapter.rb
Overview
This API is experimental, and may change.
TODO: use with more clients, to verify the API can accommodate them.
An abstract base class for implementing a SASL authentication exchange. Different clients will each have their own adapter subclass, overridden to match their needs.
Although the default implementations may be sufficient, subclasses will probably need to override some methods. Additionally, subclasses may need to include a protocol adapter mixin, if the default ProtocolAdapters::Generic isn’t sufficient.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#command_proc ⇒ Object
readonly
Returns the value of attribute command_proc.
Instance Method Summary collapse
-
#auth_capable?(mechanism) ⇒ Boolean
Does the server advertise support for the mechanism?.
-
#authenticate ⇒ Object
Delegates to AuthenticationExchange.authenticate.
-
#drop_connection ⇒ Object
Drop the connection gracefully.
-
#drop_connection! ⇒ Object
Drop the connection abruptly.
-
#initialize(client, &command_proc) ⇒ ClientAdapter
constructor
command_proc
can used to avoid exposing private methods on #client. -
#response_errors ⇒ Object
Returns an array of server responses errors raised by run_command.
-
#run_command(mechanism, initial_response = nil, &block) ⇒ Object
Runs the authenticate command with
mechanism
andinitial_response
. -
#sasl_ir_capable? ⇒ Boolean
Do the protocol and server both support an initial response?.
Methods included from ProtocolAdapters::Generic
#cancel_response, #command_name, #decode, #encode, #encode_ir, #host, #port, #service
Constructor Details
#initialize(client, &command_proc) ⇒ ClientAdapter
command_proc
can used to avoid exposing private methods on #client. It should run a command with the arguments sent to it, yield each continuation payload, respond to the server with the result of each yield, and return the result. Non-successful results MUST raise an exception. Exceptions in the block MUST cause the command to fail.
Subclasses that override #run_command may use #command_proc for other purposes.
32 33 34 |
# File 'lib/net/imap/sasl/client_adapter.rb', line 32 def initialize(client, &command_proc) @client, @command_proc = client, command_proc end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
22 23 24 |
# File 'lib/net/imap/sasl/client_adapter.rb', line 22 def client @client end |
#command_proc ⇒ Object (readonly)
Returns the value of attribute command_proc.
22 23 24 |
# File 'lib/net/imap/sasl/client_adapter.rb', line 22 def command_proc @command_proc end |
Instance Method Details
#auth_capable?(mechanism) ⇒ Boolean
Does the server advertise support for the mechanism?
43 |
# File 'lib/net/imap/sasl/client_adapter.rb', line 43 def auth_capable?(mechanism); client.auth_capable?(mechanism) end |
#authenticate ⇒ Object
Delegates to AuthenticationExchange.authenticate.
37 |
# File 'lib/net/imap/sasl/client_adapter.rb', line 37 def authenticate(...) AuthenticationExchange.authenticate(self, ...) end |
#drop_connection ⇒ Object
Drop the connection gracefully.
65 |
# File 'lib/net/imap/sasl/client_adapter.rb', line 65 def drop_connection; client.drop_connection end |
#drop_connection! ⇒ Object
Drop the connection abruptly.
68 |
# File 'lib/net/imap/sasl/client_adapter.rb', line 68 def drop_connection!; client.drop_connection! end |
#response_errors ⇒ Object
Returns an array of server responses errors raised by run_command. Exceptions in this array won’t drop the connection.
62 |
# File 'lib/net/imap/sasl/client_adapter.rb', line 62 def response_errors; [] end |
#run_command(mechanism, initial_response = nil, &block) ⇒ Object
Runs the authenticate command with mechanism
and initial_response
. When initial_response
is nil, an initial response must NOT be sent.
Yields each continuation payload, responds to the server with the result of each yield, and returns the result. Non-successful results MUST raise an exception. Exceptions in the block MUST cause the command to fail.
Subclasses that override this may use #command_proc differently.
54 55 56 57 58 |
# File 'lib/net/imap/sasl/client_adapter.rb', line 54 def run_command(mechanism, initial_response = nil, &block) command_proc or raise Error, "initialize with block or override" args = [command_name, mechanism, initial_response].compact command_proc.call(*args, &block) end |
#sasl_ir_capable? ⇒ Boolean
Do the protocol and server both support an initial response?
40 |
# File 'lib/net/imap/sasl/client_adapter.rb', line 40 def sasl_ir_capable?; client.sasl_ir_capable? end |