Skip to content

Commit 907b019

Browse files
committedSep 21, 2015
[auth system] Data source integration for OWS connections
1 parent 0d2b945 commit 907b019

22 files changed

+376
-132
lines changed
 

‎python/core/qgsgml.sip

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ class QgsGml: QObject
1919
* @param extent retrieved extents
2020
* @param userName username for authentication
2121
* @param password password for authentication
22+
* @param authcfg authentication configuration id
2223
* @return 0 in case of success
2324
*/
24-
int getFeatures( const QString& uri, QGis::WkbType* wkbType, QgsRectangle* extent = 0, const QString& userName = QString(), const QString& password = QString() ) /PyName=getFeaturesUri/;
25+
int getFeatures( const QString& uri, QGis::WkbType* wkbType, QgsRectangle* extent = 0, const QString& userName = QString(), const QString& password = QString(), const QString& authcfg = QString() ) /PyName=getFeaturesUri/;
2526

2627
/** Read from GML data. Constructor uri param is ignored
2728
* Supports only UTF-8, UTF-16, ISO-8859-1, ISO-8859-1 XML encodings.

‎src/core/qgsgml.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* *
1414
***************************************************************************/
1515
#include "qgsgml.h"
16+
#include "qgsauthmanager.h"
1617
#include "qgsrectangle.h"
1718
#include "qgscoordinatereferencesystem.h"
1819
#include "qgsgeometry.h"
@@ -69,7 +70,7 @@ QgsGml::~QgsGml()
6970
{
7071
}
7172

