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
6// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.6// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
7//7//
8 8
9#include <QtCore/QProcess>
9#include <QtCore/QThread>10#include <QtCore/QThread>
10#include <QtCore/QTimer>11#include <QtCore/QTimer>
11 12
13#include <AccountManager.h>
12#include <Assignment.h>14#include <Assignment.h>
13#include <Logging.h>15#include <Logging.h>
14#include <NodeList.h>16#include <NodeList.h>
@@ -91,6 +93,10 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) : · 76 unmodified lines
91 93
92 // connect our readPendingDatagrams method to the readyRead() signal of the socket94 // connect our readPendingDatagrams method to the readyRead() signal of the socket
93 connect(&nodeList->getNodeSocket(), &QUdpSocket::readyRead, this, &AssignmentClient::readPendingDatagrams);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
96void AssignmentClient::sendAssignmentRequest() {102void AssignmentClient::sendAssignmentRequest() {
@@ -158,6 +164,30 @@ void AssignmentClient::readPendingDatagrams() { · 61 unmodified lines
158 }164 }
159}165}
160 166
167void 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
161void AssignmentClient::assignmentCompleted() {191void AssignmentClient::assignmentCompleted() {
162 // reset the logging target to the the CHILD_TARGET_NAME192 // reset the logging target to the the CHILD_TARGET_NAME
163 Logging::setTargetName(ASSIGNMENT_CLIENT_TARGET_NAME);193 Logging::setTargetName(ASSIGNMENT_CLIENT_TARGET_NAME);
@@ -175,5 +205,6 @@ void AssignmentClient::assignmentCompleted() { · 11 unmodified lines
175 // reset our NodeList by switching back to unassigned and clearing the list205 // reset our NodeList by switching back to unassigned and clearing the list
176 nodeList->setOwnerType(NodeType::Unassigned);206 nodeList->setOwnerType(NodeType::Unassigned);
177 nodeList->reset();207 nodeList->reset();
208 nodeList->getDomainInfo().reset();
178 nodeList->resetNodeInterestSet();209 nodeList->resetNodeInterestSet();
179}210}