mirror of
https://github.com/lubosz/overte.git
synced 2025-04-10 04:28:59 +02:00
persist and recall domain-server web sessions from ini settings
This commit is contained in:
parent
2e5dc2320d
commit
005a3c7c12
4 changed files with 44 additions and 1 deletions
|
@ -50,6 +50,9 @@ DomainServer::DomainServer(int argc, char* argv[]) :
|
|||
setOrganizationDomain("highfidelity.io");
|
||||
setApplicationName("domain-server");
|
||||
QSettings::setDefaultFormat(QSettings::IniFormat);
|
||||
|
||||
qRegisterMetaType<DomainServerWebSessionData>("DomainServerWebSessionData");
|
||||
qRegisterMetaTypeStreamOperators<DomainServerWebSessionData>("DomainServerWebSessionData");
|
||||
|
||||
_argumentVariantMap = HifiConfigVariantMap::mergeCLParametersWithJSONConfig(arguments());
|
||||
|
||||
|
@ -59,6 +62,8 @@ DomainServer::DomainServer(int argc, char* argv[]) :
|
|||
|
||||
qDebug() << "Setting up LimitedNodeList and assignments.";
|
||||
setupNodeListAndAssignments();
|
||||
|
||||
loadExistingSessionsFromSettings();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1407,6 +1412,9 @@ void DomainServer::handleProfileRequestFinished() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
const QString DS_SETTINGS_SESSIONS_GROUP = "web-sessions";
|
||||
|
||||
Headers DomainServer::setupCookieHeadersFromProfileReply(QNetworkReply* profileReply) {
|
||||
Headers cookieHeaders;
|
||||
|
||||
|
@ -1417,7 +1425,14 @@ Headers DomainServer::setupCookieHeadersFromProfileReply(QNetworkReply* profileR
|
|||
QJsonObject userObject = profileDocument.object()["data"].toObject()["user"].toObject();
|
||||
|
||||
// add the profile to our in-memory data structure so we know who the user is when they send us their cookie
|
||||
_cookieSessionHash.insert(cookieUUID, DomainServerWebSessionData(userObject));
|
||||
DomainServerWebSessionData sessionData(userObject);
|
||||
_cookieSessionHash.insert(cookieUUID, sessionData);
|
||||
|
||||
// persist the cookie to settings file so we can get it back on DS relaunch
|
||||
QSettings localSettings;
|
||||
localSettings.beginGroup(DS_SETTINGS_SESSIONS_GROUP);
|
||||
QVariant sessionVariant = QVariant::fromValue(sessionData);
|
||||
localSettings.setValue(cookieUUID.toString(), QVariant::fromValue(sessionData));
|
||||
|
||||
// setup expiry for cookie to 1 month from today
|
||||
QDateTime cookieExpiry = QDateTime::currentDateTimeUtc().addMonths(1);
|
||||
|
@ -1435,6 +1450,17 @@ Headers DomainServer::setupCookieHeadersFromProfileReply(QNetworkReply* profileR
|
|||
return cookieHeaders;
|
||||
}
|
||||
|
||||
void DomainServer::loadExistingSessionsFromSettings() {
|
||||
// read data for existing web sessions into memory so existing sessions can be leveraged
|
||||
QSettings domainServerSettings;
|
||||
domainServerSettings.beginGroup(DS_SETTINGS_SESSIONS_GROUP);
|
||||
|
||||
foreach(const QString& uuidKey, domainServerSettings.childKeys()) {
|
||||
_cookieSessionHash.insert(QUuid(uuidKey), domainServerSettings.value(uuidKey).value<DomainServerWebSessionData>());
|
||||
qDebug() << "Pulled web session from settings - cookie UUID is" << uuidKey;
|
||||
}
|
||||
}
|
||||
|
||||
void DomainServer::refreshStaticAssignmentAndAddToQueue(SharedAssignmentPointer& assignment) {
|
||||
QUuid oldUUID = assignment->getUUID();
|
||||
assignment->resetUUID();
|
||||
|
|
|
@ -93,6 +93,8 @@ private:
|
|||
void handleProfileRequestFinished();
|
||||
Headers setupCookieHeadersFromProfileReply(QNetworkReply* profileReply);
|
||||
|
||||
void loadExistingSessionsFromSettings();
|
||||
|
||||
QJsonObject jsonForSocket(const HifiSockAddr& socket);
|
||||
QJsonObject jsonObjectForNode(const SharedNodePointer& node);
|
||||
|
||||
|
|
|
@ -51,3 +51,13 @@ void DomainServerWebSessionData::swap(DomainServerWebSessionData& otherSessionDa
|
|||
swap(_roles, otherSessionData._roles);
|
||||
}
|
||||
|
||||
QDataStream& operator<<(QDataStream &out, const DomainServerWebSessionData& session) {
|
||||
out << session._username << session._roles;
|
||||
return out;
|
||||
}
|
||||
|
||||
QDataStream& operator>>(QDataStream &in, DomainServerWebSessionData& session) {
|
||||
in >> session._username >> session._roles;
|
||||
return in;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,9 @@ public:
|
|||
const QString& getUsername() const { return _username; }
|
||||
const QSet<QString>& getRoles() const { return _roles; }
|
||||
|
||||
friend QDataStream& operator<<(QDataStream &out, const DomainServerWebSessionData& session);
|
||||
friend QDataStream& operator>>(QDataStream &in, DomainServerWebSessionData& session);
|
||||
|
||||
private:
|
||||
void swap(DomainServerWebSessionData& otherSessionData);
|
||||
|
||||
|
@ -33,4 +36,6 @@ private:
|
|||
QSet<QString> _roles;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(DomainServerWebSessionData)
|
||||
|
||||
#endif // hifi_DomainServerWebSessionData_h
|
Loading…
Reference in a new issue