Skip to content

Commit de360f2

Browse files
authoredOct 14, 2016
Merge pull request #3577 from dakcarto/master-ows-fixes
2 parents d30a8c1 + a629dee commit de360f2

12 files changed

+184
-21
lines changed
 

‎src/core/qgsgml.cpp‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ int QgsGml::getFeatures( const QString& uri, QgsWkbTypes::Type* wkbType, QgsRect
8383
}
8484
QNetworkReply* reply = QgsNetworkAccessManager::instance()->get( request );
8585

86+
if ( !authcfg.isEmpty() )
87+
{
88+
if ( !QgsAuthManager::instance()->updateNetworkReply( reply, authcfg ) )
89+
{
90+
reply->deleteLater();
91+
QgsMessageLog::logMessage(
92+
tr( "GML Getfeature network reply update failed for authcfg %1" ).arg( authcfg ),
93+
tr( "Network" ),
94+
QgsMessageLog::CRITICAL
95+
);
96+
return 1;
97+
}
98+
}
99+
86100
connect( reply, SIGNAL( finished() ), this, SLOT( setFinished() ) );
87101
connect( reply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( handleProgressEvent( qint64, qint64 ) ) );
88102

‎src/providers/wcs/qgswcscapabilities.cpp‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ bool QgsWcsCapabilities::sendRequest( QString const & url )
157157

158158
QgsDebugMsg( QString( "getcapabilities: %1" ).arg( url ) );
159159
mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );
160+
if ( !setAuthorizationReply( mCapabilitiesReply ) )
161+
{
162+
mCapabilitiesReply->deleteLater();
163+
mCapabilitiesReply = nullptr;
164+
mError = tr( "Download of capabilities failed: network reply update failed for authentication config" );
165+
QgsMessageLog::logMessage( mError, tr( "WCS" ) );
166+
return false;
167+
}
160168

161169
connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) );
162170
connect( mCapabilitiesReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( capabilitiesReplyProgress( qint64, qint64 ) ) );
@@ -367,6 +375,15 @@ void QgsWcsCapabilities::capabilitiesReplyFinished()
367375
mCapabilitiesReply->deleteLater();
368376
QgsDebugMsg( QString( "redirected getcapabilities: %1" ).arg( redirect.toString() ) );
369377
mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );
378+
if ( !setAuthorizationReply( mCapabilitiesReply ) )
379+
{
380+
mCapabilitiesResponse.clear();
381+
mCapabilitiesReply->deleteLater();
382+
mCapabilitiesReply = nullptr;
383+
mError = tr( "Download of capabilities failed: network reply update failed for authentication config" );
384+
QgsMessageLog::logMessage( mError, tr( "WCS" ) );
385+
return;
386+
}
370387

371388
connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) );
372389
connect( mCapabilitiesReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( capabilitiesReplyProgress( qint64, qint64 ) ) );
@@ -393,6 +410,15 @@ void QgsWcsCapabilities::capabilitiesReplyFinished()
393410
mCapabilitiesReply->deleteLater();
394411

395412
mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );
413+
if ( !setAuthorizationReply( mCapabilitiesReply ) )
414+
{
415+
mCapabilitiesResponse.clear();
416+
mCapabilitiesReply->deleteLater();
417+
mCapabilitiesReply = nullptr;
418+
mError = tr( "Download of capabilities failed: network reply update failed for authentication config" );
419+
QgsMessageLog::logMessage( mError, tr( "WCS" ) );
420+
return;
421+
}
396422
connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) );
397423
connect( mCapabilitiesReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( capabilitiesReplyProgress( qint64, qint64 ) ) );
398424
return;
@@ -1178,6 +1204,15 @@ bool QgsWcsCapabilities::setAuthorization( QNetworkRequest &request ) const
11781204
return true;
11791205
}
11801206

1207+
bool QgsWcsCapabilities::setAuthorizationReply( QNetworkReply *reply ) const
1208+
{
1209+
if ( mUri.hasParam( "authcfg" ) && !mUri.param( "authcfg" ).isEmpty() )
1210+
{
1211+
return QgsAuthManager::instance()->updateNetworkReply( reply, mUri.param( "authcfg" ) );
1212+
}
1213+
return true;
1214+
}
1215+
11811216
void QgsWcsCapabilities::showMessageBox( const QString& title, const QString& text )
11821217
{
11831218
QgsMessageOutput *message = QgsMessageOutput::createMessageOutput();

‎src/providers/wcs/qgswcscapabilities.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ class QgsWcsCapabilities : public QObject
162162
//! set authorization header
163163
bool setAuthorization( QNetworkRequest &request ) const;
164164

165+
//! set authorization reply
166+
bool setAuthorizationReply( QNetworkReply * reply ) const;
167+
165168
QString version() const { return mCapabilities.version; }
166169

167170
/**

‎src/providers/wcs/qgswcsprovider.cpp‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,6 +1663,15 @@ QgsWcsDownloadHandler::QgsWcsDownloadHandler( const QUrl& url, QgsWcsAuthorizati
16631663
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, cacheLoadControl );
16641664

16651665
mCacheReply = QgsNetworkAccessManager::instance()->get( request );
1666+
if ( !mAuth.setAuthorizationReply( mCacheReply ) )
1667+
{
1668+
mCacheReply->deleteLater();
1669+
mCacheReply = nullptr;
1670+
QgsMessageLog::logMessage( tr( "Network reply update failed for authentication config" ),
1671+
tr( "WCS" ) );
1672+
finish();
1673+
return;
1674+
}
16661675
connect( mCacheReply, SIGNAL( finished() ), this, SLOT( cacheReplyFinished() ) );
16671676
connect( mCacheReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( cacheReplyProgress( qint64, qint64 ) ) );
16681677

@@ -1701,6 +1710,15 @@ void QgsWcsDownloadHandler::cacheReplyFinished()
17011710
return;
17021711
}
17031712
mCacheReply = QgsNetworkAccessManager::instance()->get( request );
1713+
if ( !mAuth.setAuthorizationReply( mCacheReply ) )
1714+
{
1715+
mCacheReply->deleteLater();
1716+
mCacheReply = nullptr;
1717+
QgsMessageLog::logMessage( tr( "Network reply update failed for authentication config" ),
1718+
tr( "WCS" ) );
1719+
finish();
1720+
return;
1721+
}
17041722
connect( mCacheReply, SIGNAL( finished() ), this, SLOT( cacheReplyFinished() ) );
17051723
connect( mCacheReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( cacheReplyProgress( qint64, qint64 ) ) );
17061724

@@ -1868,6 +1886,15 @@ void QgsWcsDownloadHandler::cacheReplyFinished()
18681886
mCacheReply->deleteLater();
18691887

18701888
mCacheReply = QgsNetworkAccessManager::instance()->get( request );
1889+
if ( !mAuth.setAuthorizationReply( mCacheReply ) )
1890+
{
1891+
mCacheReply->deleteLater();
1892+
mCacheReply = nullptr;
1893+
QgsMessageLog::logMessage( tr( "Network reply update failed for authentication config" ),
1894+
tr( "WCS" ) );
1895+
finish();
1896+
return;
1897+
}
18711898
connect( mCacheReply, SIGNAL( finished() ), this, SLOT( cacheReplyFinished() ), Qt::DirectConnection );
18721899
connect( mCacheReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( cacheReplyProgress( qint64, qint64 ) ), Qt::DirectConnection );
18731900

‎src/providers/wcs/qgswcsprovider.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ struct QgsWcsAuthorization
7272
return true;
7373
}
7474

75+
//! set authorization reply
76+
bool setAuthorizationReply( QNetworkReply * reply ) const
77+
{
78+
if ( !mAuthCfg.isEmpty() )
79+
{
80+
return QgsAuthManager::instance()->updateNetworkReply( reply, mAuthCfg );
81+
}
82+
return true;
83+
}
84+
7585
//! Username for basic http authentication
7686
QString mUserName;
7787

‎src/providers/wfs/qgswfsdatasourceuri.cpp‎

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,19 @@ QgsWFSDataSourceURI::QgsWFSDataSourceURI( const QString& uri )
4141
QString typeName = url.queryItemValue( QgsWFSConstants::URI_PARAM_TYPENAME );
4242
QString version = url.queryItemValue( QgsWFSConstants::URI_PARAM_VERSION );
4343
QString filter = url.queryItemValue( QgsWFSConstants::URI_PARAM_FILTER );
44-
mAuth.mUserName = url.queryItemValue( QgsWFSConstants::URI_PARAM_USERNAME );
45-
// In QgsDataSourceURI, the "username" param is named "user", check it
46-
if ( mAuth.mUserName.isEmpty() )
44+
mAuth.mAuthCfg = url.queryItemValue( QgsWFSConstants::URI_PARAM_AUTHCFG );
45+
// NOTE: A defined authcfg overrides any older username/password auth
46+
// Only check for older auth if it is undefined
47+
if ( mAuth.mAuthCfg.isEmpty() )
4748
{
48-
mAuth.mUserName = url.queryItemValue( QgsWFSConstants::URI_PARAM_USER );
49+
mAuth.mUserName = url.queryItemValue( QgsWFSConstants::URI_PARAM_USERNAME );
50+
// In QgsDataSourceURI, the "username" param is named "user", check it
51+
if ( mAuth.mUserName.isEmpty() )
52+
{
53+
mAuth.mUserName = url.queryItemValue( QgsWFSConstants::URI_PARAM_USER );
54+
}
55+
mAuth.mPassword = url.queryItemValue( QgsWFSConstants::URI_PARAM_PASSWORD );
4956
}
50-
mAuth.mPassword = url.queryItemValue( QgsWFSConstants::URI_PARAM_PASSWORD );
51-
mAuth.mAuthCfg = url.queryItemValue( QgsWFSConstants::URI_PARAM_AUTHCFG );
5257

5358
// Now remove all stuff that is not the core URL
5459
url.removeQueryItem( "SERVICE" );
@@ -90,19 +95,24 @@ QgsWFSDataSourceURI::QgsWFSDataSourceURI( const QString& uri )
9095
const QString QgsWFSDataSourceURI::uri( bool expandAuthConfig ) const
9196
{
9297
QgsDataSourceUri theURI( mURI );
93-
// Add auth params back into the uri
98+
// Add authcfg param back into the uri (must be non-empty value)
9499
if ( ! mAuth.mAuthCfg.isEmpty() )
95100
{
96101
theURI.setAuthConfigId( mAuth.mAuthCfg );
97102
}
98-
if ( ! mAuth.mUserName.isEmpty() )
99-
{
100-
theURI.setUsername( mAuth.mUserName );
101-
}
102-
if ( ! mAuth.mPassword.isEmpty() )
103+
else
103104
{
104-
theURI.setPassword( mAuth.mPassword );
105+
// Add any older username/password auth params back in (allow empty values)
106+
if ( ! mAuth.mUserName.isNull() )
107+
{
108+
theURI.setUsername( mAuth.mUserName );
109+
}
110+
if ( ! mAuth.mPassword.isNull() )
111+
{
112+
theURI.setPassword( mAuth.mPassword );
113+
}
105114
}
115+
// NOTE: avoid expanding authcfg here; it is handled during network access
106116
return theURI.uri( expandAuthConfig );
107117
}
108118

‎src/providers/wfs/qgswfsdatasourceuri.h‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,30 @@ struct QgsWFSAuthorization
3232
, mAuthCfg( authcfg )
3333
{}
3434

35-
//! set authorization header
35+
//! update authorization for request
3636
bool setAuthorization( QNetworkRequest &request ) const
3737
{
38-
if ( !mAuthCfg.isEmpty() )
38+
if ( !mAuthCfg.isEmpty() ) // must be non-empty value
3939
{
4040
return QgsAuthManager::instance()->updateNetworkRequest( request, mAuthCfg );
4141
}
42-
else if ( !mUserName.isNull() || !mPassword.isNull() )
42+
else if ( !mUserName.isNull() || !mPassword.isNull() ) // allow empty values
4343
{
4444
request.setRawHeader( "Authorization", "Basic " + QString( "%1:%2" ).arg( mUserName, mPassword ).toLatin1().toBase64() );
4545
}
4646
return true;
4747
}
4848

49+
//! update authorization for reply
50+
bool setAuthorizationReply( QNetworkReply *reply ) const
51+
{
52+
if ( !mAuthCfg.isEmpty() )
53+
{
54+
return QgsAuthManager::instance()->updateNetworkReply( reply, mAuthCfg );
55+
}
56+
return true;
57+
}
58+
4959
//! Username for basic http authentication
5060
QString mUserName;
5161

@@ -65,8 +75,8 @@ class QgsWFSDataSourceURI
6575

6676
explicit QgsWFSDataSourceURI( const QString& uri );
6777

68-
/** Return the URI */
69-
const QString uri( bool expandAuthConfig = true ) const;
78+
/** Return the URI, avoiding expansion of authentication configuration, which is handled during network access */
79+
const QString uri( bool expandAuthConfig = false ) const;
7080

7181
/** Return base URL (with SERVICE=WFS parameter if bIncludeServiceWFS=true) */
7282
QUrl baseURL( bool bIncludeServiceWFS = true ) const;

‎src/providers/wfs/qgswfsprovider.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ bool QgsWFSProvider::describeFeatureType( QString& geometryAttribute, QgsFields&
11041104
{
11051105
fields.clear();
11061106

1107-
QgsWFSDescribeFeatureType describeFeatureType( mShared->mURI.uri( false ) );
1107+
QgsWFSDescribeFeatureType describeFeatureType( mShared->mURI.uri() );
11081108
if ( !describeFeatureType.requestFeatureType( mShared->mWFSVersion,
11091109
mShared->mURI.typeName() ) )
11101110
{
@@ -1340,7 +1340,7 @@ bool QgsWFSProvider::sendTransactionDocument( const QDomDocument& doc, QDomDocum
13401340
return false;
13411341
}
13421342

1343-
QgsWFSTransactionRequest request( mShared->mURI.uri( false ) );
1343+
QgsWFSTransactionRequest request( mShared->mURI.uri() );
13441344
return request.send( doc, serverResponse );
13451345
}
13461346

@@ -1443,7 +1443,7 @@ bool QgsWFSProvider::getCapabilities()
14431443

14441444
if ( mShared->mCaps.version.isEmpty() )
14451445
{
1446-
QgsWfsCapabilities getCapabilities( mShared->mURI.uri( false ) );
1446+
QgsWfsCapabilities getCapabilities( mShared->mURI.uri() );
14471447
const bool synchronous = true;
14481448
const bool forceRefresh = false;
14491449
if ( !getCapabilities.requestCapabilities( synchronous, forceRefresh ) )

‎src/providers/wfs/qgswfsrequest.cpp‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ bool QgsWfsRequest::sendGET( const QUrl& url, bool synchronous, bool forceRefres
116116
}
117117

118118
mReply = QgsNetworkAccessManager::instance()->get( request );
119+
if ( !mUri.auth().setAuthorizationReply( mReply ) )
120+
{
121+
mErrorCode = QgsWfsRequest::NetworkError;
122+
mErrorMessage = errorMessageFailedAuth();
123+
QgsMessageLog::logMessage( mErrorMessage, tr( "WFS" ) );
124+
return false;
125+
}
119126
connect( mReply, SIGNAL( finished() ), this, SLOT( replyFinished() ) );
120127
connect( mReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( replyProgress( qint64, qint64 ) ) );
121128

@@ -160,6 +167,13 @@ bool QgsWfsRequest::sendPOST( const QUrl& url, const QString& contentTypeHeader,
160167
request.setHeader( QNetworkRequest::ContentTypeHeader, contentTypeHeader );
161168

162169
mReply = QgsNetworkAccessManager::instance()->post( request, data );
170+
if ( !mUri.auth().setAuthorizationReply( mReply ) )
171+
{
172+
mErrorCode = QgsWfsRequest::NetworkError;
173+
mErrorMessage = errorMessageFailedAuth();
174+
QgsMessageLog::logMessage( mErrorMessage, tr( "WFS" ) );
175+
return false;
176+
}
163177
connect( mReply, SIGNAL( finished() ), this, SLOT( replyFinished() ) );
164178
connect( mReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( replyProgress( qint64, qint64 ) ) );
165179

@@ -243,6 +257,15 @@ void QgsWfsRequest::replyFinished()
243257

244258
QgsDebugMsg( QString( "redirected: %1 forceRefresh=%2" ).arg( redirect.toString() ).arg( mForceRefresh ) );
245259
mReply = QgsNetworkAccessManager::instance()->get( request );
260+
if ( !mUri.auth().setAuthorizationReply( mReply ) )
261+
{
262+
mResponse.clear();
263+
mErrorMessage = errorMessageFailedAuth();
264+
mErrorCode = QgsWfsRequest::NetworkError;
265+
QgsMessageLog::logMessage( mErrorMessage, tr( "WFS" ) );
266+
emit downloadFinished();
267+
return;
268+
}
246269
connect( mReply, SIGNAL( finished() ), this, SLOT( replyFinished() ) );
247270
connect( mReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( replyProgress( qint64, qint64 ) ) );
248271
return;

‎src/providers/wms/qgswmscapabilities.cpp‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,6 +1955,14 @@ bool QgsWmsCapabilitiesDownload::downloadCapabilities()
19551955
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
19561956

19571957
mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );
1958+
if ( !mAuth.setAuthorizationReply( mCapabilitiesReply ) )
1959+
{
1960+
mCapabilitiesReply->deleteLater();
1961+
mCapabilitiesReply = nullptr;
1962+
mError = tr( "Download of capabilities failed: network reply update failed for authentication config" );
1963+
QgsMessageLog::logMessage( mError, tr( "WMS" ) );
1964+
return false;
1965+
}
19581966
connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ), Qt::DirectConnection );
19591967
connect( mCapabilitiesReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( capabilitiesReplyProgress( qint64, qint64 ) ), Qt::DirectConnection );
19601968

@@ -2021,6 +2029,18 @@ void QgsWmsCapabilitiesDownload::capabilitiesReplyFinished()
20212029

20222030
QgsDebugMsg( QString( "redirected getcapabilities: %1 forceRefresh=%2" ).arg( redirect.toString() ).arg( mForceRefresh ) );
20232031
mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );
2032+
2033+
if ( !mAuth.setAuthorizationReply( mCapabilitiesReply ) )
2034+
{
2035+
mHttpCapabilitiesResponse.clear();
2036+
mCapabilitiesReply->deleteLater();
2037+
mCapabilitiesReply = nullptr;
2038+
mError = tr( "Download of capabilities failed: network reply update failed for authentication config" );
2039+
QgsMessageLog::logMessage( mError, tr( "WMS" ) );
2040+
emit downloadFinished();
2041+
return;
2042+
}
2043+
20242044
connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ), Qt::DirectConnection );
20252045
connect( mCapabilitiesReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( capabilitiesReplyProgress( qint64, qint64 ) ), Qt::DirectConnection );
20262046
return;

