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



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/mongo/auth/gssapi/conversation.rb', line 44

def initialize(user, connection, **opts)
  super
  host = connection.address.host
  unless defined?(Mongo::GssapiNative)
    require 'mongo_kerberos'
  end
  @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



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

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



64
65
66
# File 'lib/mongo/auth/gssapi/conversation.rb', line 64

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



66
67
68
69
# File 'lib/mongo/auth/gssapi/conversation.rb', line 66

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



77
78
79
80
81
82
83
84
# File 'lib/mongo/auth/gssapi/conversation.rb', line 77

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



93
94
95
96
# File 'lib/mongo/auth/gssapi/conversation.rb', line 93

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



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

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

  @continue_token = authenticator.evaluate_challenge(payload)
end