diff options
author | Sara Golemon <sara.golemon@mongodb.com> | 2022-02-08 19:08:58 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-02-11 17:24:02 +0000 |
commit | b357b0f68d0ff3323cebde97a560c3f42843237b (patch) | |
tree | 30b1075a226eed26a9b7f4a5d137827db68e9f37 | |
parent | 89600c35511ce81a62ae235b27746a0698bdfef2 (diff) | |
download | mongo-b357b0f68d0ff3323cebde97a560c3f42843237b.tar.gz |
SERVER-61426 Use 'db' parameter to speculativeAuthenticate.authenticate when available
-rw-r--r-- | src/mongo/db/commands/authentication_commands.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/mongo/db/commands/authentication_commands.cpp b/src/mongo/db/commands/authentication_commands.cpp index 54da7293068..0fef67553d0 100644 --- a/src/mongo/db/commands/authentication_commands.cpp +++ b/src/mongo/db/commands/authentication_commands.cpp @@ -427,13 +427,20 @@ void doSpeculativeAuthenticate(OperationContext* opCtx, // but coming from the Hello command has it in the "db" field. // Rewrite it for handling here. BSONObjBuilder cmd; + bool hasDBField = false; for (const auto& elem : cmdObj) { - if (elem.fieldName() != kDBFieldName) { + if (elem.fieldName() == kDBFieldName) { + cmd.appendAs(elem, AuthenticateCommand::kDbNameFieldName); + hasDBField = true; + } else { cmd.append(elem); } } - cmd.append(AuthenticateCommand::kDbNameFieldName, kExternalDB); + if (!hasDBField) { + // No "db" field was provided, so default to "$external" + cmd.append(AuthenticateCommand::kDbNameFieldName, kExternalDB); + } auto authCmdObj = AuthenticateCommand::parse( IDLParserErrorContext("speculative X509 Authenticate"), cmd.obj()); |