Class: Mongo::Auth::ConversationBase Private

Inherits:
Object
  • Object
show all
Defined in:
lib/mongo/auth/conversation_base.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.

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

Since:

  • 2.0.0

API:

  • private

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, connection, **opts) ⇒ ConversationBase

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.

Create the new conversation.

Since:

  • 2.0.0

Parameters:

  • The user to authenticate.

  • The connection to authenticate over.

API:

  • private



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

def initialize(user, connection, **opts)
  @user = user
  @connection = connection
end

Instance Attribute Details

#connectionMongo::Connection (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 connection to authenticate over.

Since:

  • 2.0.0

Returns:

  • The connection to authenticate over.

API:

  • private



41
42
43
# File 'lib/mongo/auth/conversation_base.rb', line 41

def connection
  @connection
end

#userAuth::User (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 user The user for the conversation.

Since:

  • 2.0.0

Returns:

  • user The user for the conversation.

API:

  • private



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

def user
  @user
end

Instance Method Details

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

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 message to send.

Since:

  • 2.0.0

Returns:

  • The message to send.

API:

  • private



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/mongo/auth/conversation_base.rb', line 55

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_documentHash | nil

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 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.

Since:

  • 2.0.0

Returns:

  • Speculative authentication document.

API:

  • private



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

def speculative_auth_document
  nil
end

#validate_external_auth_sourceObject

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.

Since:

  • 2.0.0

API:

  • private



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/mongo/auth/conversation_base.rb', line 74

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