Skip to content

Commit ac0a188

Browse files
committedOct 19, 2018
[needs-docs] Allow users to set tokens for connections to ArcGIS Feature/Map servers
Without this it can be impossible to connect to authenticated/private servers. Tokens are set by creating an "ESRI token based authentication" method from the standard QGIS Authentication settings and associating with the connection.
1 parent ffdf39e commit ac0a188

20 files changed

+567
-52
lines changed
 

‎src/auth/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ SET (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/${QGIS_PLUGIN_SUBDI
1313
# (.*)authmethod\.(so|dll)
1414

1515
ADD_SUBDIRECTORY(basic)
16+
ADD_SUBDIRECTORY(esritoken)
1617
ADD_SUBDIRECTORY(identcert)
1718
ADD_SUBDIRECTORY(pkipaths)
1819
ADD_SUBDIRECTORY(pkipkcs12)

‎src/auth/esritoken/CMakeLists.txt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
SET(AUTH_ESRI_TOKEN_SRCS
2+
qgsauthesritokenmethod.cpp
3+
qgsauthesritokenedit.cpp
4+
)
5+
6+
SET(AUTH_ESRI_TOKEN_HDRS
7+
qgsauthesritokenmethod.h
8+
qgsauthesritokenedit.h
9+
)
10+
11+
SET(AUTH_ESRI_TOKEN_MOC_HDRS
12+
qgsauthesritokenmethod.h
13+
qgsauthesritokenedit.h
14+
)
15+
16+
SET(AUTH_ESRI_TOKEN_UIS qgsauthesritokenedit.ui)
17+
18+
INCLUDE_DIRECTORIES (
19+
../../core
20+
../../core/auth
21+
../../core/geometry
22+
../../core/metadata
23+
${CMAKE_BINARY_DIR}/src/core
24+
${CMAKE_BINARY_DIR}/src/gui
25+
)
26+
INCLUDE_DIRECTORIES (SYSTEM
27+
${QCA_INCLUDE_DIR}
28+
${QTKEYCHAIN_INCLUDE_DIR}
29+
)
30+
INCLUDE_DIRECTORIES (
31+
../../gui
32+
../../gui/auth
33+
${CMAKE_CURRENT_BINARY_DIR}
34+
)
35+
36+
QT5_WRAP_UI (AUTH_ESRI_TOKEN_UIS_H ${AUTH_ESRI_TOKEN_UIS})
37+
38+
QT5_WRAP_CPP(AUTH_ESRI_TOKEN_MOC_SRCS ${AUTH_ESRI_TOKEN_MOC_HDRS})
39+
40+
ADD_LIBRARY (esritokenauthmethod MODULE ${AUTH_ESRI_TOKEN_SRCS} ${AUTH_ESRI_TOKEN_HDRS} ${AUTH_ESRI_TOKEN_MOC_SRCS} ${AUTH_ESRI_TOKEN_UIS_H})
41+
42+
TARGET_LINK_LIBRARIES (esritokenauthmethod
43+
qgis_core
44+
qgis_gui
45+
)
46+
47+
INSTALL(TARGETS esritokenauthmethod
48+
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
49+
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/***************************************************************************
2+
qgsauthesritokenedit.cpp
3+
------------------------
4+
begin : October 2018
5+
copyright : (C) 2018 by Nyall Dawson
6+
author : Nyall Dawson
7+
email : nyall dot dawson at gmail dot com
8+
***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
17+
#include "qgsauthesritokenedit.h"
18+
#include "ui_qgsauthesritokenedit.h"
19+
20+
21+
QgsAuthEsriTokenEdit::QgsAuthEsriTokenEdit( QWidget *parent )
22+
: QgsAuthMethodEdit( parent )
23+
{
24+
setupUi( this );
25+
connect( mTokenEdit, &QPlainTextEdit::textChanged, this, &QgsAuthEsriTokenEdit::tokenChanged );
26+
}
27+
28+
bool QgsAuthEsriTokenEdit::validateConfig()
29+
{
30+
bool curvalid = !mTokenEdit->toPlainText().isEmpty();
31+
if ( mValid != curvalid )
32+
{
33+
mValid = curvalid;
34+
emit validityChanged( curvalid );
35+
}
36+
return curvalid;
37+
}
38+
39+
QgsStringMap QgsAuthEsriTokenEdit::configMap() const
40+
{
41+
QgsStringMap config;
42+
config.insert( QStringLiteral( "token" ), mTokenEdit->toPlainText() );
43+
44+
return config;
45+
}
46+
47+
void QgsAuthEsriTokenEdit::loadConfig( const QgsStringMap &configmap )
48+
{
49+
clearConfig();
50+
51+
mConfigMap = configmap;
52+
mTokenEdit->setPlainText( configmap.value( QStringLiteral( "token" ) ) );
53+
54+
validateConfig();
55+
}
56+
57+
void QgsAuthEsriTokenEdit::resetConfig()
58+
{
59+
loadConfig( mConfigMap );
60+
}
61+
62+
void QgsAuthEsriTokenEdit::clearConfig()
63+
{
64+
mTokenEdit->clear();
65+
}
66+
67+
void QgsAuthEsriTokenEdit::tokenChanged()
68+
{
69+
validateConfig();
70+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/***************************************************************************
2+
qgsauthesritokenedit.h
3+
---------------------
4+
begin : October 2018
5+
copyright : (C) 2018 by Nyall Dawson
6+
author : Nyall Dawson
7+
email : nyall dot dawson at gmail dot com
8+
***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
17+
#ifndef QGSAUTHESRITOKENEDIT_H
18+
#define QGSAUTHESRITOKENEDIT_H
19+
20+
#include <QWidget>
21+
#include "qgsauthmethodedit.h"
22+
#include "ui_qgsauthesritokenedit.h"
23+
24+
#include "qgsauthconfig.h"
25+
26+
27+
class QgsAuthEsriTokenEdit : public QgsAuthMethodEdit, private Ui::QgsAuthEsriTokenEdit
28+
{
29+
Q_OBJECT
30+
31+
public:
32+
explicit QgsAuthEsriTokenEdit( QWidget *parent = nullptr );
33+
34+
bool validateConfig() override;
35+
36+
QgsStringMap configMap() const override;
37+
38+
public slots:
39+
void loadConfig( const QgsStringMap &configmap ) override;
40+
41+
void resetConfig() override;
42+
43+
void clearConfig() override;
44+
45+
private slots:
46+
void tokenChanged();
47+
48+
private:
49+
QgsStringMap mConfigMap;
50+
bool mValid = false;
51+
};
52+
53+
#endif // QGSAUTHESRITOKENEDIT_H
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>QgsAuthEsriTokenEdit</class>
4+
<widget class="QWidget" name="QgsAuthEsriTokenEdit">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>400</width>
10+
<height>300</height>
11+
</rect>
12+
</property>
13+
<layout class="QGridLayout" name="gridLayout">
14+
<property name="leftMargin">
15+
<number>6</number>
16+
</property>
17+
<property name="topMargin">
18+
<number>6</number>
19+
</property>
20+
<property name="rightMargin">
21+
<number>6</number>
22+
</property>
23+
<property name="bottomMargin">
24+
<number>6</number>
25+
</property>
26+
<item row="1" column="0">
27+
<widget class="QLabel" name="lblToken">
28+
<property name="text">
29+
<string>Token</string>
30+
</property>
31+
</widget>
32+
</item>
33+
<item row="2" column="0">
34+
<spacer name="verticalSpacer_2">
35+
<property name="orientation">
36+
<enum>Qt::Vertical</enum>
37+
</property>
38+
<property name="sizeHint" stdset="0">
39+
<size>
40+
<width>20</width>
41+
<height>173</height>
42+
</size>
43+
</property>
44+
</spacer>
45+
</item>
46+
<item row="1" column="1" rowspan="2">
47+
<widget class="QPlainTextEdit" name="mTokenEdit">
48+
<property name="placeholderText">
49+
<string>Required</string>
50+
</property>
51+
</widget>
52+
</item>
53+
</layout>
54+
</widget>
55+
<resources/>
56+
<connections/>
57+
</ui>
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
/***************************************************************************
2+
qgsauthesritokenmethod.cpp
3+
--------------------------
4+
begin : October 2018
5+
copyright : (C) 2018 by Nyall Dawson
6+
author : Nyall Dawson
7+
email : nyall dot dawson at gmail dot com
8+
***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
17+
#include "qgsauthesritokenmethod.h"
18+
#include "qgsauthesritokenedit.h"
19+
20+
#include "qgsauthmanager.h"
21+
#include "qgslogger.h"
22+
#include "qgsapplication.h"
23+
24+
#include <QNetworkProxy>
25+
#include <QMutexLocker>
26+
#include <QUuid>
27+
28+
static const QString AUTH_METHOD_KEY = QStringLiteral( "EsriToken" );
29+
static const QString AUTH_METHOD_DESCRIPTION = QStringLiteral( "ESRI token" );
30+
31+
QMap<QString, QgsAuthMethodConfig> QgsAuthEsriTokenMethod::sAuthConfigCache = QMap<QString, QgsAuthMethodConfig>();
32+
33+
34+
QgsAuthEsriTokenMethod::QgsAuthEsriTokenMethod()
35+
{
36+
setVersion( 2 );
37+
setExpansions( QgsAuthMethod::NetworkRequest );
38+
setDataProviders( QStringList()
39+
<< QStringLiteral( "arcgismapserver" )
40+
<< QStringLiteral( "arcgisfeatureserver" ) );
41+
42+
}
43+
44+
QString QgsAuthEsriTokenMethod::key() const
45+
{
46+
return AUTH_METHOD_KEY;
47+
}
48+
49+
QString QgsAuthEsriTokenMethod::description() const
50+
{
51+
return AUTH_METHOD_DESCRIPTION;
52+
}
53+
54+
QString QgsAuthEsriTokenMethod::displayDescription() const
55+
{
56+
return tr( "ESRI token based authentication" );
57+
}
58+
59+
bool QgsAuthEsriTokenMethod::updateNetworkRequest( QNetworkRequest &request, const QString &authcfg,
60+
const QString &dataprovider )
61+
{
62+
Q_UNUSED( dataprovider )
63+
QMutexLocker locker( &mMutex );
64+
QgsAuthMethodConfig mconfig = getMethodConfig( authcfg );
65+
if ( !mconfig.isValid() )
66+
{
67+
QgsDebugMsg( QStringLiteral( "Update request config FAILED for authcfg: %1: config invalid" ).arg( authcfg ) );
68+
return false;
69+
}
70+
71+
const QString token = mconfig.config( QStringLiteral( "token" ) );
72+
73+
if ( !token.isEmpty() )
74+
{
75+
request.setRawHeader( "X-Esri-Authorization", QStringLiteral( "Bearer %1 " ).arg( token ).toLocal8Bit() );
76+
}
77+
return true;
78+
}
79+
80+
void QgsAuthEsriTokenMethod::clearCachedConfig( const QString &authcfg )
81+
{
82+
removeMethodConfig( authcfg );
83+
}
84+
85+
void QgsAuthEsriTokenMethod::updateMethodConfig( QgsAuthMethodConfig &mconfig )
86+
{
87+
if ( mconfig.hasConfig( QStringLiteral( "oldconfigstyle" ) ) )
88+
{
89+
QgsDebugMsg( QStringLiteral( "Updating old style auth method config" ) );
90+
}
91+
92+
// NOTE: add updates as method version() increases due to config storage changes
93+
}
94+
95+
QgsAuthMethodConfig QgsAuthEsriTokenMethod::getMethodConfig( const QString &authcfg, bool fullconfig )
96+
{
97+
QMutexLocker locker( &mMutex );
98+
QgsAuthMethodConfig mconfig;
99+
100+
// check if it is cached
101+
if ( sAuthConfigCache.contains( authcfg ) )
102+
{
103+
mconfig = sAuthConfigCache.value( authcfg );
104+
QgsDebugMsg( QStringLiteral( "Retrieved config for authcfg: %1" ).arg( authcfg ) );
105+
return mconfig;
106+
}
107+
108+
// else build basic bundle
109+
if ( !QgsApplication::authManager()->loadAuthenticationConfig( authcfg, mconfig, fullconfig ) )
110+
{
111+
QgsDebugMsg( QStringLiteral( "Retrieve config FAILED for authcfg: %1" ).arg( authcfg ) );
112+
return QgsAuthMethodConfig();
113+
}
114+
115+
// cache bundle
116+
putMethodConfig( authcfg, mconfig );
117+
118+
return mconfig;
119+
}
120+
121+
void QgsAuthEsriTokenMethod::putMethodConfig( const QString &authcfg, const QgsAuthMethodConfig &mconfig )
122+
{
123+
QMutexLocker locker( &mMutex );
124+
QgsDebugMsg( QStringLiteral( "Putting token config for authcfg: %1" ).arg( authcfg ) );
125+
sAuthConfigCache.insert( authcfg, mconfig );
126+
}
127+
128+
void QgsAuthEsriTokenMethod::removeMethodConfig( const QString &authcfg )
129+
{
130+
QMutexLocker locker( &mMutex );
131+
if ( sAuthConfigCache.contains( authcfg ) )
132+
{
133+
sAuthConfigCache.remove( authcfg );
134+
QgsDebugMsg( QStringLiteral( "Removed token config for authcfg: %1" ).arg( authcfg ) );
135+
}
136+
}
137+
138+
//////////////////////////////////////////////
139+
// Plugin externals
140+
//////////////////////////////////////////////
141+
142+
/**
143+
* Required class factory to return a pointer to a newly created object
144+
*/
145+
QGISEXTERN QgsAuthEsriTokenMethod *classFactory()
146+
{
147+
return new QgsAuthEsriTokenMethod();
148+
}
149+
150+
/**
151+
* Required key function (used to map the plugin to a data store type)
152+
*/
153+
QGISEXTERN QString authMethodKey()
154+
{
155+
return AUTH_METHOD_KEY;
156+
}
157+
158+
/**
159+
* Required description function
160+
*/
161+
QGISEXTERN QString description()
162+
{
163+
return AUTH_METHOD_DESCRIPTION;
164+
}
165+
166+
/**
167+
* Required isAuthMethod function. Used to determine if this shared library
168+
* is an authentication method plugin
169+
*/
170+
QGISEXTERN bool isAuthMethod()
171+
{
172+
return true;
173+
}
174+
175+
/**
176+
* Optional class factory to return a pointer to a newly created edit widget
177+
*/
178+
QGISEXTERN QgsAuthEsriTokenEdit *editWidget( QWidget *parent )
179+
{
180+
return new QgsAuthEsriTokenEdit( parent );
181+
}
182+
183+
/**
184+
* Required cleanup function
185+
*/
186+
QGISEXTERN void cleanupAuthMethod() // pass QgsAuthMethod *method, then delete method ?
187+
{
188+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/***************************************************************************
2+
qgsauthesritokenmethod.h
3+
---------------------
4+
begin : October 2018
5+
copyright : (C) 2018 by Nyall Dawson
6+
author : Nyall Dawson
7+
email : nyall dot dawson at gmail dot com
8+
***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
17+
#ifndef QGSAUTHESRITOKENMETHOD_H
18+
#define QGSAUTHESRITOKENMETHOD_H
19+
20+
#include <QObject>
21+
#include <QMutex>
22+
23+
#include "qgsauthconfig.h"
24+
#include "qgsauthmethod.h"
25+
26+
27+
class QgsAuthEsriTokenMethod : public QgsAuthMethod
28+
{
29+
Q_OBJECT
30+
31+
public:
32+
explicit QgsAuthEsriTokenMethod();
33+
34+
// QgsAuthMethod interface
35+
QString key() const override;
36+
37+
QString description() const override;
38+
39+
QString displayDescription() const override;
40+
41+
bool updateNetworkRequest( QNetworkRequest &request, const QString &authcfg,
42+
const QString &dataprovider = QString() ) override;
43+
44+
void clearCachedConfig( const QString &authcfg ) override;
45+
void updateMethodConfig( QgsAuthMethodConfig &mconfig ) override;
46+
47+
private:
48+
QgsAuthMethodConfig getMethodConfig( const QString &authcfg, bool fullconfig = true );
49+
50+
void putMethodConfig( const QString &authcfg, const QgsAuthMethodConfig &mconfig );
51+
52+
void removeMethodConfig( const QString &authcfg );
53+
54+
static QMap<QString, QgsAuthMethodConfig> sAuthConfigCache;
55+
56+
};
57+
58+
#endif // QGSAUTHESRITOKENMETHOD_H

‎src/providers/arcgisrest/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ INCLUDE_DIRECTORIES(
1414
)
1515

1616
INCLUDE_DIRECTORIES(SYSTEM
17+
${QCA_INCLUDE_DIR}
18+
${QTKEYCHAIN_INCLUDE_DIR}
1719
)
1820

1921
IF (WITH_GUI)
@@ -57,10 +59,12 @@ ADD_LIBRARY(arcgisfeatureserverprovider MODULE ${AFS_SRCS} ${AFS_MOC_SRCS})
5759

5860
TARGET_LINK_LIBRARIES(arcgisfeatureserverprovider
5961
qgis_core
62+
${QCA_LIBRARY}
6063
)
6164

6265
TARGET_LINK_LIBRARIES (arcgisfeatureserverprovider_a
6366
qgis_core
67+
${QCA_LIBRARY}
6468
)
6569

6670
IF (WITH_GUI)
@@ -107,6 +111,7 @@ ADD_LIBRARY(arcgismapserverprovider MODULE ${AMS_SRCS} ${AMS_MOC_SRCS})
107111

108112
TARGET_LINK_LIBRARIES(arcgismapserverprovider
109113
qgis_core
114+
${QCA_LIBRARY}
110115
)
111116

112117
IF (WITH_GUI)

‎src/providers/arcgisrest/qgsafsdataitems.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ QVector<QgsDataItem *> QgsAfsRootItem::createChildren()
4141
{
4242
QVector<QgsDataItem *> connections;
4343

44-
const QStringList connectionList = QgsOwsConnection::connectionList( "arcgisfeatureserver" );
44+
const QStringList connectionList = QgsOwsConnection::connectionList( "ARCGISFEATURESERVER" );
4545
for ( const QString &connName : connectionList )
4646
{
4747
const QString path = QStringLiteral( "afs:/" ) + connName;
@@ -94,12 +94,13 @@ QgsAfsConnectionItem::QgsAfsConnectionItem( QgsDataItem *parent, const QString &
9494

9595
QVector<QgsDataItem *> QgsAfsConnectionItem::createChildren()
9696
{
97-
const QgsOwsConnection connection( QStringLiteral( "arcgisfeatureserver" ), mConnName );
97+
const QgsOwsConnection connection( QStringLiteral( "ARCGISFEATURESERVER" ), mConnName );
9898
const QString url = connection.uri().param( QStringLiteral( "url" ) );
99+
const QString authcfg = connection.uri().param( QStringLiteral( "authcfg" ) );
99100

100101
QVector<QgsDataItem *> layers;
101102
QString errorTitle, errorMessage;
102-
const QVariantMap serviceData = QgsArcGisRestUtils::getServiceInfo( url, errorTitle, errorMessage );
103+
const QVariantMap serviceData = QgsArcGisRestUtils::getServiceInfo( url, authcfg, errorTitle, errorMessage );
103104
if ( serviceData.isEmpty() )
104105
{
105106
if ( !errorMessage.isEmpty() )
@@ -124,7 +125,7 @@ QVector<QgsDataItem *> QgsAfsConnectionItem::createChildren()
124125
continue;
125126
}
126127
const QString id = layerInfoMap.value( QStringLiteral( "id" ) ).toString();
127-
QgsAfsLayerItem *layer = new QgsAfsLayerItem( this, mName, url + '/' + id, layerInfoMap.value( QStringLiteral( "name" ) ).toString(), authid );
128+
QgsAfsLayerItem *layer = new QgsAfsLayerItem( this, mName, url + '/' + id, layerInfoMap.value( QStringLiteral( "name" ) ).toString(), authid, authcfg );
128129
layers.append( layer );
129130
}
130131

@@ -133,7 +134,7 @@ QVector<QgsDataItem *> QgsAfsConnectionItem::createChildren()
133134

134135
bool QgsAfsConnectionItem::equal( const QgsDataItem *other )
135136
{
136-
const QgsAfsConnectionItem *o = dynamic_cast<const QgsAfsConnectionItem *>( other );
137+
const QgsAfsConnectionItem *o = qobject_cast<const QgsAfsConnectionItem *>( other );
137138
return ( type() == other->type() && o && mPath == o->mPath && mName == o->mName );
138139
}
139140

@@ -200,10 +201,12 @@ void QgsAfsConnectionItem::refreshConnection()
200201

201202
///////////////////////////////////////////////////////////////////////////////
202203

203-
QgsAfsLayerItem::QgsAfsLayerItem( QgsDataItem *parent, const QString &name, const QString &url, const QString &title, const QString &authid )
204+
QgsAfsLayerItem::QgsAfsLayerItem( QgsDataItem *parent, const QString &name, const QString &url, const QString &title, const QString &authid, const QString &authcfg )
204205
: QgsLayerItem( parent, title, parent->path() + "/" + name, QString(), QgsLayerItem::Vector, QStringLiteral( "arcgisfeatureserver" ) )
205206
{
206207
mUri = QStringLiteral( "crs='%1' url='%2'" ).arg( authid, url );
208+
if ( !authcfg.isEmpty() )
209+
mUri += QStringLiteral( " authcfg='%1'" ).arg( authcfg );
207210
setState( Populated );
208211
mIconName = QStringLiteral( "mIconAfs.svg" );
209212
}

‎src/providers/arcgisrest/qgsafsdataitems.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class QgsAfsLayerItem : public QgsLayerItem
6969
Q_OBJECT
7070

7171
public:
72-
QgsAfsLayerItem( QgsDataItem *parent, const QString &name, const QString &url, const QString &title, const QString &authid );
72+
QgsAfsLayerItem( QgsDataItem *parent, const QString &name, const QString &url, const QString &title, const QString &authid, const QString &authcfg );
7373
};
7474

7575
#endif // QGSAFSDATAITEMS_H

‎src/providers/arcgisrest/qgsafsprovider.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@ QgsAfsProvider::QgsAfsProvider( const QString &uri, const ProviderOptions &optio
4444
mSharedData->mGeometryType = QgsWkbTypes::Unknown;
4545
mSharedData->mDataSource = QgsDataSourceUri( uri );
4646

47+
const QString authcfg = mSharedData->mDataSource.authConfigId();
48+
4749
// Set CRS
4850
mSharedData->mSourceCRS.createFromString( mSharedData->mDataSource.param( QStringLiteral( "crs" ) ) );
4951

5052
// Get layer info
5153
QString errorTitle, errorMessage;
52-
const QVariantMap layerData = QgsArcGisRestUtils::getLayerInfo( mSharedData->mDataSource.param( QStringLiteral( "url" ) ), errorTitle, errorMessage );
54+
const QVariantMap layerData = QgsArcGisRestUtils::getLayerInfo( mSharedData->mDataSource.param( QStringLiteral( "url" ) ),
55+
authcfg, errorTitle, errorMessage );
5356
if ( layerData.isEmpty() )
5457
{
5558
pushError( errorTitle + ": " + errorMessage );
@@ -163,7 +166,8 @@ QgsAfsProvider::QgsAfsProvider( const QString &uri, const ProviderOptions &optio
163166
// Read OBJECTIDs of all features: these may not be a continuous sequence,
164167
// and we need to store these to iterate through the features. This query
165168
// also returns the name of the ObjectID field.
166-
QVariantMap objectIdData = QgsArcGisRestUtils::getObjectIds( mSharedData->mDataSource.param( QStringLiteral( "url" ) ), objectIdFieldName, errorTitle, errorMessage, limitBbox ? mSharedData->mExtent : QgsRectangle() );
169+
QVariantMap objectIdData = QgsArcGisRestUtils::getObjectIds( mSharedData->mDataSource.param( QStringLiteral( "url" ) ), authcfg,
170+
objectIdFieldName, errorTitle, errorMessage, limitBbox ? mSharedData->mExtent : QgsRectangle() );
167171
if ( objectIdData.isEmpty() )
168172
{
169173
appendError( QgsErrorMessage( tr( "getObjectIds failed: %1 - %2" ).arg( errorTitle, errorMessage ), QStringLiteral( "AFSProvider" ) ) );

‎src/providers/arcgisrest/qgsafsshareddata.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ bool QgsAfsSharedData::getFeature( QgsFeatureId id, QgsFeature &f, const QgsRect
6868

6969
// Query
7070
QString errorTitle, errorMessage;
71+
72+
const QString authcfg = mDataSource.authConfigId();
7173
const QVariantMap queryData = QgsArcGisRestUtils::getObjects(
72-
mDataSource.param( QStringLiteral( "url" ) ), objectIds, mDataSource.param( QStringLiteral( "crs" ) ), true,
74+
mDataSource.param( QStringLiteral( "url" ) ), authcfg, objectIds, mDataSource.param( QStringLiteral( "crs" ) ), true,
7375
fetchAttribNames, QgsWkbTypes::hasM( mGeometryType ), QgsWkbTypes::hasZ( mGeometryType ),
7476
filterRect, errorTitle, errorMessage, feedback );
7577

@@ -156,10 +158,10 @@ QgsFeatureIds QgsAfsSharedData::getFeatureIdsInExtent( const QgsRectangle &exten
156158
QString errorTitle;
157159
QString errorText;
158160

159-
161+
const QString authcfg = mDataSource.authConfigId();
160162
const QList<quint32> featuresInRect = QgsArcGisRestUtils::getObjectIdsByExtent( mDataSource.param( QStringLiteral( "url" ) ),
161163
mObjectIdFieldName,
162-
extent, errorTitle, errorText, feedback );
164+
extent, errorTitle, errorText, authcfg, feedback );
163165

164166
QgsFeatureIds ids;
165167
for ( quint32 id : featuresInRect )

‎src/providers/arcgisrest/qgsafssourceselect.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828

2929
QgsAfsSourceSelect::QgsAfsSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
30-
: QgsArcGisServiceSourceSelect( QStringLiteral( "ArcGisFeatureServer" ), QgsArcGisServiceSourceSelect::FeatureService, parent, fl, widgetMode )
30+
: QgsArcGisServiceSourceSelect( QStringLiteral( "ARCGISFEATURESERVER" ), QgsArcGisServiceSourceSelect::FeatureService, parent, fl, widgetMode )
3131
{
3232
// import/export of connections not supported yet
3333
btnLoad->hide();
@@ -37,7 +37,9 @@ QgsAfsSourceSelect::QgsAfsSourceSelect( QWidget *parent, Qt::WindowFlags fl, Qgs
3737
bool QgsAfsSourceSelect::connectToService( const QgsOwsConnection &connection )
3838
{
3939
QString errorTitle, errorMessage;
40-
QVariantMap serviceInfoMap = QgsArcGisRestUtils::getServiceInfo( connection.uri().param( QStringLiteral( "url" ) ), errorTitle, errorMessage );
40+
41+
const QString authcfg = connection.uri().param( QStringLiteral( "authcfg" ) );
42+
QVariantMap serviceInfoMap = QgsArcGisRestUtils::getServiceInfo( connection.uri().param( QStringLiteral( "url" ) ), authcfg, errorTitle, errorMessage );
4143
if ( serviceInfoMap.isEmpty() )
4244
{
4345
QMessageBox::warning( this, tr( "Error" ), tr( "Failed to retrieve service capabilities:\n%1: %2" ).arg( errorTitle, errorMessage ) );
@@ -62,7 +64,7 @@ bool QgsAfsSourceSelect::connectToService( const QgsOwsConnection &connection )
6264
}
6365

6466
// Get layer info
65-
const QVariantMap layerData = QgsArcGisRestUtils::getLayerInfo( connection.uri().param( QStringLiteral( "url" ) ) + "/" + layerInfoMap[QStringLiteral( "id" )].toString(), errorTitle, errorMessage );
67+
const QVariantMap layerData = QgsArcGisRestUtils::getLayerInfo( connection.uri().param( QStringLiteral( "url" ) ) + "/" + layerInfoMap[QStringLiteral( "id" )].toString(), authcfg, errorTitle, errorMessage );
6668
if ( layerData.isEmpty() )
6769
{
6870
layerErrors.append( tr( "Layer %1: %2 - %3" ).arg( layerInfoMap[QStringLiteral( "id" )].toString(), errorTitle, errorMessage ) );

‎src/providers/arcgisrest/qgsamsdataitems.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ QVector<QgsDataItem *> QgsAmsRootItem::createChildren()
3838
{
3939
QVector<QgsDataItem *> connections;
4040

41-
const QStringList connectionList = QgsOwsConnection::connectionList( QStringLiteral( "arcgismapserver" ) );
41+
const QStringList connectionList = QgsOwsConnection::connectionList( QStringLiteral( "ARCGISMAPSERVER" ) );
4242
for ( const QString &connName : connectionList )
4343
{
44-
QgsOwsConnection connection( QStringLiteral( "arcgismapserver" ), connName );
44+
QgsOwsConnection connection( QStringLiteral( "ARCGISMAPSERVER" ), connName );
4545
QString path = "ams:/" + connName;
4646
connections.append( new QgsAmsConnectionItem( this, connName, path, connection.uri().param( QStringLiteral( "url" ) ) ) );
4747
}
@@ -94,7 +94,11 @@ QVector<QgsDataItem *> QgsAmsConnectionItem::createChildren()
9494
{
9595
QVector<QgsDataItem *> layers;
9696
QString errorTitle, errorMessage;
97-
QVariantMap serviceData = QgsArcGisRestUtils::getServiceInfo( mUrl, errorTitle, errorMessage );
97+
98+
QgsOwsConnection connection( QStringLiteral( "ARCGISMAPSERVER" ), mName );
99+
100+
const QString authcfg = connection.uri().param( QStringLiteral( "authcfg" ) );
101+
QVariantMap serviceData = QgsArcGisRestUtils::getServiceInfo( mUrl, authcfg, errorTitle, errorMessage );
98102
if ( serviceData.isEmpty() )
99103
{
100104
return layers;
@@ -125,7 +129,7 @@ QVector<QgsDataItem *> QgsAmsConnectionItem::createChildren()
125129
{
126130
QVariantMap layerInfoMap = layerInfo.toMap();
127131
QString id = layerInfoMap[QStringLiteral( "id" )].toString();
128-
QgsAmsLayerItem *layer = new QgsAmsLayerItem( this, mName, mUrl, id, layerInfoMap[QStringLiteral( "name" )].toString(), authid, format );
132+
QgsAmsLayerItem *layer = new QgsAmsLayerItem( this, mName, mUrl, id, layerInfoMap[QStringLiteral( "name" )].toString(), authid, format, authcfg );
129133
layers.append( layer );
130134
}
131135

@@ -174,10 +178,12 @@ void QgsAmsConnectionItem::deleteConnection()
174178

175179
///////////////////////////////////////////////////////////////////////////////
176180

177-
QgsAmsLayerItem::QgsAmsLayerItem( QgsDataItem *parent, const QString &name, const QString &url, const QString &id, const QString &title, const QString &authid, const QString &format )
181+
QgsAmsLayerItem::QgsAmsLayerItem( QgsDataItem *parent, const QString &name, const QString &url, const QString &id, const QString &title, const QString &authid, const QString &format, const QString &authcfg )
178182
: QgsLayerItem( parent, title, parent->path() + "/" + name, QString(), QgsLayerItem::Raster, QStringLiteral( "arcgismapserver" ) )
179183
{
180184
mUri = QStringLiteral( "crs='%1' format='%2' layer='%3' url='%4'" ).arg( authid, format, id, url );
185+
if ( !authcfg.isEmpty() )
186+
mUri += QStringLiteral( " authcfg='%1'" ).arg( authcfg );
181187
setState( Populated );
182188
mIconName = QStringLiteral( "mIconAms.svg" );
183189
}

‎src/providers/arcgisrest/qgsamsdataitems.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class QgsAmsLayerItem : public QgsLayerItem
7171
Q_OBJECT
7272

7373
public:
74-
QgsAmsLayerItem( QgsDataItem *parent, const QString &name, const QString &url, const QString &id, const QString &title, const QString &authid, const QString &format );
74+
QgsAmsLayerItem( QgsDataItem *parent, const QString &name, const QString &url, const QString &id, const QString &title, const QString &authid, const QString &format, const QString &authcfg );
7575
};
7676

7777
#endif // QGSAMSDATAITEMS_H

‎src/providers/arcgisrest/qgsamsprovider.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,12 @@ QgsAmsProvider::QgsAmsProvider( const QString &uri, const ProviderOptions &optio
131131
mLegendFetcher = new QgsAmsLegendFetcher( this );
132132

133133
QgsDataSourceUri dataSource( dataSourceUri() );
134-
mServiceInfo = QgsArcGisRestUtils::getServiceInfo( dataSource.param( QStringLiteral( "url" ) ), mErrorTitle, mError );
135-
mLayerInfo = QgsArcGisRestUtils::getLayerInfo( dataSource.param( QStringLiteral( "url" ) ) + "/" + dataSource.param( QStringLiteral( "layer" ) ), mErrorTitle, mError );
134+
const QString authcfg = dataSource.authConfigId();
136135

137-
QVariantMap extentData = mLayerInfo[QStringLiteral( "extent" )].toMap();
136+
mServiceInfo = QgsArcGisRestUtils::getServiceInfo( dataSource.param( QStringLiteral( "url" ) ), authcfg, mErrorTitle, mError );
137+
mLayerInfo = QgsArcGisRestUtils::getLayerInfo( dataSource.param( QStringLiteral( "url" ) ) + "/" + dataSource.param( QStringLiteral( "layer" ) ), authcfg, mErrorTitle, mError );
138+
139+
const QVariantMap extentData = mLayerInfo.value( QStringLiteral( "extent" ) ).toMap();
138140
mExtent.setXMinimum( extentData[QStringLiteral( "xmin" )].toDouble() );
139141
mExtent.setYMinimum( extentData[QStringLiteral( "ymin" )].toDouble() );
140142
mExtent.setXMaximum( extentData[QStringLiteral( "xmax" )].toDouble() );
@@ -258,6 +260,7 @@ void QgsAmsProvider::draw( const QgsRectangle &viewExtent, int pixelWidth, int p
258260
return;
259261
}
260262
QgsDataSourceUri dataSource( dataSourceUri() );
263+
const QString authcfg = dataSource.param( QStringLiteral( "authcfg" ) );
261264

262265
// Use of tiles currently only implemented if service CRS is meter based
263266
if ( mServiceInfo[QStringLiteral( "singleFusedMapCache" )].toBool() && mCrs.mapUnits() == QgsUnitTypes::DistanceMeters )
@@ -349,7 +352,7 @@ void QgsAmsProvider::draw( const QgsRectangle &viewExtent, int pixelWidth, int p
349352
requestUrl.addQueryItem( QStringLiteral( "layers" ), QStringLiteral( "show:%1" ).arg( dataSource.param( QStringLiteral( "layer" ) ) ) );
350353
requestUrl.addQueryItem( QStringLiteral( "transparent" ), QStringLiteral( "true" ) );
351354
requestUrl.addQueryItem( QStringLiteral( "f" ), QStringLiteral( "image" ) );
352-
QByteArray reply = QgsArcGisRestUtils::queryService( requestUrl, mErrorTitle, mError );
355+
QByteArray reply = QgsArcGisRestUtils::queryService( requestUrl, authcfg, mErrorTitle, mError );
353356
mCachedImage = QImage::fromData( reply, dataSource.param( QStringLiteral( "format" ) ).toLatin1() );
354357
if ( mCachedImage.format() != QImage::Format_ARGB32 )
355358
{
@@ -399,7 +402,9 @@ QgsRasterIdentifyResult QgsAmsProvider::identify( const QgsPointXY &point, QgsRa
399402
queryUrl.addQueryItem( QStringLiteral( "imageDisplay" ), QStringLiteral( "%1,%2,%3" ).arg( width ).arg( height ).arg( dpi ) );
400403
queryUrl.addQueryItem( QStringLiteral( "mapExtent" ), QStringLiteral( "%1,%2,%3,%4" ).arg( extent.xMinimum(), 0, 'f' ).arg( extent.yMinimum(), 0, 'f' ).arg( extent.xMaximum(), 0, 'f' ).arg( extent.yMaximum(), 0, 'f' ) );
401404
queryUrl.addQueryItem( QStringLiteral( "tolerance" ), QStringLiteral( "10" ) );
402-
const QVariantList queryResults = QgsArcGisRestUtils::queryServiceJSON( queryUrl, mErrorTitle, mError ).value( QStringLiteral( "results" ) ).toList();
405+
406+
const QString authcfg = dataSource.param( QStringLiteral( "authcfg" ) );
407+
const QVariantList queryResults = QgsArcGisRestUtils::queryServiceJSON( queryUrl, authcfg, mErrorTitle, mError ).value( QStringLiteral( "results" ) ).toList();
403408

404409
QMap<int, QVariant> entries;
405410

‎src/providers/arcgisrest/qgsamssourceselect.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727

2828
QgsAmsSourceSelect::QgsAmsSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
29-
: QgsArcGisServiceSourceSelect( QStringLiteral( "ArcGisMapServer" ), QgsArcGisServiceSourceSelect::MapService, parent, fl, widgetMode )
29+
: QgsArcGisServiceSourceSelect( QStringLiteral( "ARCGISMAPSERVER" ), QgsArcGisServiceSourceSelect::MapService, parent, fl, widgetMode )
3030
{
3131

3232
// import/export of connections not supported yet
@@ -37,7 +37,9 @@ QgsAmsSourceSelect::QgsAmsSourceSelect( QWidget *parent, Qt::WindowFlags fl, Qgs
3737
bool QgsAmsSourceSelect::connectToService( const QgsOwsConnection &connection )
3838
{
3939
QString errorTitle, errorMessage;
40-
QVariantMap serviceInfoMap = QgsArcGisRestUtils::getServiceInfo( connection.uri().param( QStringLiteral( "url" ) ), errorTitle, errorMessage );
40+
41+
const QString authcfg = connection.uri().param( QStringLiteral( "authcfg" ) );
42+
const QVariantMap serviceInfoMap = QgsArcGisRestUtils::getServiceInfo( connection.uri().param( QStringLiteral( "url" ) ), authcfg, errorTitle, errorMessage );
4143
if ( serviceInfoMap.isEmpty() )
4244
{
4345
QMessageBox::warning( this, tr( "Error" ), tr( "Failed to retrieve service capabilities:\n%1: %2" ).arg( errorTitle, errorMessage ) );
@@ -57,7 +59,8 @@ bool QgsAmsSourceSelect::connectToService( const QgsOwsConnection &connection )
5759
}
5860

5961
// Get layer info
60-
QVariantMap layerData = QgsArcGisRestUtils::getLayerInfo( connection.uri().param( QStringLiteral( "url" ) ) + "/" + layerInfoMap[QStringLiteral( "id" )].toString(), errorTitle, errorMessage );
62+
QVariantMap layerData = QgsArcGisRestUtils::getLayerInfo( connection.uri().param( QStringLiteral( "url" ) ) + "/" + layerInfoMap[QStringLiteral( "id" )].toString(),
63+
authcfg, errorTitle, errorMessage );
6164
if ( layerData.isEmpty() )
6265
{
6366
layerErrors.append( QStringLiteral( "Layer %1: %2 - %3" ).arg( layerInfoMap[QStringLiteral( "id" )].toString(), errorTitle, errorMessage ) );

‎src/providers/arcgisrest/qgsarcgisrestutils.cpp

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include "qgsfeedback.h"
3131
#include "qgssymbol.h"
3232
#include "qgssymbollayer.h"
33+
#include "qgsauthmanager.h"
34+
#include "qgssettings.h"
3335
#include "qgslinesymbollayer.h"
3436
#include "qgsfillsymbollayer.h"
3537
#include "qgsmarkersymbollayer.h"
@@ -43,7 +45,6 @@
4345
#include <QJsonDocument>
4446
#include <QJsonObject>
4547

46-
4748
QVariant::Type QgsArcGisRestUtils::mapEsriFieldType( const QString &esriFieldType )
4849
{
4950
if ( esriFieldType == QLatin1String( "esriFieldTypeInteger" ) )
@@ -351,23 +352,23 @@ QgsCoordinateReferenceSystem QgsArcGisRestUtils::parseSpatialReference( const QV
351352
}
352353

353354

354-
QVariantMap QgsArcGisRestUtils::getServiceInfo( const QString &baseurl, QString &errorTitle, QString &errorText )
355+
QVariantMap QgsArcGisRestUtils::getServiceInfo( const QString &baseurl, const QString &authcfg, QString &errorTitle, QString &errorText )
355356
{
356357
// http://sampleserver5.arcgisonline.com/arcgis/rest/services/Energy/Geology/FeatureServer?f=json
357358
QUrl queryUrl( baseurl );
358359
queryUrl.addQueryItem( QStringLiteral( "f" ), QStringLiteral( "json" ) );
359-
return queryServiceJSON( queryUrl, errorTitle, errorText );
360+
return queryServiceJSON( queryUrl, authcfg, errorTitle, errorText );
360361
}
361362

362-
QVariantMap QgsArcGisRestUtils::getLayerInfo( const QString &layerurl, QString &errorTitle, QString &errorText )
363+
QVariantMap QgsArcGisRestUtils::getLayerInfo( const QString &layerurl, const QString &authcfg, QString &errorTitle, QString &errorText )
363364
{
364365
// http://sampleserver5.arcgisonline.com/arcgis/rest/services/Energy/Geology/FeatureServer/1?f=json
365366
QUrl queryUrl( layerurl );
366367
queryUrl.addQueryItem( QStringLiteral( "f" ), QStringLiteral( "json" ) );
367-
return queryServiceJSON( queryUrl, errorTitle, errorText );
368+
return queryServiceJSON( queryUrl, authcfg, errorTitle, errorText );
368369
}
369370

370-
QVariantMap QgsArcGisRestUtils::getObjectIds( const QString &layerurl, const QString &objectIdFieldName, QString &errorTitle, QString &errorText, const QgsRectangle &bbox )
371+
QVariantMap QgsArcGisRestUtils::getObjectIds( const QString &layerurl, const QString &authcfg, const QString &objectIdFieldName, QString &errorTitle, QString &errorText, const QgsRectangle &bbox )
371372
{
372373
// http://sampleserver5.arcgisonline.com/arcgis/rest/services/Energy/Geology/FeatureServer/1/query?where=objectid%3Dobjectid&returnIdsOnly=true&f=json
373374
QUrl queryUrl( layerurl + "/query" );
@@ -382,10 +383,10 @@ QVariantMap QgsArcGisRestUtils::getObjectIds( const QString &layerurl, const QSt
382383
queryUrl.addQueryItem( QStringLiteral( "geometryType" ), QStringLiteral( "esriGeometryEnvelope" ) );
383384
queryUrl.addQueryItem( QStringLiteral( "spatialRel" ), QStringLiteral( "esriSpatialRelEnvelopeIntersects" ) );
384385
}
385-
return queryServiceJSON( queryUrl, errorTitle, errorText );
386+
return queryServiceJSON( queryUrl, authcfg, errorTitle, errorText );
386387
}
387388

388-
QVariantMap QgsArcGisRestUtils::getObjects( const QString &layerurl, const QList<quint32> &objectIds, const QString &crs,
389+
QVariantMap QgsArcGisRestUtils::getObjects( const QString &layerurl, const QString &authcfg, const QList<quint32> &objectIds, const QString &crs,
389390
bool fetchGeometry, const QStringList &fetchAttributes,
390391
bool fetchM, bool fetchZ,
391392
const QgsRectangle &filterRect,
@@ -423,10 +424,10 @@ QVariantMap QgsArcGisRestUtils::getObjects( const QString &layerurl, const QList
423424
queryUrl.addQueryItem( QStringLiteral( "geometryType" ), QStringLiteral( "esriGeometryEnvelope" ) );
424425
queryUrl.addQueryItem( QStringLiteral( "spatialRel" ), QStringLiteral( "esriSpatialRelEnvelopeIntersects" ) );
425426
}
426-
return queryServiceJSON( queryUrl, errorTitle, errorText, feedback );
427+
return queryServiceJSON( queryUrl, authcfg, errorTitle, errorText, feedback );
427428
}
428429

429-
QList<quint32> QgsArcGisRestUtils::getObjectIdsByExtent( const QString &layerurl, const QString &objectIdField, const QgsRectangle &filterRect, QString &errorTitle, QString &errorText, QgsFeedback *feedback )
430+
QList<quint32> QgsArcGisRestUtils::getObjectIdsByExtent( const QString &layerurl, const QString &objectIdField, const QgsRectangle &filterRect, QString &errorTitle, QString &errorText, const QString &authcfg, QgsFeedback *feedback )
430431
{
431432
QUrl queryUrl( layerurl + "/query" );
432433
queryUrl.addQueryItem( QStringLiteral( "f" ), QStringLiteral( "json" ) );
@@ -437,27 +438,35 @@ QList<quint32> QgsArcGisRestUtils::getObjectIdsByExtent( const QString &layerurl
437438
.arg( filterRect.xMaximum(), 0, 'f', -1 ).arg( filterRect.yMaximum(), 0, 'f', -1 ) );
438439
queryUrl.addQueryItem( QStringLiteral( "geometryType" ), QStringLiteral( "esriGeometryEnvelope" ) );
439440
queryUrl.addQueryItem( QStringLiteral( "spatialRel" ), QStringLiteral( "esriSpatialRelEnvelopeIntersects" ) );
440-
const QVariantMap objectIdData = queryServiceJSON( queryUrl, errorTitle, errorText, feedback );
441+
const QVariantMap objectIdData = queryServiceJSON( queryUrl, authcfg, errorTitle, errorText, feedback );
441442

442443
if ( objectIdData.isEmpty() )
443444
{
444445
return QList<quint32>();
445446
}
446447

447448
QList<quint32> ids;
448-
foreach ( const QVariant &objectId, objectIdData["objectIds"].toList() )
449+
const QVariantList objectIdsList = objectIdData[QStringLiteral( "objectIds" )].toList();
450+
ids.reserve( objectIdsList.size() );
451+
for ( const QVariant &objectId : objectIdsList )
449452
{
450453
ids << objectId.toInt();
451454
}
452455
return ids;
453456
}
454457

455-
QByteArray QgsArcGisRestUtils::queryService( const QUrl &u, QString &errorTitle, QString &errorText, QgsFeedback *feedback )
458+
QByteArray QgsArcGisRestUtils::queryService( const QUrl &u, const QString &authcfg, QString &errorTitle, QString &errorText, QgsFeedback *feedback )
456459
{
457460
QEventLoop loop;
458461
QUrl url = parseUrl( u );
459462

460463
QNetworkRequest request( url );
464+
465+
if ( !authcfg.isEmpty() )
466+
{
467+
QgsApplication::authManager()->updateNetworkRequest( request, authcfg );
468+
}
469+
461470
QNetworkReply *reply = nullptr;
462471
QgsNetworkAccessManager *nam = QgsNetworkAccessManager::instance();
463472

@@ -501,9 +510,9 @@ QByteArray QgsArcGisRestUtils::queryService( const QUrl &u, QString &errorTitle,
501510
return result;
502511
}
503512

504-
QVariantMap QgsArcGisRestUtils::queryServiceJSON( const QUrl &url, QString &errorTitle, QString &errorText, QgsFeedback *feedback )
513+
QVariantMap QgsArcGisRestUtils::queryServiceJSON( const QUrl &url, const QString &authcfg, QString &errorTitle, QString &errorText, QgsFeedback *feedback )
505514
{
506-
QByteArray reply = queryService( url, errorTitle, errorText, feedback );
515+
QByteArray reply = queryService( url, authcfg, errorTitle, errorText, feedback );
507516
if ( !errorTitle.isEmpty() )
508517
{
509518
return QVariantMap();

‎src/providers/arcgisrest/qgsarcgisrestutils.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ class QgsArcGisRestUtils
4040
static std::unique_ptr< QgsAbstractGeometry > parseEsriGeoJSON( const QVariantMap &geometryData, const QString &esriGeometryType, bool readM, bool readZ, QgsCoordinateReferenceSystem *crs = nullptr );
4141
static QgsCoordinateReferenceSystem parseSpatialReference( const QVariantMap &spatialReferenceMap );
4242

43-
static QVariantMap getServiceInfo( const QString &baseurl, QString &errorTitle, QString &errorText );
44-
static QVariantMap getLayerInfo( const QString &layerurl, QString &errorTitle, QString &errorText );
45-
static QVariantMap getObjectIds( const QString &layerurl, const QString &objectIdFieldName, QString &errorTitle, QString &errorText,
43+
static QVariantMap getServiceInfo( const QString &baseurl, const QString &authcfg, QString &errorTitle, QString &errorText );
44+
static QVariantMap getLayerInfo( const QString &layerurl, const QString &authcfg, QString &errorTitle, QString &errorText );
45+
static QVariantMap getObjectIds( const QString &layerurl, const QString &authcfg, const QString &objectIdFieldName, QString &errorTitle, QString &errorText,
4646
const QgsRectangle &bbox = QgsRectangle() );
47-
static QVariantMap getObjects( const QString &layerurl, const QList<quint32> &objectIds, const QString &crs,
47+
static QVariantMap getObjects( const QString &layerurl, const QString &authcfg, const QList<quint32> &objectIds, const QString &crs,
4848
bool fetchGeometry, const QStringList &fetchAttributes, bool fetchM, bool fetchZ,
4949
const QgsRectangle &filterRect, QString &errorTitle, QString &errorText, QgsFeedback *feedback = nullptr );
50-
static QList<quint32> getObjectIdsByExtent( const QString &layerurl, const QString &objectIdField, const QgsRectangle &filterRect, QString &errorTitle, QString &errorText, QgsFeedback *feedback = nullptr );
51-
static QByteArray queryService( const QUrl &url, QString &errorTitle, QString &errorText, QgsFeedback *feedback = nullptr );
52-
static QVariantMap queryServiceJSON( const QUrl &url, QString &errorTitle, QString &errorText, QgsFeedback *feedback = nullptr );
50+
static QList<quint32> getObjectIdsByExtent( const QString &layerurl, const QString &objectIdField, const QgsRectangle &filterRect, QString &errorTitle, QString &errorText, const QString &authcfg, QgsFeedback *feedback = nullptr );
51+
static QByteArray queryService( const QUrl &url, const QString &authcfg, QString &errorTitle, QString &errorText, QgsFeedback *feedback = nullptr );
52+
static QVariantMap queryServiceJSON( const QUrl &url, const QString &authcfg, QString &errorTitle, QString &errorText, QgsFeedback *feedback = nullptr );
5353

5454
static std::unique_ptr< QgsSymbol > parseEsriSymbolJson( const QVariantMap &symbolData );
5555
static std::unique_ptr< QgsLineSymbol > parseEsriLineSymbolJson( const QVariantMap &symbolData );

‎src/providers/arcgisrest/qgsarcgisservicesourceselect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void QgsArcGisServiceSourceSelect::populateImageEncodings( const QStringList &av
144144

145145
QString QgsArcGisServiceSourceSelect::getSelectedImageEncoding() const
146146
{
147-
return mImageEncodingGroup ? mImageEncodingGroup->checkedButton()->text() : QString();
147+
return mImageEncodingGroup && mImageEncodingGroup->checkedButton() ? mImageEncodingGroup->checkedButton()->text() : QString();
148148
}
149149

150150
void QgsArcGisServiceSourceSelect::populateConnectionList()

0 commit comments

Comments
 (0)
Please sign in to comment.