Skip to content

Commit a629dee

Browse files
committedOct 13, 2016
[auth] Reinstate auth system reply expansions for OWS providers
- Apparently this was lost during a git squash of commits for 2.12 PR
1 parent 37b00eb commit a629dee

10 files changed

+154
-1
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.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct QgsWFSAuthorization
3232
, mAuthCfg( authcfg )
3333
{}
3434

35-
//! set authorization header
35+
//! update authorization for request
3636
bool setAuthorization( QNetworkRequest &request ) const
3737
{
3838
if ( !mAuthCfg.isEmpty() ) // must be non-empty value
@@ -46,6 +46,16 @@ struct QgsWFSAuthorization
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

‎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.