Skip to content

Commit

Permalink
[auth] Reinstate auth system reply expansions for OWS providers
Browse files Browse the repository at this point in the history
- Apparently this was lost during a git squash of commits for 2.12 PR
  • Loading branch information
dakcarto committed Oct 12, 2016
1 parent e3164e9 commit 2d7164f
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/core/qgsgml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ int QgsGml::getFeatures( const QString& uri, QGis::WkbType* wkbType, QgsRectangl
}
QNetworkReply* reply = QgsNetworkAccessManager::instance()->get( request );

if ( !authcfg.isEmpty() )
{
if ( !QgsAuthManager::instance()->updateNetworkReply( reply, authcfg ) )
{
reply->deleteLater();
QgsMessageLog::logMessage(
tr( "GML Getfeature network reply update failed for authcfg %1" ).arg( authcfg ),
tr( "Network" ),
QgsMessageLog::CRITICAL
);
return 1;
}
}

connect( reply, SIGNAL( finished() ), this, SLOT( setFinished() ) );
connect( reply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( handleProgressEvent( qint64, qint64 ) ) );

Expand Down
35 changes: 35 additions & 0 deletions src/providers/wcs/qgswcscapabilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ bool QgsWcsCapabilities::sendRequest( QString const & url )

QgsDebugMsg( QString( "getcapabilities: %1" ).arg( url ) );
mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );
if ( !setAuthorizationReply( mCapabilitiesReply ) )
{
mCapabilitiesReply->deleteLater();
mCapabilitiesReply = nullptr;
mError = tr( "Download of capabilities failed: network reply update failed for authentication config" );
QgsMessageLog::logMessage( mError, tr( "WCS" ) );
return false;
}

connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) );
connect( mCapabilitiesReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( capabilitiesReplyProgress( qint64, qint64 ) ) );
Expand Down Expand Up @@ -368,6 +376,15 @@ void QgsWcsCapabilities::capabilitiesReplyFinished()
mCapabilitiesReply->deleteLater();
QgsDebugMsg( QString( "redirected getcapabilities: %1" ).arg( redirect.toString() ) );
mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );
if ( !setAuthorizationReply( mCapabilitiesReply ) )
{
mCapabilitiesResponse.clear();
mCapabilitiesReply->deleteLater();
mCapabilitiesReply = nullptr;
mError = tr( "Download of capabilities failed: network reply update failed for authentication config" );
QgsMessageLog::logMessage( mError, tr( "WCS" ) );
return;
}

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

mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );
if ( !setAuthorizationReply( mCapabilitiesReply ) )
{
mCapabilitiesResponse.clear();
mCapabilitiesReply->deleteLater();
mCapabilitiesReply = nullptr;
mError = tr( "Download of capabilities failed: network reply update failed for authentication config" );
QgsMessageLog::logMessage( mError, tr( "WCS" ) );
return;
}
connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) );
connect( mCapabilitiesReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( capabilitiesReplyProgress( qint64, qint64 ) ) );
return;
Expand Down Expand Up @@ -1179,6 +1205,15 @@ bool QgsWcsCapabilities::setAuthorization( QNetworkRequest &request ) const
return true;
}

bool QgsWcsCapabilities::setAuthorizationReply( QNetworkReply *reply ) const
{
if ( mUri.hasParam( "authcfg" ) && !mUri.param( "authcfg" ).isEmpty() )
{
return QgsAuthManager::instance()->updateNetworkReply( reply, mUri.param( "authcfg" ) );
}
return true;
}