‎src/providers/wms/qgswmscapabilities.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,15 @@ struct QgsWmsAuthorization
512512
}
513513
return true;
514514
}
515+
//! set authorization reply
516+
bool setAuthorizationReply( QNetworkReply * reply ) const
517+
{
518+
if ( !mAuthCfg.isEmpty() )
519+
{
520+
return QgsAuthManager::instance()->updateNetworkReply( reply, mAuthCfg );
521+
}
522+
return true;
523+
}
515524

516525
//! Username for basic http authentication
517526
QString mUserName;

‎src/providers/wms/qgswmsprovider.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3110,6 +3110,7 @@ void QgsWmsProvider::identifyReplyFinished()
31103110

31113111
QgsDebugMsg( QString( "redirected getfeatureinfo: %1" ).arg( redirect.toString() ) );
31123112
mIdentifyReply = QgsNetworkAccessManager::instance()->get( QNetworkRequest( redirect.toUrl() ) );
3113+
mSettings.authorization().setAuthorizationReply( mIdentifyReply );
31133114
mIdentifyReply->setProperty( "eventLoop", QVariant::fromValue( qobject_cast<QObject *>( loop ) ) );
31143115
connect( mIdentifyReply, SIGNAL( finished() ), this, SLOT( identifyReplyFinished() ) );
31153116
return;
@@ -4100,6 +4101,7 @@ QgsWmsLegendDownloadHandler::startUrl( const QUrl& url )
41004101
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
41014102

41024103
mReply = mNetworkAccessManager.get( request );
4104+
mSettings.authorization().setAuthorizationReply( mReply );
41034105
connect( mReply, SIGNAL( error( QNetworkReply::NetworkError ) ), this, SLOT( errored( QNetworkReply::NetworkError ) ) );
41044106
connect( mReply, SIGNAL( finished() ), this, SLOT( finished() ) );
41054107
connect( mReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( progressed( qint64, qint64 ) ) );

0 commit comments

Comments
 (0)
Please sign in to comment.