Commit b3930fd6 authored by John Tourtellott's avatar John Tourtellott
Browse files

Update authentication logic to include multifactor token

* MFA not mandatory at NERSC
* Also fix some signal-slot mismatches in jobrequest.cxx
parent 579a3749
......@@ -15,16 +15,16 @@
#include "jobrequest.h"
#include "utils.h"
#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
#include <QtCore/QList>
#include <QtCore/QThread>
#include <QtCore/QUrlQuery>
#include <QtCore/QVariant>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkCookie>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkRequest>
#include <QCoreApplication>
#include <QDebug>
#include <QList>
#include <QThread>
#include <QUrlQuery>
#include <QVariant>
#include <QNetworkAccessManager>
#include <QNetworkCookie>
#include <QNetworkReply>
#include <QNetworkRequest>
namespace
{
......@@ -124,6 +124,10 @@ void CumulusProxy::authenticationNewtFinished()
m_newtSessionId.clear();
m_newtSessionId.append(sessionId);
int lifetime = cJSON_GetObjectItem(reply, "session_lifetime")->valueint;
qInfo() << "Logged into NERSC with NEWT Session id" << sessionId;
emit this->newtSessionId(sessionId, lifetime);
// Now authenticate with Girder
this->authenticateGirder(m_newtSessionId);
}
......
......@@ -60,6 +60,7 @@ signals:
void jobTerminated(cumulus::Job job);
void jobDownloaded(cumulus::Job job, const QString& path);
void info(const QString& msg);
void newtSessionId(const QString& sessionId, int lifetime);
private slots:
void authenticationNewtFinished();
......
......@@ -55,6 +55,9 @@ CumulusWidget::CumulusWidget(QWidget* parentObject)
connect(
m_jobTableModel, &JobTableModel::finishTimeChanged, m_cumulusProxy, &CumulusProxy::patchJobs);
// Relay newt session id from proxy
connect(m_cumulusProxy, &CumulusProxy::newtSessionId, this, &CumulusWidget::newtSessionId);
// Instantiate polling timer (but don't start)
m_timer = new QTimer(this);
m_timer->setInterval(timer_period_msec);
......
......@@ -57,6 +57,7 @@ public:
signals:
void info(const QString& msg);
void resultDownloaded(const QString& path);
void newtSessionId(const QString& sessionId, int lifetime);
protected:
void createJobTable();
......
......@@ -13,14 +13,14 @@
#include "cumulusproxy.h"
#include "utils.h"
#include <QtCore/QDebug>
#include <QtCore/QList>
#include <QtCore/QTimer>
#include <QtCore/QVariant>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkCookie>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkRequest>
#include <QDebug>
#include <QList>
#include <QTimer>
#include <QVariant>
#include <QNetworkAccessManager>
#include <QNetworkCookie>
#include <QNetworkReply>
#include <QNetworkRequest>
namespace cumulus
{
......@@ -54,14 +54,13 @@ void DeleteJobRequest::send()
request.setRawHeader(QByteArray("Girder-Token"), m_girderToken.toUtf8());
QObject::connect(
m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(finished(QNetworkReply*)));
m_networkManager, &QNetworkAccessManager::finished, this, &DeleteJobRequest::finished);
m_networkManager->deleteResource(request);
}
void DeleteJobRequest::finished()
void DeleteJobRequest::finished(QNetworkReply* reply)
{
auto reply = qobject_cast<QNetworkReply*>(this->sender());
QByteArray bytes = reply->readAll();
if (reply->error())
{
......@@ -92,7 +91,7 @@ void TerminateJobRequest::send()
request.setRawHeader(QByteArray("Girder-Token"), m_girderToken.toUtf8());
QObject::connect(
m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(finished(QNetworkReply*)));
m_networkManager, &QNetworkAccessManager::finished, this, &TerminateJobRequest::finished);
QByteArray empty;
m_networkManager->put(request, empty);
......@@ -133,10 +132,10 @@ void DownloadJobRequest::send()
DownloadFolderRequest* request = new DownloadFolderRequest(
m_networkManager, m_girderUrl, m_girderToken, m_downloadPath, folderId, this);
connect(request, SIGNAL(complete()), this, SLOT(downloadFolderFinished()));
connect(request, SIGNAL(error(const QString, QNetworkReply*)), this,
SIGNAL(error(const QString, QNetworkReply*)));
connect(request, SIGNAL(info(const QString)), this, SIGNAL(info(const QString)));
connect(
request, &DownloadFolderRequest::complete, this, &DownloadJobRequest::downloadFolderFinished);
connect(request, &DownloadFolderRequest::error, this, &DownloadJobRequest::error);
connect(request, &DownloadFolderRequest::info, this, &DownloadJobRequest::info);
request->send();
}
......@@ -179,7 +178,7 @@ void PatchJobRequest::send()
// Qt doesn't have native patch method; must use custom request
auto reply = m_networkManager->sendCustomRequest(request, "PATCH", data);
QObject::connect(reply, SIGNAL(finished()), this, SLOT(finished()));
QObject::connect(reply, &QNetworkReply::finished, this, &PatchJobRequest::finished);
free(jsonString);
}
......
......@@ -55,7 +55,7 @@ public:
void send();
private slots:
void finished();
void finished(QNetworkReply*);
};
class TerminateJobRequest : public JobRequest
......
......@@ -30,15 +30,18 @@ LoginDialog::~LoginDialog()
void LoginDialog::accept()
{
emit entered(ui->usernameEdit->text(), ui->credentialsEdit->text());
ui->credentialsEdit->clear();
QString password = ui->passwordEdit->text() + ui->mfaEdit->text();
emit entered(ui->usernameEdit->text(), password);
ui->passwordEdit->clear();
ui->mfaEdit->clear();
ui->messageLabel->clear();
QDialog::accept();
}
void LoginDialog::reject()
{
ui->credentialsEdit->clear();
ui->passwordEdit->clear();
ui->mfaEdit->clear();
ui->messageLabel->clear();
QDialog::reject();
}
......
......@@ -7,27 +7,17 @@
<x>0</x>
<y>0</y>
<width>408</width>
<height>196</height>
<height>173</height>
</rect>
</property>
<property name="windowTitle">
<string>NERSC NEWT login</string>
<string>NERSC Login</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="hostLabel">
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<item row="0" column="0" colspan="2">
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
......@@ -35,36 +25,33 @@
<property name="labelAlignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<item row="1" column="1">
<widget class="QLineEdit" name="credentialsEdit">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
<item row="0" column="1">
<widget class="QLineEdit" name="usernameEdit">
<property name="placeholderText">
<string>NERSC Username</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="promptLabel">
<property name="enabled">
<bool>true</bool>
<item row="2" column="1">
<widget class="QLineEdit" name="passwordEdit">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
<property name="text">
<property name="placeholderText">
<string>Password</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="usernameEdit"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="usernameLabel">
<property name="text">
<string>Username</string>
<item row="3" column="1">
<widget class="QLineEdit" name="mfaEdit">
<property name="placeholderText">
<string>MFA Token</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="messageLabel">
<property name="text">
<string/>
......@@ -74,7 +61,7 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<item row="2" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -87,7 +74,7 @@
</property>
</spacer>
</item>
<item row="4" column="1">
<item row="3" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
......@@ -101,7 +88,7 @@
</widget>
<tabstops>
<tabstop>usernameEdit</tabstop>
<tabstop>credentialsEdit</tabstop>
<tabstop>passwordEdit</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment