X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fcore.cpp;h=bb1df473173a3042e7516e38ab1ba8f41c78108f;hp=67f3a8151b8c7f2551fa9442dc6c343ee3e5aa57;hb=39c33d8cbaecdd1e5c756a715bef87844149ae5b;hpb=8965e63594dd297347afced784dcaed6c26b7c6a diff --git a/src/core/core.cpp b/src/core/core.cpp index 67f3a815..bb1df473 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -175,7 +175,7 @@ Core::Core() } registerStorageBackends(); - registerAuthenticatorBackends(); + registerAuthenticators(); connect(&_storageSyncTimer, SIGNAL(timeout()), this, SLOT(syncStorage())); _storageSyncTimer.start(10 * 60 * 1000); // 10 minutes @@ -191,7 +191,7 @@ void Core::init() // Not entirely sure what is 'legacy' about the above, but it seems to be the way things work! QVariantMap authSettings = cs.authSettings().toMap(); - initAuthenticator(authSettings.value("AuthBackend").toString(), authSettings.value("ConnectionProperties").toMap()); + initAuthenticator(authSettings.value("Authenticator").toString(), authSettings.value("AuthProperties").toMap()); if (Quassel::isOptionSet("select-backend") || Quassel::isOptionSet("select-authenticator")) { if (Quassel::isOptionSet("select-backend")) { @@ -248,7 +248,7 @@ Core::~Core() } qDeleteAll(_sessions); qDeleteAll(_storageBackends); - qDeleteAll(_authenticatorBackends); + qDeleteAll(_authenticators); } @@ -299,13 +299,13 @@ void Core::restoreState() /*** Core Setup ***/ -QString Core::setup(const QString &adminUser, const QString &adminPassword, const QString &backend, const QVariantMap &setupData, const QString &authBackend, const QVariantMap &authSetupData) +QString Core::setup(const QString &adminUser, const QString &adminPassword, const QString &backend, const QVariantMap &setupData, const QString &authenticator, const QVariantMap &authSetupData) { - return instance()->setupCore(adminUser, adminPassword, backend, setupData, authBackend, authSetupData); + return instance()->setupCore(adminUser, adminPassword, backend, setupData, authenticator, authSetupData); } -QString Core::setupCore(const QString &adminUser, const QString &adminPassword, const QString &backend, const QVariantMap &setupData, const QString &authBackend, const QVariantMap &authSetupData) +QString Core::setupCore(const QString &adminUser, const QString &adminPassword, const QString &backend, const QVariantMap &setupData, const QString &authenticator, const QVariantMap &authSetupData) { if (_configured) return tr("Core is already configured! Not configuring again..."); @@ -317,8 +317,8 @@ QString Core::setupCore(const QString &adminUser, const QString &adminPassword, return tr("Could not setup storage!"); } - quInfo() << "Selected authenticator: " << authBackend; - if (!(_configured = initAuthenticator(authBackend, authSetupData, true))) + quInfo() << "Selected authenticator:" << authenticator; + if (!(_configured = initAuthenticator(authenticator, authSetupData, true))) { return tr("Could not setup authenticator!"); } @@ -326,7 +326,7 @@ QString Core::setupCore(const QString &adminUser, const QString &adminPassword, if (!saveBackendSettings(backend, setupData)) { return tr("Could not save backend settings, probably a permission problem."); } - saveAuthBackendSettings(authBackend, authSetupData); + saveAuthenticatorSettings(authenticator, authSetupData); quInfo() << qPrintable(tr("Creating admin user...")); _storage->addUser(adminUser, adminPassword); @@ -347,7 +347,7 @@ QString Core::setupCoreForInternalUsage() } // mono client currently needs sqlite - return setupCore("AdminUser", QString::number(pass), "SQLite", QVariantMap(), "StorageAuth", QVariantMap()); + return setupCore("AdminUser", QString::number(pass), "SQLite", QVariantMap(), "Database", QVariantMap()); } @@ -372,6 +372,7 @@ bool Core::registerStorageBackend(Storage *backend) } } + void Core::unregisterStorageBackends() { foreach(Storage *s, _storageBackends.values()) { @@ -390,40 +391,41 @@ void Core::unregisterStorageBackend(Storage *backend) // Authentication handling, now independent from storage. // Register and unregister authenticators. -void Core::registerAuthenticatorBackends() +void Core::registerAuthenticators() { // Register new authentication backends here! - registerAuthenticatorBackend(new SqlAuthenticator(this)); + registerAuthenticator(new SqlAuthenticator(this)); #ifdef HAVE_LDAP - registerAuthenticatorBackend(new LdapAuthenticator(this)); + registerAuthenticator(new LdapAuthenticator(this)); #endif - } -bool Core::registerAuthenticatorBackend(Authenticator *authenticator) + +bool Core::registerAuthenticator(Authenticator *authenticator) { - if (authenticator->isAvailable()) - { - _authenticatorBackends[authenticator->displayName()] = authenticator; + if (authenticator->isAvailable()) { + _authenticators[authenticator->backendId()] = authenticator; return true; - } else { + } + else { authenticator->deleteLater(); return false; } } -void Core::unregisterAuthenticatorBackends() + +void Core::unregisterAuthenticators() { - foreach(Authenticator* a, _authenticatorBackends.values()) - { + foreach(Authenticator* a, _authenticators.values()) { a->deleteLater(); } - _authenticatorBackends.clear(); + _authenticators.clear(); } -void Core::unregisterAuthenticatorBackend(Authenticator *backend) + +void Core::unregisterAuthenticator(Authenticator *backend) { - _authenticatorBackends.remove(backend->displayName()); + _authenticators.remove(backend->backendId()); backend->deleteLater(); } @@ -467,18 +469,19 @@ bool Core::initStorage(const QString &backend, const QVariantMap &settings, bool return true; } -// XXX: TODO: Apparently, this is legacy? +// FIXME: Apparently, this is the legacy way of initting storage backends? +// If there's a not-legacy way, it should be used here bool Core::initAuthenticator(const QString &backend, const QVariantMap &settings, bool setup) { _authenticator = 0; if (backend.isEmpty()) { - return false; + return false; } Authenticator *authenticator = 0; - if (_authenticatorBackends.contains(backend)) { - authenticator = _authenticatorBackends[backend]; + if (_authenticators.contains(backend)) { + authenticator = _authenticators[backend]; } else { qCritical() << "Selected auth backend is not available:" << backend; @@ -498,13 +501,14 @@ bool Core::initAuthenticator(const QString &backend, const QVariantMap &settings exit(EXIT_FAILURE); case Authenticator::IsReady: // delete all other backends - _authenticatorBackends.remove(backend); - unregisterAuthenticatorBackends(); + _authenticators.remove(backend); + unregisterAuthenticators(); } _authenticator = authenticator; return true; } + void Core::syncStorage() { if (_storage) @@ -789,12 +793,13 @@ QVariantList Core::backendInfo() return backends; } + QVariantList Core::authenticatorInfo() { QVariantList backends; - foreach(const Authenticator *backend, instance()->_authenticatorBackends.values()) { + foreach(const Authenticator *backend, instance()->_authenticators.values()) { QVariantMap v; - v["DisplayName"] = backend->displayName(); + v["DisplayName"] = backend->backendId(); v["Description"] = backend->description(); v["SetupKeys"] = backend->setupKeys(); v["SetupDefaults"] = backend->setupDefaults(); @@ -885,25 +890,25 @@ bool Core::selectBackend(const QString &backend) return true; } -// XXX: I am not sure if this function is implemented correctly. +// TODO: I am not sure if this function is implemented correctly. // There is currently no concept of migraiton between auth backends. bool Core::selectAuthenticator(const QString &backend) { // Register all authentication backends. - registerAuthenticatorBackends(); - if (!_authenticatorBackends.contains(backend)) { + registerAuthenticators(); + if (!_authenticators.contains(backend)) { qWarning() << qPrintable(QString("Core::selectAuthenticator(): unsupported backend: %1").arg(backend)); - qWarning() << " supported backends are:" << qPrintable(QStringList(_authenticatorBackends.keys()).join(", ")); + qWarning() << " supported backends are:" << qPrintable(QStringList(_authenticators.keys()).join(", ")); return false; } - Authenticator *authenticator = _authenticatorBackends[backend]; + Authenticator *authenticator = _authenticators[backend]; QVariantMap settings = promptForSettings(authenticator); Authenticator::State state = authenticator->init(settings); switch (state) { case Authenticator::IsReady: - saveAuthBackendSettings(backend, settings); + saveAuthenticatorSettings(backend, settings); qWarning() << "Switched auth backend to:" << qPrintable(backend); // qWarning() << "Auth backend already initialized. Skipping Migration"; return true; @@ -921,12 +926,12 @@ bool Core::selectAuthenticator(const QString &backend) return false; } - saveAuthBackendSettings(backend, settings); + saveAuthenticatorSettings(backend, settings); qWarning() << "Switched auth backend to:" << qPrintable(backend); } - + _authenticator = authenticator; - return true; + return true; } @@ -980,8 +985,7 @@ bool Core::changeUserPass(const QString &username) return false; } - if (!canChangeUserPassword(userId)) - { + if (!canChangeUserPassword(userId)) { out << "User " << username << " is configured through an auth provider that has forbidden manual password changing." << endl; return false; } @@ -1030,24 +1034,25 @@ bool Core::changeUserPassword(UserId userId, const QString &password) return instance()->_storage->updateUser(userId, password); } -// XXX: this code isn't currently 100% optimal because the core +// TODO: this code isn't currently 100% optimal because the core // doesn't know it can have multiple auth providers configured (there aren't // multiple auth providers at the moment anyway) and we have hardcoded the // Database provider to be always allowed. bool Core::canChangeUserPassword(UserId userId) { QString authProvider = instance()->_storage->getUserAuthenticator(userId); - if (authProvider != "Database") - { - if (authProvider != instance()->_authenticator->displayName()) { + if (authProvider != "Database") { + if (authProvider != instance()->_authenticator->backendId()) { return false; - } else if (instance()->_authenticator->canChangePassword()) { + } + else if (instance()->_authenticator->canChangePassword()) { return false; } } return true; } + AbstractSqlMigrationReader *Core::getMigrationReader(Storage *storage) { if (!storage) @@ -1088,11 +1093,12 @@ bool Core::saveBackendSettings(const QString &backend, const QVariantMap &settin return s.sync(); } -void Core::saveAuthBackendSettings(const QString &backend, const QVariantMap &settings) + +void Core::saveAuthenticatorSettings(const QString &backend, const QVariantMap &settings) { QVariantMap dbsettings; - dbsettings["AuthBackend"] = backend; - dbsettings["ConnectionProperties"] = settings; + dbsettings["Authenticator"] = backend; + dbsettings["AuthProperties"] = settings; CoreSettings().setAuthSettings(dbsettings); } @@ -1153,9 +1159,9 @@ QVariantMap Core::promptForSettings(const Storage *storage) QStringList keys = storage->setupKeys(); QVariantMap defaults = storage->setupDefaults(); return Core::promptForSettings(keys, defaults); - } + QVariantMap Core::promptForSettings(const Authenticator *authenticator) { QStringList keys = authenticator->setupKeys();