Skip to content

Commit acf45cd

Browse files
Aji13187/7100 un tracetool auth (#746)
* Handled authentication in UN trace tool * Update uitools/common/src/UtilityNetworkTraceController.h Co-authored-by: James Ballard <[email protected]> * Update uitools/common/src/UtilityNetworkTraceController.cpp Co-authored-by: James Ballard <[email protected]> * Review comment fixed --------- Co-authored-by: James Ballard <[email protected]>
1 parent b4ed641 commit acf45cd

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

uitools/common/src/UtilityNetworkTraceController.cpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@
2020
#include "UtilityNetworkTraceController.h"
2121

2222
// ArcGISRuntime headers
23+
#include <ArcGISRuntimeEnvironment.h>
2324
#include <ArcGISFeature.h>
2425
#include <ArcGISFeatureListModel.h>
26+
#include <Authentication/AuthenticationManager.h>
27+
#include <Authentication/ArcGISAuthenticationChallenge.h>
28+
#include <Authentication/TokenCredential.h>
2529
#include <AttributeListModel.h>
2630
#include <Error.h>
2731
#include <FeatureLayer.h>
@@ -83,6 +87,8 @@
8387
// std headers
8488
#include <cmath>
8589

90+
using namespace Esri::ArcGISRuntime::Authentication;
91+
8692
namespace Esri::ArcGISRuntime::Toolkit {
8793

8894
namespace {
@@ -159,7 +165,7 @@ void connectToGeoView(GeoViewToolkit* geoView, UtilityNetworkTraceController* se
159165
\endlist
160166
*/
161167
UtilityNetworkTraceController::UtilityNetworkTraceController(QObject* parent) :
162-
QObject(parent),
168+
ArcGISAuthenticationChallengeHandler(parent),
163169
m_startingPointParent(new QObject(this)),
164170
m_startingPointsGraphicsOverlay(new GraphicsOverlay(m_startingPointParent)),
165171
m_startingPoints(new UtilityNetworkTraceStartingPointsModel(this)),
@@ -184,10 +190,13 @@ UtilityNetworkTraceController::UtilityNetworkTraceController(QObject* parent) :
184190
this),
185191
this))
186192
{
187-
//
193+
ArcGISRuntimeEnvironment::authenticationManager()->setArcGISAuthenticationChallengeHandler(this);
188194
}
189195

190-
UtilityNetworkTraceController::~UtilityNetworkTraceController() = default;
196+
UtilityNetworkTraceController::~UtilityNetworkTraceController()
197+
{
198+
ArcGISRuntimeEnvironment::authenticationManager()->setArcGISAuthenticationChallengeHandler(nullptr);
199+
}
191200

192201
/*!
193202
\brief Returns the \c GeoView as a \c QObject.
@@ -334,7 +343,10 @@ void UtilityNetworkTraceController::setSelectedUtilityNetwork(UtilityNetwork* se
334343
if (m_selectedUtilityNetwork == selectedUtilityNetwork)
335344
return;
336345

337-
disconnect(m_selectedUtilityNetwork, nullptr, this, nullptr);
346+
if (m_selectedUtilityNetwork != nullptr)
347+
{
348+
disconnect(m_selectedUtilityNetwork, nullptr, this, nullptr);
349+
}
338350

339351
m_selectedUtilityNetwork = selectedUtilityNetwork;
340352

@@ -906,4 +918,15 @@ void UtilityNetworkTraceController::applyStartingPointWarnings()
906918
}
907919
}
908920

921+
void UtilityNetworkTraceController::handleArcGISAuthenticationChallenge(ArcGISAuthenticationChallenge* challenge)
922+
{
923+
TokenCredential::createWithChallengeAsync(challenge, "viewer01", "I68VGU^nMurF", {}, this).then(this, [challenge](TokenCredential* tokenCredential)
924+
{
925+
challenge->continueWithCredential(tokenCredential);
926+
}).onFailed(this, [challenge](const ErrorException& e)
927+
{
928+
challenge->continueWithError(e.error());
929+
});
930+
}
931+
909932
} // Esri::ArcGISRuntime::Toolkit

uitools/common/src/UtilityNetworkTraceController.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <QObject>
2121

2222
// ArcGIS Maps SDK headers
23+
#include <Authentication/ArcGISAuthenticationChallengeHandler.h>
2324
#include <Point.h>
2425

2526
// Other headers
@@ -53,7 +54,7 @@ class UtilityNetworkFunctionTraceResultsModel;
5354
class UtilityNetworkTraceStartingPoint;
5455
class UtilityNetworkTraceStartingPointsModel;
5556

56-
class UtilityNetworkTraceController : public QObject
57+
class UtilityNetworkTraceController : public Authentication::ArcGISAuthenticationChallengeHandler
5758
{
5859
Q_OBJECT
5960
Q_PROPERTY(QObject* geoView READ geoView WRITE setGeoView NOTIFY geoViewChanged)
@@ -153,6 +154,7 @@ private slots:
153154
void addStartingPoint(ArcGISFeature* identifiedFeature, const Point& mapPoint);
154155
void setupUtilityNetworks();
155156
void applyStartingPointWarnings();
157+
void handleArcGISAuthenticationChallenge(Authentication::ArcGISAuthenticationChallenge* challenge) override;
156158

157159
QObject* m_geoView = nullptr;
158160
QObject* m_startingPointParent = nullptr;

0 commit comments

Comments
 (0)