Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 3rdParty/QtCurl
4 changes: 0 additions & 4 deletions App/App.pro
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ HEADERS += \
Server/appTargomanAPI.h \
Server/clsRedisConnector.h \
Server/clsRequestHandler.h \
Server/clsSimpleCrypt.h \
Server/intfCacheConnector.hpp \
Server/QJWT.h \
Server/RESTAPIRegistry.h \
Server/RESTServer.h \
Server/WebSocketServer.h \
Expand All @@ -33,8 +31,6 @@ SOURCES += \
Server/clsAPIObject.cpp \
Server/clsRedisConnector.cpp \
Server/clsRequestHandler.cpp \
Server/clsSimpleCrypt.cpp \
Server/QJWT.cpp \
Server/WebSocketServer.cpp \
Server/RESTAPIRegistry.cpp \
Server/RESTServer.cpp \
Expand Down
2 changes: 1 addition & 1 deletion App/Server/RESTServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "clsRedisConnector.h"
#include "WebSocketServer.h"
#include "RESTAPIRegistry.h"
#include "QJWT.h"
#include "Interfaces/Server/QJWT.h"
#include "APICache.hpp"

namespace Targoman::API {
Expand Down
1 change: 1 addition & 0 deletions App/Server/appTargomanAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ void appTargomanAPI::slotExecute()
foreach (auto Plugin, LoadedModules)
{
intfPureModule* Module = qobject_cast<intfPureModule*>(Plugin.Instance);
Module->setInstancePointer();

if (!Module)
throw exInvalidAPIModule(QString("Seems that this an incorrect module: %1").arg(Plugin.File));
Expand Down
39 changes: 20 additions & 19 deletions App/Server/clsRequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "libTargomanCommon/CmdIO.h"
#include "Interfaces/API/intfPureModule.h"
#include "ServerConfigs.h"
#include "QJWT.h"
#include "Interfaces/Server/QJWT.h"
#include "APICache.hpp"
#include "OpenAPIGenerator.h"

Expand Down Expand Up @@ -332,20 +332,21 @@ clsRequestHandler::stuResult clsRequestHandler::run(clsAPIObject* _apiObject, QS

try
{
JWT = QJWT::verifyJWT(
BearerToken,
RemoteIP
);
QJWT::verifyJWT(
BearerToken,
RemoteIP,
JWT
);
}
catch (exJWTExpired &exp)
{
QString NewToken = Authentication::renewJWT(
BearerToken,
JWT,
RemoteIP
);

BearerToken = NewToken;
ResponseHeaders.insert("X-AUTH-NEW-TOKEN", BearerToken);
ResponseHeaders.insert("x-auth-new-token", BearerToken);
}
JWT["encodedJWT"] = BearerToken;
}
Expand Down Expand Up @@ -597,8 +598,8 @@ void clsRequestHandler::sendFile(const QString& _basePath, const QString _path)
this->Response->setStatusCode(qhttp::ESTATUS_OK);

#ifdef QT_DEBUG
this->Response->addHeaderValue("Access-Control-Expose-Headers", QStringLiteral("X-DEBUG-TIME-ELAPSED"));
this->Response->addHeaderValue("X-DEBUG-TIME-ELAPSED", QString::number(this->ElapsedTimer.elapsed()) + " ms");
this->Response->addHeaderValue("Access-Control-Expose-Headers", QStringLiteral("x-debug-time-elapsed"));
this->Response->addHeaderValue("x-debug-time-elapsed", QString::number(this->ElapsedTimer.elapsed()) + " ms");
#endif

QTimer::singleShot(10, this, &clsRequestHandler::slotSendFileData);
Expand Down Expand Up @@ -672,13 +673,13 @@ void clsRequestHandler::sendResponse(qhttp::TStatusCode _code,
};

#ifdef QT_DEBUG
funcAddToHeaderArray("X-DEBUG-TIME-ELAPSED");
funcAddToHeaderArray("x-debug-time-elapsed");

if (_responseHeaders.contains("X-DEBUG-TIME-ELAPSED") == false)
_responseHeaders["X-DEBUG-TIME-ELAPSED"] = QString::number(this->ElapsedTimer.elapsed()) + " ms";
if (_responseHeaders.contains("x-debug-time-elapsed") == false)
_responseHeaders["x-debug-time-elapsed"] = QString::number(this->ElapsedTimer.elapsed()) + " ms";
#endif

funcAddToHeaderArray("X-AUTH-NEW-TOKEN");
funcAddToHeaderArray("x-auth-new-token");

this->addHeaderValues(_responseHeaders);

Expand Down Expand Up @@ -715,8 +716,8 @@ void clsRequestHandler::sendCORSOptions()
this->Response->setStatusCode(qhttp::ESTATUS_NO_CONTENT);

#ifdef QT_DEBUG
this->Response->addHeaderValue("Access-Control-Expose-Headers", QStringLiteral("X-DEBUG-TIME-ELAPSED"));
this->Response->addHeaderValue("X-DEBUG-TIME-ELAPSED", QString::number(this->ElapsedTimer.elapsed()) + " ms");
this->Response->addHeaderValue("Access-Control-Expose-Headers", QStringLiteral("x-debug-time-elapsed"));
this->Response->addHeaderValue("x-debug-time-elapsed", QString::number(this->ElapsedTimer.elapsed()) + " ms");
#endif

this->Response->end();
Expand Down Expand Up @@ -779,13 +780,13 @@ void clsRequestHandler::sendResponseBase(qhttp::TStatusCode _code,
};

#ifdef QT_DEBUG
funcAddToHeaderArray("X-DEBUG-TIME-ELAPSED");
funcAddToHeaderArray("x-debug-time-elapsed");

if (_responseHeaders.contains("X-DEBUG-TIME-ELAPSED") == false)
_responseHeaders["X-DEBUG-TIME-ELAPSED"] = QString::number(this->ElapsedTimer.elapsed()) + " ms";
if (_responseHeaders.contains("x-debug-time-elapsed") == false)
_responseHeaders["x-debug-time-elapsed"] = QString::number(this->ElapsedTimer.elapsed()) + " ms";
#endif

funcAddToHeaderArray("X-AUTH-NEW-TOKEN");
funcAddToHeaderArray("x-auth-new-token");

this->addHeaderValues(_responseHeaders);

Expand Down
37 changes: 19 additions & 18 deletions Interfaces/AAA/Authentication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "Authentication.h"
#include "PrivHelpers.h"
#include "Interfaces/AAA/clsJWT.hpp"
#include "App/Server/QJWT.h"
#include "Interfaces/Server/QJWT.h"

namespace Targoman::API::AAA::Authentication {

Expand Down Expand Up @@ -74,47 +74,48 @@ stuActiveAccount updatePrivs(const QString& _ip, const QString& _ssid, const QSt
*/

QString renewJWT(
const QString &_jwt,
INOUT TAPI::JWT_t &_JWTPayload,
// const QString &_jwt,
const QString &_ip
)
{
QStringList JWTParts = _jwt.split('.');
// QStringList JWTParts = _jwt.split('.');

if (JWTParts.length() != 3)
throw exHTTPForbidden("Invalid JWT Token");
// if (JWTParts.length() != 3)
// throw exHTTPForbidden("Invalid JWT Token");

QJsonParseError Error;
QJsonDocument Payload = QJsonDocument::fromJson(QByteArray::fromBase64(JWTParts.at(1).toLatin1()), &Error);
// QJsonParseError Error;
// QJsonDocument Payload = QJsonDocument::fromJson(QByteArray::fromBase64(JWTParts.at(1).toLatin1()), &Error);

if (Payload.isNull())
throw exHTTPForbidden("Invalid JWT payload: " + Error.errorString());
// if (Payload.isNull())
// throw exHTTPForbidden("Invalid JWT payload: " + Error.errorString());

TAPI::JWT_t JWTPayload = Payload.object();
// TAPI::JWT_t JWTPayload = Payload.object();

clsJWT JWT(JWTPayload);
clsJWT JWT(_JWTPayload);
QStringList Services = JWT.privatePart().value("svc").toString().split(',', QString::SkipEmptyParts);

makeAAADAC(DAC);

quint32 Duration = JWTPayload["exp"].toInt() - JWTPayload["iat"].toInt();
quint32 Duration = _JWTPayload["exp"].toInt() - _JWTPayload["iat"].toInt();
QJsonObject UserInfo = DAC.callSP({},
"spSessionRetrieveInfo", {
{ "iSSID", JWT.session() },
{ "iIP", _ip },
{ "iIssuance", JWTPayload["iat"].toInt() },
{ "iIssuance", _JWTPayload["iat"].toInt() },
}).toJson(true).object();


stuActiveAccount ActiveAccount = PrivHelpers::processUserObject(UserInfo, {}, Services);

JWTPayload["iat"] = ActiveAccount.Privs["Issuance"];
JWTPayload["privs"] = ActiveAccount.Privs["privs"];
_JWTPayload["iat"] = ActiveAccount.Privs["Issuance"];
_JWTPayload["privs"] = ActiveAccount.Privs["privs"];

return Server::QJWT::createSigned(
JWTPayload,
JWTPayload.contains("prv") ? JWTPayload["prv"].toObject() : QJsonObject(),
_JWTPayload,
_JWTPayload.contains("prv") ? _JWTPayload["prv"].toObject() : QJsonObject(),
Duration,
JWTPayload["jti"].toString(),
_JWTPayload["jti"].toString(),
_ip
);
}
Expand Down
3 changes: 2 additions & 1 deletion Interfaces/AAA/Authentication.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ extern Targoman::API::AAA::stuActiveAccount login(

//extern Targoman::API::AAA::stuActiveAccount updatePrivs(const QString &_ip, const QString &_ssid, const QString &_requiredServices);
extern QString renewJWT(
const QString &_jwt,
INOUT TAPI::JWT_t &_JWTPayload,
// const QString &_jwt,
const QString &_ip
);

Expand Down
2 changes: 1 addition & 1 deletion Interfaces/AAA/PrivHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/

#include "PrivHelpers.h"
#include "App/Server/QJWT.h"
#include "Interfaces/Server/QJWT.h"
#include "libTargomanCommon/Helpers.hpp"
#include "Interfaces/Common/QtTypes.hpp"
#include "QtCUrl.h"
Expand Down
18 changes: 13 additions & 5 deletions Interfaces/API/intfPureModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
#include "Interfaces/DBM/clsORMField.h"
#include "Interfaces/DBM/clsTable.h"

#define RESPONSE_HEADER_X_PAGINATION_TOTAL_COUNT "X-PAGINATION-TOTAL-COUNT"
#define RESPONSE_HEADER_X_PAGINATION_PAGE_COUNT "X-PAGINATION-PAGE-COUNT"
#define RESPONSE_HEADER_X_PAGINATION_CURRENT_PAGE "X-PAGINATION-CURRENT-PAGE"
#define RESPONSE_HEADER_X_PAGINATION_PER_PAGE "X-PAGINATION-PER-PAGE"
#define RESPONSE_HEADER_X_PAGINATION_TOTAL_COUNT "x-pagination-total-count"
#define RESPONSE_HEADER_X_PAGINATION_PAGE_COUNT "x-pagination-page-count"
#define RESPONSE_HEADER_X_PAGINATION_CURRENT_PAGE "x-pagination-current-page"
#define RESPONSE_HEADER_X_PAGINATION_PER_PAGE "x-pagination-per-page"

/**********************************************************************\
|** GET ***************************************************************|
Expand Down Expand Up @@ -317,6 +317,7 @@ class intfPureModule : public Targoman::Common::Configuration::intfModule
virtual stuDBInfo requiredDB() const { return {}; }

virtual bool init() { return true; }
virtual void setInstancePointer() { };

virtual QList<DBM::clsORMField> filterItems(qhttp::THttpMethod _method = qhttp::EHTTP_ACL)
{
Expand Down Expand Up @@ -374,7 +375,14 @@ public: \
private: \
TAPI_DISABLE_COPY(_name); \
public: \
_name();
_name(); \
virtual void setInstancePointer() { _name::InstancePointer = this; } \
protected: \
static _name* InstancePointer; \
static _name* instance() { return _name::InstancePointer; }

#define TARGOMAN_IMPL_API_MODULE(_name) \
_name* _name::InstancePointer;

#define TARGOMAN_DEFINE_API_SUBMODULE_WO_CTOR(_module, _name) \
public: \
Expand Down
25 changes: 17 additions & 8 deletions Interfaces/Helpers/RESTClientHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <QDebug>
#include "Interfaces/AAA/PrivHelpers.h"
//#include "Interfaces/AAA/clsJWT.hpp"
//#include "App/Server/QJWT.h"
//#include "Interfaces/Server/QJWT.h"

using namespace Targoman::Common::Configuration;
using namespace Targoman::API::AAA;
Expand Down Expand Up @@ -61,7 +61,8 @@ QVariant RESTClientHelper::callAPI(
const QVariantMap &_urlArgs,
const QVariantMap &_postOrFormFields,
const QVariantMap &_formFiles,
QString _aPIURL
QString _aPIURL,
QVariantMap *_outResponseHeaders
)
{
// QString EncodedJWT = Targoman::API::Server::QJWT::createSigned(_JWT,
Expand All @@ -77,7 +78,8 @@ QVariant RESTClientHelper::callAPI(
_urlArgs,
_postOrFormFields,
_formFiles,
_aPIURL
_aPIURL,
_outResponseHeaders
);
}

Expand All @@ -88,7 +90,8 @@ QVariant RESTClientHelper::callAPI(
const QVariantMap &_urlArgs,
const QVariantMap &_postOrFormFields,
const QVariantMap &_formFiles,
QString _aPIURL
QString _aPIURL,
QVariantMap *_outResponseHeaders
)
{
if (_aPIURL.isEmpty())
Expand Down Expand Up @@ -176,13 +179,19 @@ QVariant RESTClientHelper::callAPI(

QString CUrlResult = CUrl.exec(Opt);

if (_outResponseHeaders != nullptr)
*_outResponseHeaders = CUrl.headerBuffer();

if (CUrl.lastError().isOk() == false)
{
auto LastError = CUrl.lastError();
qDebug() << "CURL ERROR:" << LastError.code() << LastError.text()
<< ", ERROR_BUFFER:" << CUrl.errorBuffer()
<< ", BUFFER:" << CUrl.buffer()
<< ", RESULT:" << CUrlResult;
qDebug().noquote().nospace()
<< "-- CURL ERROR: (" << LastError.code() << ") " << LastError.text() << endl
<< " RESPONSE HEADERS: " << (_outResponseHeaders != nullptr ? *_outResponseHeaders : CUrl.headerBuffer()) << endl
<< " BUFFER: " << CUrl.buffer() << endl
<< " RESULT: " << CUrlResult << endl
<< " ERROR_BUFFER: " << CUrl.errorBuffer() << endl
;
return QVariant();
}

Expand Down
6 changes: 4 additions & 2 deletions Interfaces/Helpers/RESTClientHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class RESTClientHelper
const QVariantMap &_urlArgs = {},
const QVariantMap &_postOrFormFields = {},
const QVariantMap &_formFiles = {},
QString _aPIURL = {}
QString _aPIURL = {},
QVariantMap *_outResponseHeaders = nullptr
);

static QVariant callAPI(
Expand All @@ -66,7 +67,8 @@ class RESTClientHelper
const QVariantMap &_urlArgs = {},
const QVariantMap &_postOrFormFields = {},
const QVariantMap &_formFiles = {},
QString _aPIURL = {}
QString _aPIURL = {},
QVariantMap *_outResponseHeaders = nullptr
);

};
Expand Down
2 changes: 1 addition & 1 deletion Interfaces/Helpers/SecurityHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <QCryptographicHash>
#include <QRandomGenerator>
#include "SecurityHelper.h"
#include "App/Server/clsSimpleCrypt.h"
#include "Interfaces/Server/clsSimpleCrypt.h"

namespace Targoman::API::Helpers {

Expand Down
6 changes: 6 additions & 0 deletions Interfaces/Interfaces.pro
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
LibName=TargomanAPIInterface

DIST_HEADERS += \
Server/clsSimpleCrypt.h \
Server/QJWT.h \
Common/GenericTypes.h \
Common/tmplAPIArg.h \
Common/intfAPIArgManipulator.h \
Expand Down Expand Up @@ -39,6 +41,8 @@ DIST_HEADERS += \
PRIVATE_HEADERS += \

HEADERS += \
Server/clsSimpleCrypt.h \
Server/QJWT.h \
Common/ServerCommon.h \
Common/base.h \
Common/tmplNullable.hpp \
Expand Down Expand Up @@ -70,6 +74,8 @@ HEADERS += \
ObjectStorage/ObjectStorageManager.h

SOURCES += \
Server/clsSimpleCrypt.cpp \
Server/QJWT.cpp \
Common/ServerCommon.cpp \
Common/base.cpp \
Common/GenericTypes.cpp \
Expand Down
4 changes: 2 additions & 2 deletions Interfaces/ObjectStorage/ORM/ObjectStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ public: \
this->addSubModule(this->_UploadQueue.data()); \
this->addSubModule(this->_UploadGateways.data());

// UploadFiles ::instance().prepareFiltersList(); \
// UploadQueue ::instance().prepareFiltersList(); \
// UploadFiles ::instance().prepareFiltersList();
// UploadQueue ::instance().prepareFiltersList();
// UploadGateways ::instance().prepareFiltersList();

/****************************************************/
Expand Down
Loading