mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
Ref T586, allow to do SSO even if the user not yet is enabled in the DB
Rational: user can do authenticated mappings/quick mapping without the account approved
This commit is contained in:
committed by
Mat Sutcliffe
parent
e2e7621e48
commit
f9884cd585
@@ -11,7 +11,6 @@
|
||||
#include "blackcore/db/databaseauthentication.h"
|
||||
#include "blackmisc/json.h"
|
||||
#include "blackmisc/logcategory.h"
|
||||
#include "blackmisc/logcategorylist.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/network/authenticateduser.h"
|
||||
#include "blackmisc/network/networkutils.h"
|
||||
@@ -36,6 +35,12 @@ namespace BlackCore
|
||||
{
|
||||
namespace Db
|
||||
{
|
||||
const CLogCategoryList &CDatabaseAuthenticationService::getLogCategories()
|
||||
{
|
||||
static const CLogCategoryList cats { CLogCategory::swiftDbWebservice() };
|
||||
return cats;
|
||||
}
|
||||
|
||||
CDatabaseAuthenticationService::CDatabaseAuthenticationService(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
@@ -63,9 +68,9 @@ namespace BlackCore
|
||||
CStatusMessageList CDatabaseAuthenticationService::login(const QString &username, const QString &password)
|
||||
{
|
||||
CStatusMessageList msgs;
|
||||
static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::validation()}));
|
||||
static const CLogCategoryList cats(getLogCategories().join({ CLogCategory::validation() }));
|
||||
|
||||
if (m_shutdown) { msgs.push_back(CStatusMessage(cats, CStatusMessage::SeverityError, u"Shutdown in progress")); return msgs; }
|
||||
if (!sApp || m_shutdown) { msgs.push_back(CStatusMessage(cats, CStatusMessage::SeverityError, u"Shutdown in progress")); return msgs; }
|
||||
|
||||
const QString un(username.trimmed());
|
||||
const QString pw(password.trimmed());
|
||||
@@ -96,6 +101,7 @@ namespace BlackCore
|
||||
|
||||
void CDatabaseAuthenticationService::logoff()
|
||||
{
|
||||
if (!sApp) { return; }
|
||||
CUrl url(sApp->getGlobalSetup().getDbLoginServiceUrl());
|
||||
url.setQuery("logoff=true");
|
||||
QNetworkRequest request(CNetworkUtils::getSwiftNetworkRequest(url));
|
||||
@@ -133,7 +139,7 @@ namespace BlackCore
|
||||
|
||||
static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::validation()}));
|
||||
const QJsonObject jsonObj(Json::jsonObjectFromString(json));
|
||||
const CAuthenticatedUser user = CAuthenticatedUser::fromDatabaseJson(jsonObj.contains("user") ? jsonObj["user"].toObject() : jsonObj);
|
||||
CAuthenticatedUser user = CAuthenticatedUser::fromDatabaseJson(jsonObj.contains("user") ? jsonObj["user"].toObject() : jsonObj);
|
||||
CStatusMessageList msgs;
|
||||
if (jsonObj.contains("messages"))
|
||||
{
|
||||
@@ -141,6 +147,16 @@ namespace BlackCore
|
||||
msgs.setCategories(cats);
|
||||
}
|
||||
|
||||
// allow auto enabled for SSO users
|
||||
if (user.isValid() && !user.isEnabled())
|
||||
{
|
||||
if (user.getRoles().hasRole("VATSIMUSER"))
|
||||
{
|
||||
user.setEnabled(true);
|
||||
msgs.push_back(CStatusMessage(cats, CStatusMessage::SeverityInfo, u"Auto enabled SSO user"));
|
||||
}
|
||||
}
|
||||
|
||||
if (!user.isAuthenticated() || !user.isValid())
|
||||
{
|
||||
if (!msgs.hasErrorMessages())
|
||||
|
||||
@@ -11,9 +11,10 @@
|
||||
#ifndef BLACKCORE_DATABASE_CDATABASEUATHENTICATIONSERVICE_H
|
||||
#define BLACKCORE_DATABASE_CDATABASEUATHENTICATIONSERVICE_H
|
||||
|
||||
#include "blackcore/blackcoreexport.h"
|
||||
#include "blackcore/data/authenticateduser.h"
|
||||
#include "blackcore/blackcoreexport.h"
|
||||
#include "blackmisc/datacache.h"
|
||||
#include "blackmisc/logcategorylist.h"
|
||||
#include "blackmisc/statusmessagelist.h"
|
||||
|
||||
#include <QObject>
|
||||
@@ -32,6 +33,9 @@ namespace BlackCore
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Log categories
|
||||
static const BlackMisc::CLogCategoryList &getLogCategories();
|
||||
|
||||
//! Constructor
|
||||
CDatabaseAuthenticationService(QObject *parent = nullptr);
|
||||
|
||||
@@ -64,7 +68,7 @@ namespace BlackCore
|
||||
//! User object changed
|
||||
void userChanged();
|
||||
|
||||
BlackMisc::CData<BlackCore::Data::TAuthenticatedDbUser> m_swiftDbUser {this, &CDatabaseAuthenticationService::userChanged};
|
||||
BlackMisc::CData<BlackCore::Data::TAuthenticatedDbUser> m_swiftDbUser { this, &CDatabaseAuthenticationService::userChanged };
|
||||
bool m_shutdown = false;
|
||||
};
|
||||
} // ns
|
||||
|
||||
@@ -7,17 +7,18 @@
|
||||
*/
|
||||
|
||||
#include "ui_dblogincomponent.h"
|
||||
#include "blackcore/data/globalsetup.h"
|
||||
#include "blackgui/components/dblogincomponent.h"
|
||||
#include "blackgui/guiapplication.h"
|
||||
#include "blackgui/guiutility.h"
|
||||
#include "blackgui/overlaymessagesframe.h"
|
||||
#include "blackcore/data/globalsetup.h"
|
||||
#include "blackmisc/network/authenticateduser.h"
|
||||
#include "blackmisc/network/url.h"
|
||||
#include "blackmisc/htmlutils.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/statusmessage.h"
|
||||
#include "blackmisc/verify.h"
|
||||
#include "blackconfig/buildconfig.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
@@ -31,6 +32,7 @@
|
||||
using namespace BlackCore;
|
||||
using namespace BlackCore::Db;
|
||||
using namespace BlackGui;
|
||||
using namespace BlackConfig;
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Network;
|
||||
|
||||
@@ -64,10 +66,16 @@ namespace BlackGui
|
||||
ui->lbl_DatabaseName->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
||||
ui->lbl_DatabaseName->setOpenExternalLinks(true);
|
||||
|
||||
connect(ui->pb_Login, &QPushButton::clicked, this, &CDbLoginComponent::onLoginClicked);
|
||||
connect(ui->pb_Login, &QPushButton::clicked, this, &CDbLoginComponent::onLoginClicked);
|
||||
connect(ui->pb_Logoff, &QPushButton::clicked, this, &CDbLoginComponent::onLogoffClicked);
|
||||
connect(&m_loginService, &CDatabaseAuthenticationService::userAuthenticationFinished, this, &CDbLoginComponent::onAuthenticationFinished);
|
||||
connect(ui->le_Password, &QLineEdit::returnPressed, this, &CDbLoginComponent::onLoginClicked);
|
||||
connect(&m_loginService, &CDatabaseAuthenticationService::userAuthenticationFinished, this, &CDbLoginComponent::onAuthenticationFinished, Qt::QueuedConnection);
|
||||
|
||||
if (CBuildConfig::isLocalDeveloperDebugBuild())
|
||||
{
|
||||
const QString url = sApp->getGlobalSetup().getDbLoginServiceUrl().toQString();
|
||||
ui->pb_Login->setToolTip(url);
|
||||
}
|
||||
|
||||
// init GUI
|
||||
this->setUserInfo(this->getDbUser());
|
||||
|
||||
@@ -29,6 +29,7 @@ namespace BlackGui
|
||||
{
|
||||
/**
|
||||
* Login to DB
|
||||
* \sa BlackCore::Db::CDatabaseAuthenticationService
|
||||
*/
|
||||
class BLACKGUI_EXPORT CDbLoginComponent :
|
||||
public QFrame,
|
||||
@@ -41,7 +42,7 @@ namespace BlackGui
|
||||
explicit CDbLoginComponent(QWidget *parent = nullptr);
|
||||
|
||||
//! Destructor
|
||||
virtual ~CDbLoginComponent();
|
||||
virtual ~CDbLoginComponent() override;
|
||||
|
||||
//! DB user
|
||||
BlackMisc::Network::CAuthenticatedUser getDbUser() const;
|
||||
|
||||
@@ -31,13 +31,13 @@ namespace BlackMisc
|
||||
*/
|
||||
class BLACKMISC_EXPORT CRole :
|
||||
public CValueObject<CRole>,
|
||||
public BlackMisc::Db::IDatastoreObjectWithIntegerKey
|
||||
public Db::IDatastoreObjectWithIntegerKey
|
||||
{
|
||||
public:
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexName = BlackMisc::CPropertyIndex::GlobalIndexCRole,
|
||||
IndexName = CPropertyIndex::GlobalIndexCRole,
|
||||
IndexDescription
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user