History

add auth to assignment-client, fix refresh of static assignments

Stephen Birarda committed 12 years ago

Commit 27c77961 parent fcb36f08 files · +96 −34Browse files

Showing the changes to assignment-client/src/AssignmentClient.cpp (1 of 8 files). Show all

Unified · Split

assignment-client/src/AssignmentClient.cpp+31−0
@@ -6,9 +6,11 @@ · 5 unmodified lines
66 // Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
77 //
88
9+#include <QtCore/QProcess>
910 #include <QtCore/QThread>
1011 #include <QtCore/QTimer>
1112
13+#include <AccountManager.h>
1214 #include <Assignment.h>
1315 #include <Logging.h>
1416 #include <NodeList.h>
@@ -91,6 +93,10 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) : · 76 unmodified lines
9193
9294 // connect our readPendingDatagrams method to the readyRead() signal of the socket
9395 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);
94100 }
95101
96102 void AssignmentClient::sendAssignmentRequest() {
@@ -158,6 +164,30 @@ void AssignmentClient::readPendingDatagrams() { · 61 unmodified lines
158164 }
159165 }
160166
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+
161191 void AssignmentClient::assignmentCompleted() {
162192 // reset the logging target to the the CHILD_TARGET_NAME
163193 Logging::setTargetName(ASSIGNMENT_CLIENT_TARGET_NAME);
@@ -175,5 +205,6 @@ void AssignmentClient::assignmentCompleted() { · 11 unmodified lines
175205 // reset our NodeList by switching back to unassigned and clearing the list
176206 nodeList->setOwnerType(NodeType::Unassigned);
177207 nodeList->reset();
208+ nodeList->getDomainInfo().reset();
178209 nodeList->resetNodeInterestSet();
179210 }