Class: Mongo::Auth::ConversationBase Private

Inherits:
Object
  • Object
show all
Defined in:
build/ruby-driver-master/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

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.

Parameters:

  • user (Auth::User)

    The user to authenticate.

  • connection (Mongo::Connection)

    The connection to authenticate over.

Since:

  • 2.0.0



32
33
34
35
# File 'build/ruby-driver-master/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.

Returns:

  • (Mongo::Connection)

    The connection to authenticate over.

Since:

  • 2.0.0



41
42
43
# File 'build/ruby-driver-master/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.

Returns:

  • (Auth::User)

    user The user for the conversation.

Since:

  • 2.0.0



38
39
40
# File 'build/ruby-driver-master/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.

Returns:

Since:

  • 2.0.0



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'build/ruby-driver-master/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.

Returns:

  • (Hash | nil)

    Speculative authentication document.

Since:

  • 2.0.0



50
51
52
# File 'build/ruby-driver-master/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



74
75
76
77
78
79
80
81
82
83
84
# File 'build/ruby-driver-master/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