summaryrefslogtreecommitdiffstats
path: root/src/libs/installer/metadatajob.cpp
diff options
context:
space:
mode:
authorkh <karsten.heimrich@theqtcompany.com>2014-11-25 12:21:33 +0100
committerKarsten Heimrich <karsten.heimrich@theqtcompany.com>2014-11-26 14:48:53 +0100
commitd18b9696e573aa7b3f38784f6c5764b9fe6fd81b (patch)
treeb322cefe545a6425a0d87c7ef191fcda973fbb98 /src/libs/installer/metadatajob.cpp
parentd81176d2dd3b03cc6a2f9d69e1fd1e90832a0374 (diff)
Implement server authentication and updating repository credentials.
Task-number: QTIFW-570 Change-Id: I7b6b1fab8279331e5cb4b4da86726322b44a1109 Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com> Reviewed-by: Leena Miettinen <riitta-leena.miettinen@theqtcompany.com>
Diffstat (limited to 'src/libs/installer/metadatajob.cpp')
-rw-r--r--src/libs/installer/metadatajob.cpp66
1 files changed, 49 insertions, 17 deletions
diff --git a/src/libs/installer/metadatajob.cpp b/src/libs/installer/metadatajob.cpp
index ead3dd922..2b5b798b4 100644
--- a/src/libs/installer/metadatajob.cpp
+++ b/src/libs/installer/metadatajob.cpp
@@ -38,6 +38,7 @@
#include "packagemanagerproxyfactory.h"
#include "productkeycheck.h"
#include "proxycredentialsdialog.h"
+#include "serverauthenticationdialog.h"
#include "settings.h"
#include <QTemporaryDir>
@@ -117,24 +118,55 @@ void MetadataJob::xmlTaskFinished()
try {
m_xmlTask.waitForFinished();
status = parseUpdatesXml(m_xmlTask.future().results());
- } catch (const ProxyAuthenticationRequiredException &e) {
- //! will be shown as title in the UI dialog
-
- const QNetworkProxy proxy = e.proxy();
- ProxyCredentialsDialog proxyCredentials(proxy);
- qDebug() << e.message();
-
- if (proxyCredentials.exec() == QDialog::Accepted) {
- qDebug() << "Retrying with new credentials ...";
- PackageManagerProxyFactory *factory = m_core->proxyFactory();
+ } catch (const AuthenticationRequiredException &e) {
+ if (e.type() == AuthenticationRequiredException::Type::Proxy) {
+ const QNetworkProxy proxy = e.proxy();
+ ProxyCredentialsDialog proxyCredentials(proxy);
+ qDebug() << e.message();
+
+ if (proxyCredentials.exec() == QDialog::Accepted) {
+ qDebug() << "Retrying with new credentials ...";
+ PackageManagerProxyFactory *factory = m_core->proxyFactory();
+
+ factory->setProxyCredentials(proxy, proxyCredentials.userName(),
+ proxyCredentials.password());
+ m_core->setProxyFactory(factory);
+ status = XmlDownloadRetry;
+ } else {
+ reset();
+ emitFinishedWithError(QInstaller::DownloadError, tr("Missing proxy credentials."));
+ }
+ } else if (e.type() == AuthenticationRequiredException::Type::Server) {
+ qDebug() << e.message();
+ ServerAuthenticationDialog dlg(e.message(), e.taskItem());
+ if (dlg.exec() == QDialog::Accepted) {
+ Repository original = e.taskItem().value(TaskRole::UserRole)
+ .value<Repository>();
+ Repository replacement = original;
+ replacement.setUsername(dlg.user());
+ replacement.setPassword(dlg.password());
+
+ Settings &s = m_core->settings();
+ QSet<Repository> temporaries = s.temporaryRepositories();
+ if (temporaries.contains(original)) {
+ temporaries.remove(original);
+ temporaries.insert(replacement);
+ s.addTemporaryRepositories(temporaries, true);
+ } else {
+ QHash<QString, QPair<Repository, Repository> > update;
+ update.insert(QLatin1String("replace"), qMakePair(original, replacement));
- factory->setProxyCredentials(proxy, proxyCredentials.userName(),
- proxyCredentials.password());
- m_core->setProxyFactory(factory);
- status = XmlDownloadRetry;
- } else {
- reset();
- emitFinishedWithError(QInstaller::DownloadError, tr("Missing proxy credentials."));
+ if (s.updateDefaultRepositories(update) == Settings::UpdatesApplied
+ || s.updateUserRepositories(update) == Settings::UpdatesApplied) {
+ if (m_core->isUpdater() || m_core->isPackageManager())
+ m_core->writeMaintenanceConfigFiles();
+ }
+ }
+ status = XmlDownloadRetry;
+ } else {
+ reset();
+ emitFinishedWithError(QInstaller::DownloadError, tr("Authentication failed."));
+ }
}
} catch (const TaskException &e) {
reset();