Class: Mongo::Auth::SaslConversationBase Private
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
|
Subclasses:
Mongo::Auth::ScramConversationBase, Mongo::Auth::Aws::Conversation, Mongo::Auth::Gssapi::Conversation, Mongo::Auth::Scram256::Conversation, Mongo::Auth::Scram::Conversation
|
|
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
ConversationBase
|
|
|
Instance Chain:
self,
ConversationBase
|
|
| Inherits: |
Mongo::Auth::ConversationBase
|
| Defined in: | lib/mongo/auth/sasl_conversation_base.rb |
Overview
Defines common behavior around SASL conversations between the client and the server.
Constant Summary
-
CLIENT_CONTINUE_MESSAGE =
# File 'lib/mongo/auth/sasl_conversation_base.rb', line 31
The base client continue message.
{ saslContinue: 1 }.freeze -
CLIENT_FIRST_MESSAGE =
# File 'lib/mongo/auth/sasl_conversation_base.rb', line 28
The base client first message.
{ saslStart: 1, autoAuthorize: 1 }.freeze
Class Method Summary
ConversationBase - Inherited
| .new | Create the new conversation. |
Instance Attribute Summary
ConversationBase - Inherited
Instance Method Summary
-
#start(connection) ⇒ Protocol::Message
Internal use only
Start the SASL conversation.
-
#auth_mechanism_name ⇒ String
private
Internal use only
Gets the auth mechanism name for the conversation class.
- #client_first_document private Internal use only
- #client_first_message_options private Internal use only
-
#validate_server_nonce!
private
Internal use only
Helper method to validate that server nonce starts with the client nonce.
ConversationBase - Inherited
| #build_message, | |
| #speculative_auth_document | Returns the hash to provide to the server in the handshake as value of the speculativeAuthenticate key. |
| #validate_external_auth_source | |
Instance Method Details
#auth_mechanism_name ⇒ String (private)
Gets the auth mechanism name for the conversation class.
Example return: SCRAM-SHA-1.
# File 'lib/mongo/auth/sasl_conversation_base.rb', line 51
def auth_mechanism_name # self.class.name is e.g. Mongo::Auth::Scram256::Mechanism. # We need Mongo::Auth::Scram::MECHANISM. # Pull out the Scram256 part, get that class off of Auth, # then get the value of MECHANISM constant in Scram256. # With ActiveSupport, this method would be: # self.class.module_parent.const_get(:MECHANISM) parts = self.class.name.split('::') parts.pop Auth.const_get(parts.last).const_get(:MECHANISM) end
#client_first_document (private)
# File 'lib/mongo/auth/sasl_conversation_base.rb', line 67
def client_first_document payload = client_first_payload if Lint.enabled? unless payload.is_a?(String) raise Error::LintError, "Payload must be a string but is a #{payload.class}: #{payload}" end end doc = CLIENT_FIRST_MESSAGE.merge( mechanism: auth_mechanism_name, payload: BSON::Binary.new(payload), ) if = # Short SCRAM conversation, # https://jira.mongodb.org/browse/DRIVERS-707 doc[:] = end doc end
#client_first_message_options (private)
# File 'lib/mongo/auth/sasl_conversation_base.rb', line 63
def nil end
#start(connection) ⇒ Protocol::Message
Start the SASL conversation. This returns the first message that needs to be sent to the server.
# File 'lib/mongo/auth/sasl_conversation_base.rb', line 39
def start(connection) selector = client_first_document (connection, user.auth_source, selector) end
#validate_server_nonce! (private)
Helper method to validate that server nonce starts with the client nonce.
Note that this class does not define the client_nonce or server_nonce attributes - derived classes must do so.
# File 'lib/mongo/auth/sasl_conversation_base.rb', line 91
def validate_server_nonce! if client_nonce.nil? || client_nonce.empty? raise ArgumentError, 'Cannot validate server nonce when client nonce is nil or empty' end unless server_nonce.start_with?(client_nonce) raise Error::InvalidNonce.new(client_nonce, server_nonce) end end