Class: Mongo::Auth::CR::Conversation Deprecated Private

Inherits:
Mongo::Auth::ConversationBase show all
Defined in:
lib/mongo/auth/cr/conversation.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.

Deprecated.

MONGODB-CR authentication mechanism is deprecated as of MongoDB 3.6. Support for it in the Ruby driver will be removed in driver version 3.0. Please use SCRAM instead.

Defines behavior around a single MONGODB-CR conversation between the client and server.

Since:

  • 2.0.0

Constant Summary collapse

LOGIN =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The login message base.

Since:

  • 2.0.0

{ authenticate: 1 }.freeze

Instance Attribute Summary collapse

Attributes inherited from Mongo::Auth::ConversationBase

#connection, #user

Instance Method Summary collapse

Methods inherited from Mongo::Auth::ConversationBase

#initialize, #speculative_auth_document

Constructor Details

This class inherits a constructor from Mongo::Auth::ConversationBase

Instance Attribute Details

#databaseString (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 database The database to authenticate against.

Returns:

  • (String)

    database The database to authenticate against.

Since:

  • 2.0.0



35
36
37
# File 'lib/mongo/auth/cr/conversation.rb', line 35

def database
  @database
end

#nonceString (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 nonce The initial auth nonce.

Returns:

  • (String)

    nonce The initial auth nonce.

Since:

  • 2.0.0



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

def nonce
  @nonce
end

Instance Method Details

#continue(reply_document, connection) ⇒ Protocol::Query

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.

Continue the CR conversation. This sends the client final message to the server after setting the reply from the previous server communication.

Parameters:

  • reply_document (BSON::Document)

    The reply document of the previous message.

  • connection (Mongo::Server::Connection)

    The connection being authenticated.

Returns:

Since:

  • 2.0.0



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/mongo/auth/cr/conversation.rb', line 76

def continue(reply_document, connection)
  @nonce = reply_document[Auth::NONCE]

  if connection && connection.features.op_msg_enabled?
    selector = LOGIN.merge(user: user.name, nonce: nonce, key: user.auth_key(nonce))
    selector[Protocol::Msg::DATABASE_IDENTIFIER] = user.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(
      user.auth_source,
      Database::COMMAND,
      LOGIN.merge(user: user.name, nonce: nonce, key: user.auth_key(nonce)),
      limit: -1
    )
  end
end

#start(connection) ⇒ Protocol::Query

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.

Start the CR conversation. This returns the first message that needs to be sent to the server.

Parameters:

Returns:

Since:

  • 2.0.0



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/mongo/auth/cr/conversation.rb', line 49

def start(connection)
  if connection && connection.features.op_msg_enabled?
    selector = Auth::GET_NONCE.merge(Protocol::Msg::DATABASE_IDENTIFIER => user.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(
      user.auth_source,
      Database::COMMAND,
      Auth::GET_NONCE,
      limit: -1)
  end
end