Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions src/robomongo/core/engine/ScriptEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,36 @@ namespace Robomongo

std::stringstream ss;
auto hostAndPort = serverAddr.empty() ? _connection->hostAndPort().toString() : serverAddr;
ss << "db = connect('" << hostAndPort << "/" << connectDatabase;
ss << "db = connect('" << hostAndPort << "/" << connectDatabase << "')\n";

// v0.9
// ss << "db = connect('" << _connection->serverHost() << ":" << _connection->serverPort() << _connection->sslInfo() << _connection->sshInfo() << "/" << connectDatabase;

if (!_connection->hasEnabledPrimaryCredential())
ss << "')";
else
ss << "', '"
<< _connection->primaryCredential()->userName() << "', '"
<< _connection->primaryCredential()->userPassword() << "')";

{
mongo::shell_utils::_dbConnect = ss.str();
mongo::shell_utils::_dbAuth = "(function() { \nDB.prototype._defaultGssapiServiceName = \"mongodb\";\n}())";
std::stringstream authStringStream;
authStringStream << "(function() {\n";
if (!_connection->primaryCredential()->mechanism().empty()) {
authStringStream << "DB.prototype._defaultAuthenticationMechanism = \""
<< _connection->primaryCredential()->mechanism() << "\";\n";
}
authStringStream << "DB.prototype._defaultGssapiServiceName = \"mongodb\";\n";
authStringStream << "var username = \"" << _connection->primaryCredential()->userName() << "\";\n";
authStringStream << "var password = \"" << _connection->primaryCredential()->userPassword() << "\";\n";
if (_connection->primaryCredential()->databaseName().empty()) {
authStringStream << "var authDb = db;\n";
} else {
authStringStream << "var authDb = db.getSiblingDB(\""
<< _connection->primaryCredential()->databaseName() << "\");\n";
}
authStringStream << "authDb.auth({ user: username";
authStringStream << ", pwd: password";
if (_connection->primaryCredential()->mechanism() == "PLAIN") {
authStringStream << ", digestPassword: false";
}
authStringStream << ", mechanism: \"" << _connection->primaryCredential()->mechanism() << "\" });\n";
authStringStream << "}())";

mongo::shell_utils::_dbAuth = authStringStream.str();

// v0.9
// mongo::isShell = true;
Expand Down
29 changes: 20 additions & 9 deletions src/robomongo/core/mongodb/MongoWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,31 @@ namespace Robomongo
CredentialSettings *credentials = _connSettings->primaryCredential();

// Building BSON object:
mongo::BSONObj authParams(mongo::BSONObjBuilder()
.append("user", credentials->userName())
.append("db", credentials->databaseName())
.append("pwd", credentials->userPassword())
.append("mechanism", credentials->mechanism())
.obj());

conn->auth(authParams);
if (credentials->mechanism() == "PLAIN") {
mongo::BSONObj authParams(mongo::BSONObjBuilder()
.append("user", credentials->userName())
.append("db", credentials->databaseName())
.append("pwd", credentials->userPassword())
.append("mechanism", credentials->mechanism())
.append("digestPassword", false)
.obj());
conn->auth(authParams);
} else {
mongo::BSONObj authParams(mongo::BSONObjBuilder()
.append("user", credentials->userName())
.append("db", credentials->databaseName())
.append("pwd", credentials->userPassword())
.append("mechanism", credentials->mechanism())
.obj());

conn->auth(authParams);
}

// If authentication succeed and database name is 'admin' -
// then user is admin, otherwise user is not admin
std::string dbName = credentials->databaseName();
std::transform(dbName.begin(), dbName.end(), dbName.begin(), ::tolower);
if (dbName.compare("admin") != 0) // dbName is NOT "admin"
if (dbName.compare("admin") != 0 && dbName.compare("$external") != 0) // dbName is NOT "admin"
_isAdmin = false;
}

Expand Down
1 change: 1 addition & 0 deletions src/robomongo/gui/dialogs/ConnectionAuthTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace Robomongo
_mechanismComboBox = new QComboBox();
_mechanismComboBox->addItem("SCRAM-SHA-1");
_mechanismComboBox->addItem("MONGODB-CR");
_mechanismComboBox->addItem("PLAIN");

_useAuth = new QCheckBox("Perform authentication");
_useAuth->setStyleSheet("margin-bottom: 7px");
Expand Down