void ConnectionDiagnosticThread::run()
    {
        boost::scoped_ptr<mongo::DBClientConnection> connection;

        try {
            connection.reset(new mongo::DBClientConnection);
            connection->connect(_connection->info());
            emit connectionStatus("", true);
        }
        catch(const mongo::UserException &ex) {
            const char *what = ex.what();
            emit connectionStatus(QString(what), false);
            emit completed();
            return;
        }

        try {
            if (_connection->hasEnabledPrimaryCredential())
            {
                CredentialSettings *credential = _connection->primaryCredential();
                std::string database = credential->databaseName();
                std::string username = credential->userName();
                std::string password = credential->userPassword();

                std::string errmsg;
                bool ok = connection->auth(database, username, password, errmsg);
                emit authStatus("", ok);
            }
        } catch (const mongo::UserException &) {
            emit authStatus("", false);
        }

        emit completed();
    }
예제 #2
0
    /**
     * @brief Converts to QVariantMap
     */
    QVariant ConnectionSettings::toVariant() const
    {
        QVariantMap map;
        map.insert("connectionName", QtUtils::toQString(connectionName()));
        map.insert("serverHost", QtUtils::toQString(serverHost()));
        map.insert("serverPort", serverPort());
        map.insert("defaultDatabase", QtUtils::toQString(defaultDatabase()));
        map.insert("isReplicaSet", isReplicaSet());
        if (isReplicaSet()) {
            map.insert("replicaSet", _replicaSetSettings->toVariant());
        }

#ifdef MONGO_SSL
        SSLInfo infl = _info.sslInfo();
        map.insert("sslEnabled", infl._sslSupport);
        map.insert("sslPemKeyFile", QtUtils::toQString(infl._sslPEMKeyFile));
#endif
        QVariantList list;
        for (QList<CredentialSettings *>::const_iterator it = _credentials.begin(); it != _credentials.end(); ++it) {
            CredentialSettings *credential = *it;
            list.append(credential->toVariant());
        }
        map.insert("credentials", list);

        map.insert("ssh", _sshSettings->toVariant());
        map.insert("ssl", _sslSettings->toVariant());
        map.insert("uuid", _uuid); 

        return map;
    }
예제 #3
0
    ConnectionAuthTab::ConnectionAuthTab(ConnectionSettings *settings) :
        _settings(settings)
    {
        _databaseNameDescriptionLabel = new QLabel(
            "<nobr>The <code>admin</code> database is unique in MongoDB.</nobr> Users with normal access "
            "to the <code>admin</code> database have read and write access to <b>all "
            "databases</b>.");

        _databaseNameDescriptionLabel->setWordWrap(true);
        _databaseNameDescriptionLabel->setAlignment(Qt::AlignTop);
        _databaseNameDescriptionLabel->setContentsMargins(0, -2, 0, 0);
        _databaseNameDescriptionLabel->setMinimumSize(_databaseNameDescriptionLabel->sizeHint());

        _userName = new QLineEdit();
        _userNameLabel = new QLabel("User Name");
        _userPassword = new QLineEdit();
        _userPassword->setEchoMode(QLineEdit::Password);
        _userPasswordLabel = new QLabel("Password");
        _databaseName = new QLineEdit("admin");
        _databaseNameLabel = new QLabel("Database");

        _useAuth = new QCheckBox("Perform authentication");
        _useAuth->setStyleSheet("margin-bottom: 7px");
        VERIFY(connect(_useAuth, SIGNAL(toggled(bool)), this, SLOT(authChecked(bool))));

        _echoModeButton = new QPushButton("Show");
        VERIFY(connect(_echoModeButton, SIGNAL(clicked()), this, SLOT(toggleEchoMode())));

        _useAuth->setChecked(_settings->hasEnabledPrimaryCredential());
        authChecked(_settings->hasEnabledPrimaryCredential());

        if (_settings->credentialCount() > 0) {
            CredentialSettings *primaryCredential = _settings->primaryCredential();
            _userName->setText(QtUtils::toQString(primaryCredential->userName()));
            _userPassword->setText(QtUtils::toQString(primaryCredential->userPassword()));
            _databaseName->setText(QtUtils::toQString(primaryCredential->databaseName()));
        }

        QGridLayout *_authLayout = new QGridLayout;
        _authLayout->addWidget(_useAuth,                      0, 0, 1, 3);
        _authLayout->addWidget(_databaseNameLabel,            1, 0);
        _authLayout->addWidget(_databaseName,                 1, 1, 1, 2);
        _authLayout->addWidget(_databaseNameDescriptionLabel, 2, 1, 1, 2);
        _authLayout->addWidget(_userNameLabel,                3, 0);
        _authLayout->addWidget(_userName,                     3, 1, 1, 2);
        _authLayout->addWidget(_userPasswordLabel,            4, 0);
        _authLayout->addWidget(_userPassword,                 4, 1);
        _authLayout->addWidget(_echoModeButton,               4, 2);
        _authLayout->setAlignment(Qt::AlignTop);

        QVBoxLayout *mainLayout = new QVBoxLayout;
        mainLayout->addLayout(_authLayout);
        setLayout(mainLayout);
    }
예제 #4
0
 CredentialSettings *ConnectionSettings::findCredential(const std::string &databaseName) const
 {
     CredentialSettings *result = nullptr;
     for (QList<CredentialSettings *>::const_iterator it = _credentials.begin(); it != _credentials.end(); ++it) {
         CredentialSettings *cred = *it;
         if (cred->databaseName() == databaseName) {
             result = cred;
             break;
         }
     }
     return result;
 }
예제 #5
0
    void ConnectionAuthTab::accept()
    {
        _settings->clearCredentials();

        // If all fields is empty - do nothing
        if (_userName->text().isEmpty()     &&
            _userPassword->text().isEmpty() &&
            _databaseName->text().isEmpty())
            return;       

        CredentialSettings *credential = new CredentialSettings();
        credential->setEnabled(_useAuth->isChecked());
        credential->setUserName(QtUtils::toStdString(_userName->text()));
        credential->setUserPassword(QtUtils::toStdString(_userPassword->text()));
        credential->setDatabaseName(QtUtils::toStdString(_databaseName->text()));
        _settings->addCredential(credential);
    }
예제 #6
0
void ConnectionDiagnosticThread::run()
{
    QString address = QString("%1:%2")
        .arg(_connection->serverHost())
        .arg(_connection->serverPort());

    boost::scoped_ptr<DBClientConnection> connection;

    try {
        connection.reset(new DBClientConnection);
        connection->connect(address.toStdString());
        emit connectionStatus("", true);
    }
    catch(UserException &ex) {
        const char *what = ex.what();
        emit connectionStatus(QString(what), false);
        emit completed();
        return;
    }

    try {
        if (_connection->hasEnabledPrimaryCredential())
        {
            CredentialSettings *credential = _connection->primaryCredential();
            QString database = credential->databaseName();
            QString username = credential->userName();
            QString password = credential->userPassword();

            string errmsg;
            bool ok = connection->auth(database.toStdString(), username.toStdString(), password.toStdString(), errmsg);
            if (!ok) {
                emit authStatus("", false);
            } else {
                emit authStatus("", true);
            }
        }
    } catch (UserException &ex) {
        emit authStatus("", false);
    }

    emit completed();
}