123456789_123456789_123456789_123456789_123456789_

Class: Mongo::Auth::ConversationBase Private

Do not use. This class is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Mongo::Auth::SaslConversationBase, Mongo::Auth::ScramConversationBase, Mongo::Auth::Aws::Conversation, Mongo::Auth::CR::Conversation, Mongo::Auth::Gssapi::Conversation, Mongo::Auth::LDAP::Conversation, Mongo::Auth::Scram256::Conversation, Mongo::Auth::Scram::Conversation, Mongo::Auth::X509::Conversation
Inherits: Object
Defined in: lib/mongo/auth/conversation_base.rb

Overview

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

Since:

  • 2.0.0

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#connectionMongo::Connection (readonly)

Returns:

  • (Mongo::Connection)

    The connection to authenticate over.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/auth/conversation_base.rb', line 38

attr_reader :connection

#userAuth::User (readonly)

Returns:

  • (Auth::User)

    user The user for the conversation.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/auth/conversation_base.rb', line 35

attr_reader :user

Instance Method Details

#build_message(connection, auth_source, selector) ⇒ Protocol::Message

Returns:

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/auth/conversation_base.rb', line 52

def build_message(connection, auth_source, selector)
  if connection
    selector = selector.dup
    selector[Protocol::Msg::DATABASE_IDENTIFIER] = auth_source
    cluster_time = connection.mongos? && connection.cluster_time
    selector[Operation::CLUSTER_TIME] = cluster_time if cluster_time
    Protocol::Msg.new([], {}, selector)
  else
    Protocol::Query.new(
      auth_source,
      Database::COMMAND,
      selector,
      limit: -1
    )
  end
end

#speculative_auth_documentHash | nil

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.

Returns:

  • (Hash | nil)

    Speculative authentication document.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/auth/conversation_base.rb', line 47

def speculative_auth_document
  nil
end

#validate_external_auth_source

Raises:

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/auth/conversation_base.rb', line 69

def validate_external_auth_source
  return unless 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