72-
int QgsGml::getFeatures( const QString& uri, QGis::WkbType* wkbType, QgsRectangle* extent, const QString& userName, const QString& password )
73+
int QgsGml::getFeatures( const QString& uri, QGis::WkbType* wkbType, QgsRectangle* extent, const QString& userName, const QString& password , const QString& authcfg )
7374
{
7475
mUri = uri;
7576
mWkbType = wkbType;
@@ -83,7 +84,19 @@ int QgsGml::getFeatures( const QString& uri, QGis::WkbType* wkbType, QgsRectangl
8384
mExtent.setMinimal();
8485

8586
QNetworkRequest request( mUri );
86-
if ( !userName.isNull() || !password.isNull() )
87+
if ( !authcfg.isEmpty() )
88+
{
89+
if ( !QgsAuthManager::instance()->updateNetworkRequest( request, authcfg ) )
90+
{
91+
QgsMessageLog::logMessage(
92+
tr( "GML Getfeature network request update failed for authcfg %1" ).arg( authcfg ),
93+
tr( "Network" ),
94+
QgsMessageLog::CRITICAL
95+
);
96+
return 1;
97+
}
98+
}
99+
else if ( !userName.isNull() || !password.isNull() )
87100
{
88101
request.setRawHeader( "Authorization", "Basic " + QString( "%1:%2" ).arg( userName ).arg( password ).toAscii().toBase64() );
89102
}

‎src/core/qgsgml.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,15 @@ class CORE_EXPORT QgsGml : public QObject
5656
* @param extent retrieved extents
5757
* @param userName username for authentication
5858
* @param password password for authentication
59+
* @param authcfg authentication configuration id
5960
* @return 0 in case of success
6061
*/
61-
int getFeatures( const QString& uri, QGis::WkbType* wkbType, QgsRectangle* extent = 0, const QString& userName = QString(), const QString& password = QString() );
62+
int getFeatures( const QString& uri,
63+
QGis::WkbType* wkbType,
64+
QgsRectangle* extent = 0,
65+
const QString& userName = QString(),
66+
const QString& password = QString(),
67+
const QString& authcfg = QString() );
6268

6369
/** Read from GML data. Constructor uri param is ignored
6470
* Supports only UTF-8, UTF-16, ISO-8859-1, ISO-8859-1 XML encodings.

‎src/core/qgsowsconnection.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ QgsOWSConnection::QgsOWSConnection( const QString & theService, const QString &
6161
mUri.setParam( "password", password );
6262
}
6363

64+
QString authcfg = settings.value( credentialsKey + "/authcfg" ).toString();
65+
if ( !authcfg.isEmpty() )
66+
{
67+
mUri.setParam( "authcfg", authcfg );
68+
}
69+
mConnectionInfo.append( ",authcfg=" + authcfg );
70+
6471
bool ignoreGetMap = settings.value( key + "/ignoreGetMapURI", false ).toBool();
6572
bool ignoreGetFeatureInfo = settings.value( key + "/ignoreGetFeatureInfoURI", false ).toBool();
6673
bool ignoreAxisOrientation = settings.value( key + "/ignoreAxisOrientation", false ).toBool();

‎src/gui/qgsnewhttpconnection.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
#include <QRegExpValidator>
2424

2525
QgsNewHttpConnection::QgsNewHttpConnection(
26-
QWidget *parent, const QString& baseKey, const QString& connName, Qt::WindowFlags fl ):
27-
QDialog( parent, fl ),
28-
mBaseKey( baseKey ),
29-
mOriginalConnName( connName )
26+
QWidget *parent, const QString& baseKey, const QString& connName, Qt::WindowFlags fl )
27+
: QDialog( parent, fl )
28+
, mBaseKey( baseKey )
29+
, mOriginalConnName( connName )
30+
, mAuthConfigSelect( 0 )
3031
{
3132
setupUi( this );
3233

@@ -49,6 +50,9 @@ QgsNewHttpConnection::QgsNewHttpConnection(
4950
cmbDpiMode->addItem( tr( "UMN" ) );
5051
cmbDpiMode->addItem( tr( "GeoServer" ) );
5152

53+
mAuthConfigSelect = new QgsAuthConfigSelect( this );
54+
tabAuth->insertTab( 1, mAuthConfigSelect, tr( "Configurations" ) );
55+
5256
if ( !connName.isEmpty() )
5357
{
5458
// populate the dialog with the information stored for the connection
@@ -92,6 +96,13 @@ QgsNewHttpConnection::QgsNewHttpConnection(
9296

9397
txtUserName->setText( settings.value( credentialsKey + "/username" ).toString() );
9498
txtPassword->setText( settings.value( credentialsKey + "/password" ).toString() );
99+
100+
QString authcfg = settings.value( credentialsKey + "/authcfg" ).toString();
101+
mAuthConfigSelect->setConfigId( authcfg );
102+
if ( !authcfg.isEmpty() )
103+
{
104+
tabAuth->setCurrentIndex( tabAuth->indexOf( mAuthConfigSelect ) );
105+
}
95106
}
96107

97108
if ( mBaseKey != "/Qgis/connections-wms/" )
@@ -247,6 +258,8 @@ void QgsNewHttpConnection::accept()
247258
settings.setValue( credentialsKey + "/username", txtUserName->text() );
248259
settings.setValue( credentialsKey + "/password", txtPassword->text() );
249260

261+
settings.setValue( credentialsKey + "/authcfg", mAuthConfigSelect->configId() );
262+
250263
settings.setValue( mBaseKey + "/selected", txtName->text() );
251264

252265
QDialog::accept();

‎src/gui/qgsnewhttpconnection.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "ui_qgsnewhttpconnectionbase.h"
2020
#include "qgisgui.h"
2121
#include "qgscontexthelp.h"
22+
#include "qgsauthconfigselect.h"
23+
2224
/*!
2325
* \brief Dialog to allow the user to configure and save connection
2426
* information for an HTTP Server for WMS, etc.
@@ -46,6 +48,7 @@ class GUI_EXPORT QgsNewHttpConnection : public QDialog, private Ui::QgsNewHttpCo
4648
QString mBaseKey;
4749
QString mCredentialsBaseKey;
4850
QString mOriginalConnName; //store initial name to delete entry in case of rename
51+
QgsAuthConfigSelect * mAuthConfigSelect;
4952
};
5053

5154
#endif // QGSNEWHTTPCONNECTION_H

‎src/providers/ows/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ SET(OWS_MOC_HDRS
99

1010
INCLUDE_DIRECTORIES (
1111
../../core
12+
../../core/auth
1213
../../gui
14+
../../gui/auth
1315
${CMAKE_CURRENT_BINARY_DIR}/../../ui
1416
)
1517

‎src/providers/wcs/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,17 @@ SET (WCS_MOC_HDRS
1616

1717
QT4_WRAP_CPP (WCS_MOC_SRCS ${WCS_MOC_HDRS})
1818

19-
INCLUDE_DIRECTORIES( . ../../core ../../core/raster ../../gui
19+
INCLUDE_DIRECTORIES(
20+
.
21+
../../core
22+
../../core/auth
23+
../../core/raster
24+
../../gui
25+
../../gui/auth
2026
../gdal
2127
${CMAKE_CURRENT_BINARY_DIR}/../../ui
2228
${GDAL_INCLUDE_DIR}
29+
${QCA_INCLUDE_DIR}
2330
)
2431

2532
ADD_LIBRARY(wcsprovider MODULE ${WCS_SRCS} ${WCS_MOC_SRCS})

‎src/providers/wcs/qgswcscapabilities.cpp

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

2727
#include <cmath>
2828

29+
#include "qgsauthmanager.h"
2930
#include "qgscoordinatetransform.h"
3031
#include "qgsdatasourceuri.h"
3132
#include "qgsrasterlayer.h"
@@ -159,7 +160,12 @@ bool QgsWcsCapabilities::sendRequest( QString const & url )
159160
QgsDebugMsg( "url = " + url );
160161
mError = "";
161162
QNetworkRequest request( url );
162-
setAuthorization( request );
163+
if ( !setAuthorization( request ) )
164+
{
165+
mError = tr( "Download of capabilities failed: network request update failed for authentication config" );
166+
QgsMessageLog::logMessage( mError, tr( "WCS" ) );
167+
return false;
168+
}
163169
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
164170
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, mCacheLoadControl );
165171
QgsDebugMsg( QString( "mCacheLoadControl = %1" ).arg( mCacheLoadControl ) );
@@ -359,7 +365,13 @@ void QgsWcsCapabilities::capabilitiesReplyFinished()
359365
emit statusChanged( tr( "Capabilities request redirected." ) );
360366

361367
QNetworkRequest request( redirect.toUrl() );
362-
setAuthorization( request );
368+
if ( !setAuthorization( request ) )
369+
{
370+
mCapabilitiesResponse.clear();
371+
mError = tr( "Download of capabilities failed: network request update failed for authentication config" );
372+
QgsMessageLog::logMessage( mError, tr( "WCS" ) );
373+
return;
374+
}
363375
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork );
364376
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
365377

@@ -1162,14 +1174,19 @@ QString QgsWcsCapabilities::lastErrorFormat()
11621174
return mErrorFormat;
11631175
}
11641176

1165-
void QgsWcsCapabilities::setAuthorization( QNetworkRequest &request ) const
1177+
bool QgsWcsCapabilities::setAuthorization( QNetworkRequest &request ) const
11661178
{
11671179
QgsDebugMsg( "entered" );
1168-
if ( mUri.hasParam( "username" ) && mUri.hasParam( "password" ) )
1180+
if ( mUri.hasParam( "authcfg" ) && !mUri.param( "authcfg" ).isEmpty() )
1181+
{
1182+
return QgsAuthManager::instance()->updateNetworkRequest( request, mUri.param( "authcfg" ) );
1183+
}
1184+
else if ( mUri.hasParam( "username" ) && mUri.hasParam( "password" ) )
11691185
{
11701186
QgsDebugMsg( "setAuthorization " + mUri.param( "username" ) );
11711187
request.setRawHeader( "Authorization", "Basic " + QString( "%1:%2" ).arg( mUri.param( "username" ) ).arg( mUri.param( "password" ) ).toAscii().toBase64() );
11721188
}
1189+
return true;
11731190
}
11741191

11751192
void QgsWcsCapabilities::showMessageBox( const QString& title, const QString& text )

‎src/providers/wcs/qgswcscapabilities.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class QgsWcsCapabilities : public QObject
153153
bool parseDescribeCoverageDom11( QByteArray const &xml, QgsWcsCoverageSummary *coverage );
154154

155155
//! set authorization header
156-
void setAuthorization( QNetworkRequest &request ) const;
156+
bool setAuthorization( QNetworkRequest &request ) const;
157157

158158
QString version() const { return mCapabilities.version; }
159159

‎src/providers/wcs/qgswcsprovider.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,12 @@ bool QgsWcsProvider::parseUri( QString uriString )
408408
mAuth.mPassword = uri.param( "password" );
409409
QgsDebugMsg( "set password to " + mAuth.mPassword );
410410

411+
if ( uri.hasParam( "authcfg" ) )
412+
{
413+
mAuth.mAuthCfg = uri.param( "authcfg" );
414+
}
415+
QgsDebugMsg( "set authcfg to " + mAuth.mAuthCfg );
416+
411417
mIdentifier = uri.param( "identifier" );
412418

413419
mTime = uri.param( "time" );
@@ -1667,6 +1673,7 @@ int QgsWcsDownloadHandler::sErrors = 0;
16671673

16681674
QgsWcsDownloadHandler::QgsWcsDownloadHandler( const QUrl& url, QgsWcsAuthorization& auth, QNetworkRequest::CacheLoadControl cacheLoadControl, QByteArray& cachedData, const QString& wcsVersion, QgsError& cachedError )
16691675
: mNAM( new QgsNetworkAccessManager )
1676+
, mAuth( auth )
16701677
, mEventLoop( new QEventLoop )
16711678
, mCachedData( cachedData )
16721679
, mWcsVersion( wcsVersion )
@@ -1675,7 +1682,12 @@ QgsWcsDownloadHandler::QgsWcsDownloadHandler( const QUrl& url, QgsWcsAuthorizati
16751682
mNAM->setupDefaultProxyAndCache();
16761683

16771684
QNetworkRequest request( url );
1678-
auth.setAuthorization( request );
1685+
if ( !mAuth.setAuthorization( request ) )
1686+
{
1687+
QgsMessageLog::logMessage( tr( "Network request update failed for authentication config" ),
1688+
tr( "WCS" ) );
1689+
return;
1690+
}
16791691
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
16801692
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, cacheLoadControl );
16811693

@@ -1708,7 +1720,14 @@ void QgsWcsDownloadHandler::cacheReplyFinished()
17081720
mCacheReply->deleteLater();
17091721

17101722
QgsDebugMsg( QString( "redirected getmap: %1" ).arg( redirect.toString() ) );
1711-
mCacheReply = mNAM->get( QNetworkRequest( redirect.toUrl() ) );
1723+
QNetworkRequest request( redirect.toUrl() );
1724+
if ( !mAuth.setAuthorization( request ) )
1725+
{
1726+
QgsMessageLog::logMessage( tr( "Network request update failed for authentication config" ),
1727+
tr( "WCS" ) );
1728+
return;
1729+
}
1730+
mCacheReply = mNAM->get( request );
17121731
connect( mCacheReply, SIGNAL( finished() ), this, SLOT( cacheReplyFinished() ) );
17131732
connect( mCacheReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( cacheReplyProgress( qint64, qint64 ) ) );
17141733

‎src/providers/wcs/qgswcsprovider.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include "qgserror.h"
2626
#include "qgswcscapabilities.h"
27+
#include "qgsauthmanager.h"
2728
#include "qgsrasterdataprovider.h"
2829
#include "qgsgdalproviderbase.h"
2930
#include "qgsrectangle.h"
@@ -50,22 +51,34 @@ class QNetworkRequest;
5051
// TODO: merge with QgsWmsAuthorization?
5152
struct QgsWcsAuthorization
5253
{
53-
QgsWcsAuthorization( const QString& userName = QString(), const QString& password = QString() ) : mUserName( userName ), mPassword( password ) {}
54+
QgsWcsAuthorization( const QString& userName = QString(), const QString& password = QString(), const QString& authcfg = QString() )
55+
: mUserName( userName )
56+
, mPassword( password )
57+
, mAuthCfg( authcfg )
58+
{}
5459

5560
//! set authorization header
56-
void setAuthorization( QNetworkRequest &request ) const
61+
bool setAuthorization( QNetworkRequest &request ) const
5762
{
58-
if ( !mUserName.isNull() || !mPassword.isNull() )
63+
if ( !mAuthCfg.isEmpty() )
64+
{
65+
return QgsAuthManager::instance()->updateNetworkRequest( request, mAuthCfg );
66+
}
67+
else if ( !mUserName.isNull() || !mPassword.isNull() )
5968
{
6069
request.setRawHeader( "Authorization", "Basic " + QString( "%1:%2" ).arg( mUserName ).arg( mPassword ).toAscii().toBase64() );
6170
}
71+
return true;
6272
}
6373

6474
//! Username for basic http authentication
6575
QString mUserName;
6676

6777
//! Password for basic http authentication
6878
QString mPassword;
79+
80+
//! Authentication configuration ID
81+
QString mAuthCfg;
6982
};
7083

7184
/**
@@ -424,6 +437,7 @@ class QgsWcsDownloadHandler : public QObject
424437
void finish() { QMetaObject::invokeMethod( mEventLoop, "quit", Qt::QueuedConnection ); }
425438

426439
QgsNetworkAccessManager* mNAM;
440+
QgsWcsAuthorization& mAuth;
427441
QEventLoop* mEventLoop;
428442

429443
QNetworkReply* mCacheReply;

‎src/providers/wfs/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@ QT4_WRAP_CPP(WFS_MOC_SRCS ${WFS_MOC_HDRS})
2525

2626
INCLUDE_DIRECTORIES (
2727
../../core
28+
../../core/auth
2829
../../core/geometry
2930
../../gui
31+
../../gui/auth
3032
${CMAKE_CURRENT_BINARY_DIR}/../../ui
3133
${GEOS_INCLUDE_DIR}
3234
${GEOS_INCLUDE_DIR}/geos
3335
${EXPAT_INCLUDE_DIR}
3436
${QSCINTILLA_INCLUDE_DIR}
37+
${QCA_INCLUDE_DIR}
3538
)
3639

3740
ADD_LIBRARY (wfsprovider MODULE ${WFS_SRCS} ${WFS_MOC_SRCS})

‎src/providers/wfs/qgswfscapabilities.cpp

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* *
1414
***************************************************************************/
1515
#include "qgswfscapabilities.h"
16+
#include "qgsauthmanager.h"
1617
#include "qgsexpression.h"
1718
#include "qgslogger.h"
1819
#include "qgsmessagelog.h"
@@ -141,18 +142,27 @@ QString QgsWFSCapabilities::uriGetFeature( QString typeName, QString crsString,
141142
uri += "&username=" + mUri.param( "username" );
142143
uri += "&password=" + mUri.param( "password" );
143144
}
145+
if ( mUri.hasParam( "authcfg" ) )
146+
{
147+
uri += "&authcfg=" + mUri.param( "authcfg" );
148+
}
144149
QgsDebugMsg( uri );
145150
return uri;
146151
}
147152

148-
void QgsWFSCapabilities::setAuthorization( QNetworkRequest &request ) const
153+
bool QgsWFSCapabilities::setAuthorization( QNetworkRequest &request ) const
149154
{
150155
QgsDebugMsg( "entered" );
151-
if ( mUri.hasParam( "username" ) && mUri.hasParam( "password" ) )
156+
if ( mUri.hasParam( "authcfg" ) && !mUri.param( "authcfg" ).isEmpty() )
157+
{
158+
return QgsAuthManager::instance()->updateNetworkRequest( request, mUri.param( "authcfg" ) );
159+
}
160+
else if ( mUri.hasParam( "username" ) && mUri.hasParam( "password" ) )
152161
{
153162
QgsDebugMsg( "setAuthorization " + mUri.param( "username" ) );
154163
request.setRawHeader( "Authorization", "Basic " + QString( "%1:%2" ).arg( mUri.param( "username" ) ).arg( mUri.param( "password" ) ).toAscii().toBase64() );
155164
}
165+
return true;
156166
}
157167

158168
void QgsWFSCapabilities::requestCapabilities()
@@ -161,7 +171,15 @@ void QgsWFSCapabilities::requestCapabilities()
161171
mErrorMessage.clear();
162172

163173
QNetworkRequest request( uriGetCapabilities() );
164-
setAuthorization( request );
174+
if ( !setAuthorization( request ) )
175+
{
176+
mErrorCode = QgsWFSCapabilities::NetworkError;
177+
mErrorMessage = tr( "Download of capabilities failed: network request update failed for authentication config" );
178+
QgsMessageLog::logMessage( mErrorMessage, tr( "WFS" ) );
179+
emit gotCapabilities();
180+
return;
181+
}
182+
165183
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
166184
mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );
167185
connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) );
@@ -188,7 +206,16 @@ void QgsWFSCapabilities::capabilitiesReplyFinished()
188206
{
189207
QgsDebugMsg( "redirecting to " + redirect.toUrl().toString() );
190208
QNetworkRequest request( redirect.toUrl() );
191-
setAuthorization( request );
209+
if ( !setAuthorization( request ) )
210+
{
211+
mCaps.clear();
212+
mErrorCode = QgsWFSCapabilities::NetworkError;
213+
mErrorMessage = tr( "Download of capabilities failed: network request update failed for authentication config" );
214+
QgsMessageLog::logMessage( mErrorMessage, tr( "WFS" ) );
215+
emit gotCapabilities();
216+
return;
217+
}
218+
192219
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork );
193220
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
194221