void QgsWcsCapabilities::showMessageBox( const QString& title, const QString& text )
{
QgsMessageOutput *message = QgsMessageOutput::createMessageOutput();
Expand Down
3 changes: 3 additions & 0 deletions src/providers/wcs/qgswcscapabilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ class QgsWcsCapabilities : public QObject
//! set authorization header
bool setAuthorization( QNetworkRequest &request ) const;

//! set authorization reply
bool setAuthorizationReply( QNetworkReply * reply ) const;

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

/**
Expand Down
27 changes: 27 additions & 0 deletions src/providers/wcs/qgswcsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,15 @@ QgsWcsDownloadHandler::QgsWcsDownloadHandler( const QUrl& url, QgsWcsAuthorizati
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, cacheLoadControl );

mCacheReply = QgsNetworkAccessManager::instance()->get( request );
if ( !mAuth.setAuthorizationReply( mCacheReply ) )
{
mCacheReply->deleteLater();
mCacheReply = nullptr;
QgsMessageLog::logMessage( tr( "Network reply update failed for authentication config" ),
tr( "WCS" ) );
finish();
return;
}
connect( mCacheReply, SIGNAL( finished() ), this, SLOT( cacheReplyFinished() ) );
connect( mCacheReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( cacheReplyProgress( qint64, qint64 ) ) );
}
Expand Down Expand Up @@ -1724,6 +1733,15 @@ void QgsWcsDownloadHandler::cacheReplyFinished()
return;
}
mCacheReply = QgsNetworkAccessManager::instance()->get( request );
if ( !mAuth.setAuthorizationReply( mCacheReply ) )
{
mCacheReply->deleteLater();
mCacheReply = nullptr;
QgsMessageLog::logMessage( tr( "Network reply update failed for authentication config" ),
tr( "WCS" ) );
finish();
return;
}
connect( mCacheReply, SIGNAL( finished() ), this, SLOT( cacheReplyFinished() ) );
connect( mCacheReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( cacheReplyProgress( qint64, qint64 ) ) );

Expand Down Expand Up @@ -1891,6 +1909,15 @@ void QgsWcsDownloadHandler::cacheReplyFinished()
mCacheReply->deleteLater();

mCacheReply = QgsNetworkAccessManager::instance()->get( request );
if ( !mAuth.setAuthorizationReply( mCacheReply ) )
{
mCacheReply->deleteLater();
mCacheReply = nullptr;
QgsMessageLog::logMessage( tr( "Network reply update failed for authentication config" ),
tr( "WCS" ) );
finish();
return;
}
connect( mCacheReply, SIGNAL( finished() ), this, SLOT( cacheReplyFinished() ), Qt::DirectConnection );
connect( mCacheReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( cacheReplyProgress( qint64, qint64 ) ), Qt::DirectConnection );

Expand Down
10 changes: 10 additions & 0 deletions src/providers/wcs/qgswcsprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ struct QgsWcsAuthorization
return true;
}

//! set authorization reply
bool setAuthorizationReply( QNetworkReply * reply ) const
{
if ( !mAuthCfg.isEmpty() )
{
return QgsAuthManager::instance()->updateNetworkReply( reply, mAuthCfg );
}
return true;
}

//! Username for basic http authentication
QString mUserName;

Expand Down
12 changes: 11 additions & 1 deletion src/providers/wfs/qgswfsdatasourceuri.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct QgsWFSAuthorization
, mAuthCfg( authcfg )
{}

//! set authorization header
//! update authorization for request
bool setAuthorization( QNetworkRequest &request ) const
{
if ( !mAuthCfg.isEmpty() ) // must be non-empty value
Expand All @@ -46,6 +46,16 @@ struct QgsWFSAuthorization
return true;
}

//! update authorization for reply
bool setAuthorizationReply( QNetworkReply *reply ) const
{
if ( !mAuthCfg.isEmpty() )
{
return QgsAuthManager::instance()->updateNetworkReply( reply, mAuthCfg );
}
return true;
}

//! Username for basic http authentication
QString mUserName;

Expand Down
23 changes: 23 additions & 0 deletions src/providers/wfs/qgswfsrequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ bool QgsWFSRequest::sendGET( const QUrl& url, bool synchronous, bool forceRefres
}

mReply = QgsNetworkAccessManager::instance()->get( request );
if ( !mUri.auth().setAuthorizationReply( mReply ) )
{
mErrorCode = QgsWFSRequest::NetworkError;
mErrorMessage = errorMessageFailedAuth();
QgsMessageLog::logMessage( mErrorMessage, tr( "WFS" ) );
return false;
}
connect( mReply, SIGNAL( finished() ), this, SLOT( replyFinished() ) );
connect( mReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( replyProgress( qint64, qint64 ) ) );

Expand Down Expand Up @@ -160,6 +167,13 @@ bool QgsWFSRequest::sendPOST( const QUrl& url, const QString& contentTypeHeader,
request.setHeader( QNetworkRequest::ContentTypeHeader, contentTypeHeader );

mReply = QgsNetworkAccessManager::instance()->post( request, data );
if ( !mUri.auth().setAuthorizationReply( mReply ) )
{
mErrorCode = QgsWFSRequest::NetworkError;
mErrorMessage = errorMessageFailedAuth();
QgsMessageLog::logMessage( mErrorMessage, tr( "WFS" ) );
return false;
}
connect( mReply, SIGNAL( finished() ), this, SLOT( replyFinished() ) );
connect( mReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( replyProgress( qint64, qint64 ) ) );

Expand Down Expand Up @@ -243,6 +257,15 @@ void QgsWFSRequest::replyFinished()

QgsDebugMsg( QString( "redirected: %1 forceRefresh=%2" ).arg( redirect.toString() ).arg( mForceRefresh ) );
mReply = QgsNetworkAccessManager::instance()->get( request );
if ( !mUri.auth().setAuthorizationReply( mReply ) )
{
mResponse.clear();
mErrorMessage = errorMessageFailedAuth();
mErrorCode = QgsWFSRequest::NetworkError;
QgsMessageLog::logMessage( mErrorMessage, tr( "WFS" ) );
emit downloadFinished();
return;
}
connect( mReply, SIGNAL( finished() ), this, SLOT( replyFinished() ) );
connect( mReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( replyProgress( qint64, qint64 ) ) );
return;
Expand Down
20 changes: 20 additions & 0 deletions src/providers/wms/qgswmscapabilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1956,6 +1956,14 @@ bool QgsWmsCapabilitiesDownload::downloadCapabilities()
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );

mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );
if ( !mAuth.setAuthorizationReply( mCapabilitiesReply ) )
{
mCapabilitiesReply->deleteLater();
mCapabilitiesReply = nullptr;
mError = tr( "Download of capabilities failed: network reply update failed for authentication config" );
QgsMessageLog::logMessage( mError, tr( "WMS" ) );
return false;
}
connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ), Qt::DirectConnection );
connect( mCapabilitiesReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( capabilitiesReplyProgress( qint64, qint64 ) ), Qt::DirectConnection );

Expand Down Expand Up @@ -2022,6 +2030,18 @@ void QgsWmsCapabilitiesDownload::capabilitiesReplyFinished()

QgsDebugMsg( QString( "redirected getcapabilities: %1 forceRefresh=%2" ).arg( redirect.toString() ).arg( mForceRefresh ) );
mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );

if ( !mAuth.setAuthorizationReply( mCapabilitiesReply ) )
{
mHttpCapabilitiesResponse.clear();
mCapabilitiesReply->deleteLater();
mCapabilitiesReply = nullptr;
mError = tr( "Download of capabilities failed: network reply update failed for authentication config" );
QgsMessageLog::logMessage( mError, tr( "WMS" ) );
emit downloadFinished();
return;
}

connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ), Qt::DirectConnection );
connect( mCapabilitiesReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( capabilitiesReplyProgress( qint64, qint64 ) ), Qt::DirectConnection );
return;
Expand Down
9 changes: 9 additions & 0 deletions src/providers/wms/qgswmscapabilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,15 @@ struct QgsWmsAuthorization
}
return true;
}
//! set authorization reply
bool setAuthorizationReply( QNetworkReply * reply ) const
{
if ( !mAuthCfg.isEmpty() )
{
return QgsAuthManager::instance()->updateNetworkReply( reply, mAuthCfg );
}
return true;
}

//! Username for basic http authentication
QString mUserName;
Expand Down
2 changes: 2 additions & 0 deletions src/providers/wms/qgswmsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3105,6 +3105,7 @@ void QgsWmsProvider::identifyReplyFinished()

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

mReply = mNetworkAccessManager.get( request );
mSettings.authorization().setAuthorizationReply( mReply );
connect( mReply, SIGNAL( error( QNetworkReply::NetworkError ) ), this, SLOT( errored( QNetworkReply::NetworkError ) ) );
connect( mReply, SIGNAL( finished() ), this, SLOT( finished() ) );
connect( mReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( progressed( qint64, qint64 ) ) );
Expand Down

0 comments on commit 2d7164f

Please sign in to comment.