lib/mongo/auth/ldap/conversation.rb in mongo-2.4.3 vs lib/mongo/auth/ldap/conversation.rb in mongo-2.5.0.beta
- old
+ new
@@ -25,11 +25,11 @@
# The login message.
#
# @since 2.0.0
LOGIN = { saslStart: 1, autoAuthorize: 1 }.freeze
- # @return [ Protocol::Reply ] reply The current reply in the
+ # @return [ Protocol::Message ] reply The current reply in the
# conversation.
attr_reader :reply
# @return [ User ] user The user for the conversation.
attr_reader :user
@@ -38,11 +38,11 @@
# the provided reply indicates the conversation is finished.
#
# @example Finalize the conversation.
# conversation.finalize(reply)
#
- # @param [ Protocol::Reply ] reply The reply of the previous
+ # @param [ Protocol::Message ] reply The reply of the previous
# message.
#
# @return [ Protocol::Query ] The next message to send.
#
# @since 2.0.0
@@ -54,19 +54,29 @@
# needs to be send to the server.
#
# @example Start the conversation.
# conversation.start
#
+ # @param [ Mongo::Server::Connection ] connection The connection being authenticated.
+ #
# @return [ Protocol::Query ] The first PLAIN conversation message.
#
# @since 2.0.0
- def start
- Protocol::Query.new(
- Auth::EXTERNAL,
- Database::COMMAND,
- LOGIN.merge(payload: payload, mechanism: LDAP::MECHANISM),
- limit: -1
- )
+ def start(connection = nil)
+ if connection && connection.features.op_msg_enabled?
+ selector = LOGIN.merge(payload: payload, mechanism: LDAP::MECHANISM)
+ selector[Protocol::Msg::DATABASE_IDENTIFIER] = Auth::EXTERNAL
+ cluster_time = connection.mongos? && connection.cluster_time
+ selector[Operation::CLUSTER_TIME] = cluster_time if cluster_time
+ Protocol::Msg.new([:none], {}, selector)
+ else
+ Protocol::Query.new(
+ Auth::EXTERNAL,
+ Database::COMMAND,
+ LOGIN.merge(payload: payload, mechanism: LDAP::MECHANISM),
+ limit: -1
+ )
+ end
end
# Create the new conversation.
#
# @example Create the new conversation.