Skip to content

Commit 2d7164f

Browse files
committedOct 12, 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 e3164e9 commit 2d7164f

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
@@ -84,6 +84,20 @@ int QgsGml::getFeatures( const QString& uri, QGis::WkbType* wkbType, QgsRectangl
8484
}
8585
QNetworkReply* reply = QgsNetworkAccessManager::instance()->get( request );
8686

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

‎src/providers/wcs/qgswcscapabilities.cpp

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

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

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

372389
connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) );
373390
connect( mCapabilitiesReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( capabilitiesReplyProgress( qint64, qint64 ) ) );
@@ -394,6 +411,15 @@ void QgsWcsCapabilities::capabilitiesReplyFinished()
394411
mCapabilitiesReply->deleteLater();
395412

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

1208+
bool QgsWcsCapabilities::setAuthorizationReply( QNetworkReply *reply ) const
1209+
{
1210+
if ( mUri.hasParam( "authcfg" ) && !mUri.param( "authcfg" ).isEmpty() )
1211+
{
1212+
return QgsAuthManager::instance()->updateNetworkReply( reply, mUri.param( "authcfg" ) );
1213+
}
1214+
return true;
1215+
}
1216+
11821217
void QgsWcsCapabilities::showMessageBox( const QString& title, const QString& text )
11831218
{
11841219
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
@@ -1686,6 +1686,15 @@ QgsWcsDownloadHandler::QgsWcsDownloadHandler( const QUrl& url, QgsWcsAuthorizati
16861686
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, cacheLoadControl );
16871687

16881688
mCacheReply = QgsNetworkAccessManager::instance()->get( request );
1689+
if ( !mAuth.setAuthorizationReply( mCacheReply ) )
1690+
{
1691+
mCacheReply->deleteLater();
1692+
mCacheReply = nullptr;
1693+
QgsMessageLog::logMessage( tr( "Network reply update failed for authentication config" ),
1694+
tr( "WCS" ) );
1695+
finish();
1696+
return;
1697+
}
16891698
connect( mCacheReply, SIGNAL( finished() ), this, SLOT( cacheReplyFinished() ) );
16901699
connect( mCacheReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( cacheReplyProgress( qint64, qint64 ) ) );
16911700
}
@@ -1724,6 +1733,15 @@ void QgsWcsDownloadHandler::cacheReplyFinished()
17241733
return;
17251734
}
17261735
mCacheReply = QgsNetworkAccessManager::instance()->get( request );
1736+
if ( !mAuth.setAuthorizationReply( mCacheReply ) )
1737+
{
1738+
mCacheReply->deleteLater();
1739+
mCacheReply = nullptr;
1740+
QgsMessageLog::logMessage( tr( "Network reply update failed for authentication config" ),
1741+
tr( "WCS" ) );
1742+
finish();
1743+
return;
1744+
}
17271745
connect( mCacheReply, SIGNAL( finished() ), this, SLOT( cacheReplyFinished() ) );
17281746
connect( mCacheReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( cacheReplyProgress( qint64, qint64 ) ) );
17291747

@@ -1891,6 +1909,15 @@ void QgsWcsDownloadHandler::cacheReplyFinished()
18911909
mCacheReply->deleteLater();
18921910

18931911
mCacheReply = QgsNetworkAccessManager::instance()->get( request );
1912+
if ( !mAuth.setAuthorizationReply( mCacheReply ) )
1913+
{
1914+
mCacheReply->deleteLater();
1915+
mCacheReply = nullptr;
1916+
QgsMessageLog::logMessage( tr( "Network reply update failed for authentication config" ),
1917+
tr( "WCS" ) );
1918+
finish();
1919+
return;
1920+
}
18941921
connect( mCacheReply, SIGNAL( finished() ), this, SLOT( cacheReplyFinished() ), Qt::DirectConnection );
18951922
connect( mCacheReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( cacheReplyProgress( qint64, qint64 ) ), Qt::DirectConnection );
18961923

‎src/providers/wcs/qgswcsprovider.h

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

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

‎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
@@ -1956,6 +1956,14 @@ bool QgsWmsCapabilitiesDownload::downloadCapabilities()
19561956
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
19571957

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

@@ -2022,6 +2030,18 @@ void QgsWmsCapabilitiesDownload::capabilitiesReplyFinished()
20222030

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

31063106
QgsDebugMsg( QString( "redirected getfeatureinfo: %1" ).arg( redirect.toString() ) );
31073107
mIdentifyReply = QgsNetworkAccessManager::instance()->get( QNetworkRequest( redirect.toUrl() ) );
3108+
mSettings.authorization().setAuthorizationReply( mIdentifyReply );
31083109
mIdentifyReply->setProperty( "eventLoop", QVariant::fromValue( qobject_cast<QObject *>( loop ) ) );
31093110
connect( mIdentifyReply, SIGNAL( finished() ), this, SLOT( identifyReplyFinished() ) );
31103111
return;
@@ -4094,6 +4095,7 @@ QgsWmsLegendDownloadHandler::startUrl( const QUrl& url )
40944095
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
40954096

40964097
mReply = mNetworkAccessManager.get( request );
4098+
mSettings.authorization().setAuthorizationReply( mReply );
40974099
connect( mReply, SIGNAL( error( QNetworkReply::NetworkError ) ), this, SLOT( errored( QNetworkReply::NetworkError ) ) );
40984100
connect( mReply, SIGNAL( finished() ), this, SLOT( finished() ) );
40994101
connect( mReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( progressed( qint64, qint64 ) ) );

0 commit comments

Comments
 (0)
Please sign in to comment.