Class: Mongo::Auth::Gssapi::Conversation Private

Inherits:
SaslConversationBase show all
Defined in:
lib/mongo/auth/gssapi/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.

Defines behavior around a single Kerberos conversation between the client and the server.

Since:

  • 2.0.0

Constant Summary collapse

START_MESSAGE =

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 base client first message.

Since:

  • 2.0.0

{ saslStart: 1, autoAuthorize: 1 }.freeze
CONTINUE_MESSAGE =

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 base client continue message.

Since:

  • 2.0.0

{ saslContinue: 1 }.freeze

Constants inherited from SaslConversationBase

SaslConversationBase::CLIENT_CONTINUE_MESSAGE, SaslConversationBase::CLIENT_FIRST_MESSAGE

Instance Attribute Summary collapse

Attributes inherited from ConversationBase

#connection, #user

Instance Method Summary collapse

Methods inherited from SaslConversationBase

#start

Methods inherited from ConversationBase

#build_message, #speculative_auth_document, #validate_external_auth_source

Constructor Details

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

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.

Examples:

Create the new conversation.

Conversation.new(user, 'test.example.com')

Parameters:

  • user (Auth::User)

    The user to converse about.

  • connection (Mongo::Connection)

    The connection to authenticate over.

Since:

  • 2.0.0



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/mongo/auth/gssapi/conversation.rb', line 41

def initialize(user, connection, **opts)
  super
  host = connection.address.host
  require 'mongo_kerberos' unless defined?(Mongo::GssapiNative)
  @authenticator = Mongo::GssapiNative::Authenticator.new(
    user.name,
    host,
    user.auth_mech_properties[:service_name] || 'mongodb',
    user.auth_mech_properties[:canonicalize_host_name] || false
  )
end

Instance Attribute Details

#authenticatorAuthenticator (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 authenticator The native SASL authenticator.

Returns:

  • (Authenticator)

    authenticator The native SASL authenticator.

Since:

  • 2.0.0



54
55
56
# File 'lib/mongo/auth/gssapi/conversation.rb', line 54

def authenticator
  @authenticator
end

#idInteger (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.

Get the id of the conversation.

Returns:

  • (Integer)

    The conversation id.

Since:

  • 2.0.0



59
60
61
# File 'lib/mongo/auth/gssapi/conversation.rb', line 59

def id
  @id
end

Instance Method Details

#client_first_documentObject

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



61
62
63
64
# File 'lib/mongo/auth/gssapi/conversation.rb', line 61

def client_first_document
  start_token = authenticator.initialize_challenge
  START_MESSAGE.merge(mechanism: Gssapi::MECHANISM, payload: start_token)
end

#continue(reply_document, connection) ⇒ 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.

Continue the conversation.

Parameters:

  • reply_document (BSON::Document)

    The reply document of the previous message.

Returns:

Since:

  • 2.0.0



72
73
74
75
76
77
78
79
# File 'lib/mongo/auth/gssapi/conversation.rb', line 72

def continue(reply_document, connection)
  @id = reply_document['conversationId']
  payload = reply_document['payload']

  continue_token = authenticator.evaluate_challenge(payload)
  selector = CONTINUE_MESSAGE.merge(payload: continue_token, conversationId: id)
  build_message(connection, '$external', selector)
end

#finalize(connection) ⇒ 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 next query to execute.

Returns:

Since:

  • 2.0.0



88
89
90
91
# File 'lib/mongo/auth/gssapi/conversation.rb', line 88

def finalize(connection)
  selector = CONTINUE_MESSAGE.merge(payload: @continue_token, conversationId: id)
  build_message(connection, '$external', selector)
end

#process_continue_response(reply_document) ⇒ Object

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



81
82
83
84
85
# File 'lib/mongo/auth/gssapi/conversation.rb', line 81

def process_continue_response(reply_document)
  payload = reply_document['payload']

  @continue_token = authenticator.evaluate_challenge(payload)
end