Skip to content
Permalink
Browse files

[auth] Reinstate auth system reply expansions for OWS providers

- Apparently this was lost during a git squash of commits for 2.12 PR
  • Loading branch information
dakcarto committed Oct 13, 2016
1 parent ff661fe commit 9671609c2a87f73a6aaf3f8a3a1cea5c386ee7b4
@@ -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 ) ) );

@@ -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 ) ) );
@@ -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 ) ) );
@@ -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;
@@ -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();
@@ -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; }

/**
@@ -1676,6 +1676,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 ) ) );
}
@@ -1711,6 +1720,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 ) ) );

@@ -1875,6 +1893,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 );

@@ -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;

@@ -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
@@ -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;

@@ -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 ) ) );

@@ -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 ) ) );

@@ -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;
@@ -1920,6 +1920,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 );

@@ -1986,6 +1994,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;
@@ -481,6 +481,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;
@@ -2807,6 +2807,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;
@@ -3734,6 +3735,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 ) ) );

0 comments on commit 9671609

Please sign in to comment.
You can’t perform that action at this time.