‎src/providers/wfs/qgswfscapabilities.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class QgsWFSCapabilities : public QObject
7474
GetCapabilities capabilities() { return mCaps; }
7575

7676
//! set authorization header
77-
void setAuthorization( QNetworkRequest &request ) const;
77+
bool setAuthorization( QNetworkRequest &request ) const;
7878

7979
signals:
8080
void gotCapabilities();

‎src/providers/wfs/qgswfsprovider.cpp

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ QgsWFSProvider::QgsWFSProvider( const QString& uri )
9999

100100
mAuth.mUserName = parameterFromUrl( "username" );
101101
mAuth.mPassword = parameterFromUrl( "password" );
102+
mAuth.mAuthCfg = parameterFromUrl( "authcfg" );
102103

103104
//fetch attributes of layer and type of its geometry attribute
104105
//WBC 111221: extracting geometry type here instead of getFeature allows successful
@@ -706,8 +707,14 @@ int QgsWFSProvider::getFeatureGET( const QString& uri, const QString& geometryAt
706707
QUrl getFeatureUrl( uri );
707708
getFeatureUrl.removeQueryItem( "username" );
708709
getFeatureUrl.removeQueryItem( "password" );
710+
getFeatureUrl.removeQueryItem( "authcfg" );
709711
QgsRectangle extent;
710-
if ( dataReader.getFeatures( getFeatureUrl.toString(), &mWKBType, mCached ? &mExtent : &extent, mAuth.mUserName, mAuth.mPassword ) != 0 )
712+
if ( dataReader.getFeatures( getFeatureUrl.toString(),
713+
&mWKBType,
714+
mCached ? &mExtent : &extent,
715+
mAuth.mUserName,
716+
mAuth.mPassword,
717+
mAuth.mAuthCfg ) != 0 )
711718
{
712719
QgsDebugMsg( "getWFSData returned with error" );
713720
return 1;
@@ -778,11 +785,17 @@ int QgsWFSProvider::describeFeatureTypeGET( const QString& uri, QString& geometr
778785
QUrl describeFeatureUrl( uri );
779786
describeFeatureUrl.removeQueryItem( "username" );
780787
describeFeatureUrl.removeQueryItem( "password" );
788+
describeFeatureUrl.removeQueryItem( "authcfg" );
781789
describeFeatureUrl.removeQueryItem( "SRSNAME" );
782790
describeFeatureUrl.removeQueryItem( "REQUEST" );
783791
describeFeatureUrl.addQueryItem( "REQUEST", "DescribeFeatureType" );
784792
QNetworkRequest request( describeFeatureUrl.toString() );
785-
mAuth.setAuthorization( request );
793+
if ( !mAuth.setAuthorization( request ) )
794+
{
795+
QgsMessageLog::logMessage( tr( "Network request update failed for authentication config" ),
796+
tr( "WFS" ) );
797+
return 1;
798+
}
786799
QNetworkReply* reply = QgsNetworkAccessManager::instance()->get( request );
787800

788801
connect( reply, SIGNAL( finished() ), this, SLOT( networkRequestFinished() ) );
@@ -1366,6 +1379,7 @@ bool QgsWFSProvider::sendTransactionDocument( const QDomDocument& doc, QDomDocum
13661379
QUrl typeDetectionUri( dataSourceUri() );
13671380
typeDetectionUri.removeQueryItem( "username" );
13681381
typeDetectionUri.removeQueryItem( "password" );
1382+
typeDetectionUri.removeQueryItem( "authcfg" );
13691383
typeDetectionUri.removeQueryItem( "REQUEST" );
13701384
typeDetectionUri.removeQueryItem( "TYPENAME" );
13711385
typeDetectionUri.removeQueryItem( "BBOX" );
@@ -1377,7 +1391,13 @@ bool QgsWFSProvider::sendTransactionDocument( const QDomDocument& doc, QDomDocum
13771391
QString serverUrl = typeDetectionUri.toString();
13781392

13791393
QNetworkRequest request( serverUrl );
1380-
mAuth.setAuthorization( request );
1394+
if ( !mAuth.setAuthorization( request ) )
1395+
{
1396+
QgsMessageLog::logMessage( tr( "Network request update failed for authentication config" ),
1397+
tr( "WFS" ) );
1398+
return false;
1399+
}
1400+
13811401
request.setHeader( QNetworkRequest::ContentTypeHeader, "text/xml" );
13821402
QNetworkReply* reply = QgsNetworkAccessManager::instance()->post( request, doc.toByteArray( -1 ) );
13831403

@@ -1507,8 +1527,15 @@ void QgsWFSProvider::getLayerCapabilities()
15071527
QUrl getCapabilitiesUrl( uri );
15081528
getCapabilitiesUrl.removeQueryItem( "username" );
15091529
getCapabilitiesUrl.removeQueryItem( "password" );
1530+
getCapabilitiesUrl.removeQueryItem( "authcfg" );
15101531
QNetworkRequest request( getCapabilitiesUrl.toString() );
1511-
mAuth.setAuthorization( request );
1532+
if ( !mAuth.setAuthorization( request ) )
1533+
{
1534+
mCapabilities = 0;
1535+
QgsMessageLog::logMessage( tr( "Network request update failed for authentication config" ),
1536+
tr( "WFS" ) );
1537+
return;
1538+
}
15121539
QNetworkReply* reply = QgsNetworkAccessManager::instance()->get( request );
15131540

15141541
connect( reply, SIGNAL( finished() ), this, SLOT( networkRequestFinished() ) );

‎src/providers/wfs/qgswfsprovider.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <QDomElement>
2222
#include "qgis.h"
23+
#include "qgsauthmanager.h"
2324
#include "qgsrectangle.h"
2425
#include "qgscoordinatereferencesystem.h"
2526
#include "qgsvectordataprovider.h"
@@ -35,22 +36,34 @@ class QgsSpatialIndex;
3536
// TODO: merge with QgsWmsAuthorization?
3637
struct QgsWFSAuthorization
3738
{
38-
QgsWFSAuthorization( const QString& userName = QString(), const QString& password = QString() ) : mUserName( userName ), mPassword( password ) {}
39+
QgsWFSAuthorization( const QString& userName = QString(), const QString& password = QString(), const QString& authcfg = QString() )
40+
: mUserName( userName )
41+
, mPassword( password )
42+
, mAuthCfg( authcfg )
43+
{}
3944

4045
//! set authorization header
41-
void setAuthorization( QNetworkRequest &request ) const
46+
bool setAuthorization( QNetworkRequest &request ) const
4247
{
43-
if ( !mUserName.isNull() || !mPassword.isNull() )
48+
if ( !mAuthCfg.isEmpty() )
49+
{
50+
return QgsAuthManager::instance()->updateNetworkRequest( request, mAuthCfg );
51+
}
52+
else if ( !mUserName.isNull() || !mPassword.isNull() )
4453
{
4554
request.setRawHeader( "Authorization", "Basic " + QString( "%1:%2" ).arg( mUserName ).arg( mPassword ).toAscii().toBase64() );
4655
}
56+
return true;
4757
}
4858

4959
//! Username for basic http authentication
5060
QString mUserName;
5161

5262
//! Password for basic http authentication
5363
QString mPassword;
64+
65+
//! Authentication configuration ID
66+
QString mAuthCfg;
5467
};
5568

5669
/** A provider reading features from a WFS server*/

‎src/providers/wms/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,19 @@ SET (WMS_MOC_HDRS
2424

2525
QT4_WRAP_CPP (WMS_MOC_SRCS ${WMS_MOC_HDRS})
2626

27-
INCLUDE_DIRECTORIES( . ../../core ../../core/geometry ../../core/raster ../../gui
27+
INCLUDE_DIRECTORIES(
28+
.
29+
../../core
30+
../../core/auth
31+
../../core/geometry
32+
../../core/raster
33+
../../gui
34+
../../gui/auth
2835
${CMAKE_CURRENT_BINARY_DIR}/../../ui
2936
${GDAL_INCLUDE_DIR}
3037
${GEOS_INCLUDE_DIR}
3138
${QT_QTSCRIPT_INCLUDE_DIR}
39+
${QCA_INCLUDE_DIR}
3240
)
3341

3442
ADD_LIBRARY(wmsprovider MODULE ${WMS_SRCS} ${WMS_MOC_SRCS})

‎src/providers/wms/qgswmscapabilities.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ bool QgsWmsSettings::parseUri( QString uriString )
4444
mAuth.mPassword = uri.param( "password" );
4545
QgsDebugMsg( "set password to " + mAuth.mPassword );
4646

47+
if ( uri.hasParam( "authcfg" ) )
48+
{
49+
mAuth.mAuthCfg = uri.param( "authcfg" );
50+
}
51+
QgsDebugMsg( "set authcfg to " + mAuth.mAuthCfg );
52+
4753
mAuth.mReferer = uri.param( "referer" );
4854
QgsDebugMsg( "set referer to " + mAuth.mReferer );
4955

@@ -1911,7 +1917,12 @@ bool QgsWmsCapabilitiesDownload::downloadCapabilities()
19111917
mError.clear();
19121918

19131919
QNetworkRequest request( url );
1914-
mAuth.setAuthorization( request );
1920+
if ( !mAuth.setAuthorization( request ) )
1921+
{
1922+
mError = tr( "Download of capabilities failed: network request update failed for authentication config" );
1923+
QgsMessageLog::logMessage( mError, tr( "WMS" ) );
1924+
return false;
1925+
}
19151926
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork );
19161927
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
19171928

@@ -1995,7 +2006,14 @@ void QgsWmsCapabilitiesDownload::capabilitiesReplyFinished()
19952006
else
19962007
{
19972008
QNetworkRequest request( toUrl );
1998-
mAuth.setAuthorization( request );
2009+
if ( !mAuth.setAuthorization( request ) )
2010+
{
2011+
mHttpCapabilitiesResponse.clear();
2012+
mError = tr( "Download of capabilities failed: network request update failed for authentication config" );
2013+
QgsMessageLog::logMessage( mError, tr( "WMS" ) );
2014+
emit downloadFinished();
2015+
return;
2016+
}
19992017
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork );
20002018
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
20012019

‎src/providers/wms/qgswmscapabilities.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <QStringList>
88
#include <QVector>
99

10+
#include "qgsauthmanager.h"
1011
#include "qgsraster.h"
1112
#include "qgsrectangle.h"
1213

@@ -434,12 +435,16 @@ struct QgsWmsParserSettings
434435

435436
struct QgsWmsAuthorization
436437
{
437-
QgsWmsAuthorization( const QString& userName = QString(), const QString& password = QString(), const QString& referer = QString() )
438-
: mUserName( userName ), mPassword( password ), mReferer( referer ) {}
438+
QgsWmsAuthorization( const QString& userName = QString(), const QString& password = QString(), const QString& referer = QString(), const QString& authcfg = QString() )
439+
: mUserName( userName ), mPassword( password ), mReferer( referer ), mAuthCfg( authcfg ) {}
439440

440-
void setAuthorization( QNetworkRequest &request ) const
441+
bool setAuthorization( QNetworkRequest &request ) const
441442
{
442-
if ( !mUserName.isNull() || !mPassword.isNull() )
443+
if ( !mAuthCfg.isEmpty() )
444+
{
445+
return QgsAuthManager::instance()->updateNetworkRequest( request, mAuthCfg );
446+
}
447+
else if ( !mUserName.isNull() || !mPassword.isNull() )
443448
{
444449
request.setRawHeader( "Authorization", "Basic " + QString( "%1:%2" ).arg( mUserName ).arg( mPassword ).toAscii().toBase64() );
445450
}
@@ -448,6 +453,7 @@ struct QgsWmsAuthorization
448453
{
449454
request.setRawHeader( "Referer", QString( "%1" ).arg( mReferer ).toAscii() );
450455
}
456+
return true;
451457
}
452458

453459
//! Username for basic http authentication
@@ -459,7 +465,8 @@ struct QgsWmsAuthorization
459465
//! Referer for http requests
460466
QString mReferer;
461467

462-
468+
//! Authentication configuration ID
469+
QString mAuthCfg;
463470
};
464471

465472

‎src/providers/wms/qgswmsconnection.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ QgsWMSConnection::QgsWMSConnection( QString theConnName ) :
5959
mUri.setParam( "password", password );
6060
}
6161

62+
QString authcfg = settings.value( credentialsKey + "/authcfg" ).toString();
63+
if ( !authcfg.isEmpty() )
64+
{
65+
mUri.setParam( "authcfg", authcfg );
66+
}
67+
6268
QString referer = settings.value( key + "/referer" ).toString();
6369
if ( !referer.isEmpty() )
6470
{

‎src/ui/qgsnewhttpconnectionbase.ui

Lines changed: 126 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>475</width>
10-
<height>463</height>
9+
<width>526</width>
10+
<height>721</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -27,71 +27,130 @@
2727
</property>
2828
</widget>
2929
</item>
30-
<item row="0" column="0">
30+
<item row="1" column="0">
3131
<widget class="QGroupBox" name="mGroupBox">
3232
<property name="title">
3333
<string>Connection details</string>
3434
</property>
3535
<layout class="QGridLayout">
36-
<item row="8" column="0">
37-
<widget class="QLabel" name="lblDpiMode">
38-
<property name="text">
39-
<string>DPI-Mode</string>
40-
</property>
41-
<property name="buddy">
42-
<cstring>cmbDpiMode</cstring>
43-
</property>
44-
</widget>
45-
</item>
46-
<item row="1" column="0">
47-
<widget class="QLabel" name="TextLabel1">
48-
<property name="text">
49-
<string>URL</string>
50-
</property>
51-
<property name="margin">
52-
<number>5</number>
53-
</property>
54-
<property name="buddy">
55-
<cstring>txtUrl</cstring>
56-
</property>
57-
</widget>
58-
</item>
59-
<item row="4" column="0" colspan="3">
60-
<widget class="QLabel" name="label">
36+
<item row="4" column="0" colspan="2">
37+
<widget class="QTabWidget" name="tabAuth">
6138
<property name="sizePolicy">
62-
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
39+
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
6340
<horstretch>0</horstretch>
6441
<verstretch>0</verstretch>
6542
</sizepolicy>
6643
</property>
67-
<property name="text">
68-
<string>If the service requires basic authentication, enter a user name and optional password</string>
44+
<property name="currentIndex">
45+
<number>0</number>
6946
</property>
70-
<property name="textFormat">
71-
<enum>Qt::PlainText</enum>
47+
<widget class="QWidget" name="tab">
48+
<attribute name="title">
49+
<string>Authentication</string>
50+
</attribute>
51+
<layout class="QGridLayout" name="gridLayout_3">
52+
<item row="1" column="0">
53+
<widget class="QLabel" name="label_2">
54+
<property name="text">
55+
<string>&amp;User name</string>
56+
</property>
57+
<property name="buddy">
58+
<cstring>txtUserName</cstring>
59+
</property>
60+
</widget>
61+
</item>
62+
<item row="1" column="1">
63+
<widget class="QLineEdit" name="txtUserName"/>
64+
</item>
65+
<item row="0" column="0" colspan="2">
66+
<widget class="QLabel" name="label">
67+
<property name="sizePolicy">
68+
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
69+
<horstretch>0</horstretch>
70+
<verstretch>0</verstretch>
71+
</sizepolicy>
72+
</property>
73+
<property name="text">
74+
<string>If the service requires basic authentication, enter a user name and optional password</string>
75+
</property>
76+
<property name="textFormat">
77+
<enum>Qt::PlainText</enum>
78+
</property>
79+
<property name="wordWrap">
80+
<bool>true</bool>
81+
</property>
82+
</widget>
83+
</item>
84+
<item row="2" column="0">
85+
<widget class="QLabel" name="label_3">
86+
<property name="text">
87+
<string>Password</string>
88+
</property>
89+
<property name="buddy">
90+
<cstring>txtPassword</cstring>
91+
</property>
92+
</widget>
93+
</item>
94+
<item row="2" column="1">
95+
<widget class="QLineEdit" name="txtPassword">
96+
<property name="echoMode">
97+
<enum>QLineEdit::Password</enum>
98+
</property>
99+
</widget>
100+
</item>
101+
<item row="3" column="1">
102+
<spacer name="verticalSpacer">
103+
<property name="orientation">
104+
<enum>Qt::Vertical</enum>
105+
</property>
106+
<property name="sizeHint" stdset="0">
107+
<size>
108+
<width>0</width>
109+
<height>0</height>
110+
</size>
111+
</property>
112+
</spacer>
113+
</item>
114+
</layout>
115+
</widget>
116+
</widget>
117+
</item>
118+
<item row="0" column="1">
119+
<widget class="QLineEdit" name="txtName">
120+
<property name="minimumSize">
121+
<size>
122+
<width>0</width>
123+
<height>0</height>
124+
</size>
72125
</property>
73-
<property name="wordWrap">
126+
<property name="toolTip">
127+
<string>Name of the new connection</string>
128+
</property>
129+
<property name="frame">
74130
<bool>true</bool>
75131
</property>
76132
</widget>
77133
</item>
78-
<item row="6" column="0">
79-
<widget class="QLabel" name="label_3">
134+
<item row="7" column="0">
135+
<widget class="QLabel" name="lblDpiMode">
80136
<property name="text">
81-
<string>Password</string>
137+
<string>DPI-Mode</string>
82138
</property>
83139
<property name="buddy">
84-
<cstring>txtPassword</cstring>
140+
<cstring>cmbDpiMode</cstring>
85141
</property>
86142
</widget>
87143
</item>
88-
<item row="5" column="0">
89-
<widget class="QLabel" name="label_2">
144+
<item row="1" column="0">
145+
<widget class="QLabel" name="TextLabel1">
90146
<property name="text">
91-
<string>&amp;User name</string>
147+
<string>URL</string>
148+
</property>
149+
<property name="margin">
150+
<number>5</number>
92151
</property>
93152
<property name="buddy">
94-
<cstring>txtUserName</cstring>
153+
<cstring>txtUrl</cstring>
95154
</property>
96155
</widget>
97156
</item>
@@ -111,90 +170,64 @@
111170
</property>
112171
</widget>
113172
</item>
114-
<item row="0" column="1">
115-
<widget class="QLineEdit" name="txtName">
116-
<property name="minimumSize">
117-
<size>
118-
<width>0</width>
119-
<height>0</height>
120-
</size>
121-
</property>
122-
<property name="toolTip">
123-
<string>Name of the new connection</string>
124-
</property>
125-
<property name="frame">
126-
<bool>true</bool>
127-
</property>
128-
</widget>
129-
</item>
130173
<item row="1" column="1">
131174
<widget class="QLineEdit" name="txtUrl">
132175
<property name="toolTip">
133176
<string>HTTP address of the Web Map Server</string>
134177
</property>
135178
</widget>
136179
</item>
137-
<item row="5" column="1">
138-
<widget class="QLineEdit" name="txtUserName"/>
139-
</item>
140-
<item row="6" column="1">
141-
<widget class="QLineEdit" name="txtPassword">
142-
<property name="echoMode">
143-
<enum>QLineEdit::Password</enum>
144-
</property>
145-
</widget>
180+
<item row="7" column="1">
181+
<widget class="QComboBox" name="cmbDpiMode"/>
146182
</item>
147-
<item row="13" column="0" colspan="2">
148-
<widget class="QCheckBox" name="cbxIgnoreGetFeatureInfoURI">
183+
<item row="6" column="0">
184+
<widget class="QLabel" name="lblReferer">
149185
<property name="text">
150-
<string>Ignore GetFeatureInfo URI reported in capabilities</string>
186+
<string>Referer</string>
187+
</property>
188+
<property name="buddy">
189+
<cstring>txtReferer</cstring>
151190
</property>
152191
</widget>
153192
</item>
154-
<item row="12" column="0" colspan="2">
155-
<widget class="QCheckBox" name="cbxIgnoreGetMapURI">
193+
<item row="6" column="1">
194+
<widget class="QLineEdit" name="txtReferer"/>
195+
</item>
196+
<item row="15" column="0" colspan="2">
197+
<widget class="QCheckBox" name="cbxSmoothPixmapTransform">
156198
<property name="text">
157-
<string>Ignore GetMap/GetTile URI reported in capabilities</string>
199+
<string>Smooth pixmap transform</string>
158200
</property>
159201
</widget>
160202
</item>
161203
<item row="14" column="0" colspan="2">
162-
<widget class="QCheckBox" name="cbxIgnoreAxisOrientation">
204+
<widget class="QCheckBox" name="cbxInvertAxisOrientation">
163205
<property name="text">
164-
<string>Ignore axis orientation (WMS 1.3/WMTS)</string>
206+
<string>Invert axis orientation</string>
165207
</property>
166208
</widget>
167209
</item>
168-
<item row="15" column="0" colspan="2">
169-
<widget class="QCheckBox" name="cbxInvertAxisOrientation">
210+
<item row="13" column="0" colspan="2">
211+
<widget class="QCheckBox" name="cbxIgnoreAxisOrientation">
170212
<property name="text">
171-
<string>Invert axis orientation</string>
213+
<string>Ignore axis orientation (WMS 1.3/WMTS)</string>
172214
</property>
173215
</widget>
174216
</item>
175-
<item row="16" column="0" colspan="2">
176-
<widget class="QCheckBox" name="cbxSmoothPixmapTransform">
217+
<item row="11" column="0" colspan="2">
218+
<widget class="QCheckBox" name="cbxIgnoreGetMapURI">
177219
<property name="text">
178-
<string>Smooth pixmap transform</string>
220+
<string>Ignore GetMap/GetTile URI reported in capabilities</string>
179221
</property>
180222
</widget>
181223
</item>
182-
<item row="7" column="1">
183-
<widget class="QLineEdit" name="txtReferer"/>
184-
</item>
185-
<item row="7" column="0">
186-
<widget class="QLabel" name="lblReferer">
224+
<item row="12" column="0" colspan="2">
225+
<widget class="QCheckBox" name="cbxIgnoreGetFeatureInfoURI">
187226
<property name="text">
188-
<string>Referer</string>
189-
</property>
190-
<property name="buddy">
191-
<cstring>txtReferer</cstring>
227+
<string>Ignore GetFeatureInfo URI reported in capabilities</string>
192228
</property>
193229
</widget>
194230
</item>
195-
<item row="8" column="1">
196-
<widget class="QComboBox" name="cmbDpiMode"/>
197-
</item>
198231
</layout>
199232
</widget>
200233
</item>

0 commit comments

Comments
 (0)
Please sign in to comment.