class Mongo::Auth::ConversationBase

Defines common behavior around authentication conversations between the client and the server.

@api private

Attributes

connection[R]

@return [ Mongo::Connection ] The connection to authenticate over.

user[R]

@return [ Auth::User ] user The user for the conversation.

Public Class Methods

new(user, connection, **opts) click to toggle source

Create the new conversation.

@param [ Auth::User ] user The user to authenticate. @param [ Mongo::Connection ] connection The connection to authenticate

over.
# File lib/mongo/auth/conversation_base.rb, line 31
def initialize(user, connection, **opts)
  @user = user
  @connection = connection
end

Public Instance Methods

build_message(connection, auth_source, selector) click to toggle source

@return [ Protocol::Message ] The message to send.

# File lib/mongo/auth/conversation_base.rb, line 54
def build_message(connection, auth_source, selector)
  if connection && connection.features.op_msg_enabled?
    selector = selector.dup
    selector[Protocol::Msg::DATABASE_IDENTIFIER] = auth_source
    cluster_time = connection.mongos? && connection.cluster_time
    if cluster_time
      selector[Operation::CLUSTER_TIME] = cluster_time
    end
    Protocol::Msg.new([], {}, selector)
  else
    Protocol::Query.new(
      auth_source,
      Database::COMMAND,
      selector,
      limit: -1,
    )
  end
end
speculative_auth_document() click to toggle source

Returns the hash to provide to the server in the handshake as value of the speculativeAuthenticate key.

If the auth mechanism does not support speculative authentication, this method returns nil.

@return [ Hash | nil ] Speculative authentication document.

# File lib/mongo/auth/conversation_base.rb, line 49
def speculative_auth_document
  nil
end
validate_external_auth_source() click to toggle source
# File lib/mongo/auth/conversation_base.rb, line 73
def validate_external_auth_source
  if user.auth_source != '$external'
    user_name_msg = if user.name
      " #{user.name}"
    else
      ''
    end
    mechanism = user.mechanism
    raise Auth::InvalidConfiguration, "User#{user_name_msg} specifies auth source '#{user.auth_source}', but the only valid auth source for #{mechanism} is '$external'"
  end
end