Showing the changes to assignment-client/src/AssignmentClient.cpp (1 of 8 files). Show all
Unified · Split
| @@ -6,9 +6,11 @@ · 5 unmodified lines | ||
| 6 | 6 | // Copyright (c) 2013 HighFidelity, Inc. All rights reserved. |
| 7 | 7 | // |
| 8 | 8 | |
| 9 | +#include <QtCore/QProcess> | |
| 9 | 10 | #include <QtCore/QThread> |
| 10 | 11 | #include <QtCore/QTimer> |
| 11 | 12 | |
| 13 | +#include <AccountManager.h> | |
| 12 | 14 | #include <Assignment.h> |
| 13 | 15 | #include <Logging.h> |
| 14 | 16 | #include <NodeList.h> |
| @@ -91,6 +93,10 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) : · 76 unmodified lines | ||
| 91 | 93 | |
| 92 | 94 | // connect our readPendingDatagrams method to the readyRead() signal of the socket |
| 93 | 95 | connect(&nodeList->getNodeSocket(), &QUdpSocket::readyRead, this, &AssignmentClient::readPendingDatagrams); |
| 96 | + | |
| 97 | + // connections to AccountManager for authentication | |
| 98 | + connect(&AccountManager::getInstance(), &AccountManager::authRequired, | |
| 99 | + this, &AssignmentClient::handleAuthenticationRequest); | |
| 94 | 100 | } |
| 95 | 101 | |
| 96 | 102 | void AssignmentClient::sendAssignmentRequest() { |
| @@ -158,6 +164,30 @@ void AssignmentClient::readPendingDatagrams() { · 61 unmodified lines | ||
| 158 | 164 | } |
| 159 | 165 | } |
| 160 | 166 | |
| 167 | +void AssignmentClient::handleAuthenticationRequest() { | |
| 168 | + const QString DATA_SERVER_USERNAME_ENV = "HIFI_AC_USERNAME"; | |
| 169 | + const QString DATA_SERVER_PASSWORD_ENV = "HIFI_AC_PASSWORD"; | |
| 170 | + | |
| 171 | + // this node will be using an authentication server, let's make sure we have a username/password | |
| 172 | + QProcessEnvironment sysEnvironment = QProcessEnvironment::systemEnvironment(); | |
| 173 | + | |
| 174 | + QString username = sysEnvironment.value(DATA_SERVER_USERNAME_ENV); | |
| 175 | + QString password = sysEnvironment.value(DATA_SERVER_PASSWORD_ENV); | |
| 176 | + | |
| 177 | + AccountManager& accountManager = AccountManager::getInstance(); | |
| 178 | + | |
| 179 | + if (!username.isEmpty() && !password.isEmpty()) { | |
| 180 | + // ask the account manager to log us in from the env variables | |
| 181 | + accountManager.requestAccessToken(username, password); | |
| 182 | + } else { | |
| 183 | + qDebug() << "Authentication was requested against" << qPrintable(accountManager.getRootURL().toString()) | |
| 184 | + << "but both or one of" << qPrintable(DATA_SERVER_USERNAME_ENV) | |
| 185 | + << "/" << qPrintable(DATA_SERVER_PASSWORD_ENV) << "are not set. Unable to authenticate."; | |
| 186 | + | |
| 187 | + return; | |
| 188 | + } | |
| 189 | +} | |
| 190 | + | |
| 161 | 191 | void AssignmentClient::assignmentCompleted() { |
| 162 | 192 | // reset the logging target to the the CHILD_TARGET_NAME |
| 163 | 193 | Logging::setTargetName(ASSIGNMENT_CLIENT_TARGET_NAME); |
| @@ -175,5 +205,6 @@ void AssignmentClient::assignmentCompleted() { · 11 unmodified lines | ||
| 175 | 205 | // reset our NodeList by switching back to unassigned and clearing the list |
| 176 | 206 | nodeList->setOwnerType(NodeType::Unassigned); |
| 177 | 207 | nodeList->reset(); |
| 208 | + nodeList->getDomainInfo().reset(); | |
| 178 | 209 | nodeList->resetNodeInterestSet(); |
| 179 | 210 | } |