Class: Mongo::Server::PendingConnection Private
- Inherits:
-
ConnectionBase
- Object
- ConnectionCommon
- ConnectionBase
- Mongo::Server::PendingConnection
- Extended by:
- Forwardable
- Defined in:
- lib/mongo/server/pending_connection.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
This class encapsulates connections during handshake and authentication.
Constant Summary
Constants inherited from ConnectionBase
ConnectionBase::DEFAULT_MAX_BSON_OBJECT_SIZE, ConnectionBase::MAX_BSON_COMMAND_OVERHEAD, ConnectionBase::REDUCED_MAX_BSON_SIZE
Constants included from Loggable
Instance Attribute Summary collapse
-
#id ⇒ Integer
readonly
private
The ID for the connection.
Attributes inherited from ConnectionBase
#description, #options, #server
Attributes included from Monitoring::Publishable
Attributes inherited from ConnectionCommon
Instance Method Summary collapse
- #handshake_and_authenticate! ⇒ Object private
-
#initialize(socket, server, monitoring, options = {}) ⇒ PendingConnection
constructor
private
A new instance of PendingConnection.
Methods inherited from ConnectionBase
#app_metadata, #dispatch, #generation
Methods included from Monitoring::Publishable
#publish_cmap_event, #publish_event, #publish_sdam_event
Methods included from Loggable
#log_debug, #log_error, #log_fatal, #log_info, #log_warn, #logger
Methods inherited from ConnectionCommon
Constructor Details
#initialize(socket, server, monitoring, options = {}) ⇒ PendingConnection
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of PendingConnection.
24 25 26 27 28 29 30 |
# File 'lib/mongo/server/pending_connection.rb', line 24 def initialize(socket, server, monitoring, = {}) @socket = socket = @server = server @monitoring = monitoring @id = [:id] end |
Instance Attribute Details
#id ⇒ Integer (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The ID for the connection. This is the same ID as that of the regular Connection object for which this PendingConnection instance was created.
35 36 37 |
# File 'lib/mongo/server/pending_connection.rb', line 35 def id @id end |
Instance Method Details
#handshake_and_authenticate! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/mongo/server/pending_connection.rb', line 37 def handshake_and_authenticate! speculative_auth_doc = nil if [:user] || [:auth_mech] # To create an Auth instance, we need to specify the mechanism, # but at this point we don't know the mechanism that ultimately # will be used (since this depends on the data returned by # the handshake, specifically server version). # However, we know that only 4.4+ servers support speculative # authentication, and those servers also generally support # SCRAM-SHA-256. We expect that user accounts created for 4.4+ # servers would generally allow SCRAM-SHA-256 authentication; # user accounts migrated from pre-4.4 servers may only allow # SCRAM-SHA-1. The use of SCRAM-SHA-256 by default is thus # sensible, and it is also mandated by the speculative auth spec. # If no mechanism was specified and we are talking to a 3.0+ # server, we'll send speculative auth document, the server will # ignore it and we'll perform authentication using explicit # command after having defaulted the mechanism later to CR. # If no mechanism was specified and we are talking to a 4.4+ # server and the user account doesn't allow SCRAM-SHA-256, we will # authenticate in a separate command with SCRAM-SHA-1 after # going through SCRAM mechanism negotiation. = Options::Redacted.new(:auth_mech => :scram256) speculative_auth_user = Auth::User.new(.merge()) speculative_auth = Auth.get(speculative_auth_user, self) speculative_auth_doc = speculative_auth.conversation.speculative_auth_document end result = handshake!(speculative_auth_doc: speculative_auth_doc) if speculative_auth_doc && (speculative_auth_result = result['speculativeAuthenticate']) unless description.features.scram_sha_1_enabled? raise Error::InvalidServerAuthResponse, "Speculative auth succeeded on a pre-3.0 server" end case speculative_auth_user.mechanism when :mongodb_x509 # Done # We default auth mechanism to scram256, but if user specified # scram explicitly we may be able to authenticate speculatively # with scram. when :scram, :scram256 authenticate!( speculative_auth_client_nonce: speculative_auth.conversation.client_nonce, speculative_auth_mech: speculative_auth_user.mechanism, speculative_auth_result: speculative_auth_result, ) else raise NotImplementedError, "Speculative auth unexpectedly succeeded for mechanism #{speculative_auth_user.mechanism.inspect}" end elsif !description.arbiter? authenticate! end end |