Skip to content
Permalink
Browse files

Merge pull request #3378 from dakcarto/release-2_14-auth-reply-ows

[auth] Reinstate auth system reply expansions for OWS providers
  • Loading branch information
dakcarto committed Aug 12, 2016
2 parents 47421b2 + 5480a80 commit 7e37564e078f37d3b3f0b5636568278c3c125ecf
@@ -103,6 +103,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 ) ) );

@@ -157,6 +157,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;
@@ -1181,6 +1207,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();
@@ -155,6 +155,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; }

/**
@@ -1684,6 +1684,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 ) ) );
}
@@ -1719,6 +1728,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 ) ) );

@@ -1883,6 +1901,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;

@@ -165,6 +165,15 @@ bool QgsWFSCapabilities::setAuthorization( QNetworkRequest &request ) const
return true;
}

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

void QgsWFSCapabilities::requestCapabilities()
{
mErrorCode = QgsWFSCapabilities::NoError;
@@ -182,6 +191,17 @@ void QgsWFSCapabilities::requestCapabilities()

request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );
if ( !setAuthorizationReply( mCapabilitiesReply ) )
{
mCapabilitiesReply->deleteLater();
mCapabilitiesReply = nullptr;
mErrorCode = QgsWFSCapabilities::NetworkError;
mErrorMessage = tr( "Download of capabilities failed: network reply update failed for authentication config" );
QgsMessageLog::logMessage( mErrorMessage, tr( "WFS" ) );
emit gotCapabilities();
return;
}

connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) );
}

@@ -220,6 +240,17 @@ void QgsWFSCapabilities::capabilitiesReplyFinished()
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );

mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );
if ( !setAuthorizationReply( mCapabilitiesReply ) )
{
mCaps.clear();
mCapabilitiesReply->deleteLater();
mCapabilitiesReply = nullptr;
mErrorCode = QgsWFSCapabilities::NetworkError;
mErrorMessage = tr( "Download of capabilities failed: network reply update failed for authentication config" );
QgsMessageLog::logMessage( mErrorMessage, tr( "WFS" ) );
emit gotCapabilities();
return;
}

connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) );
return;
@@ -76,6 +76,9 @@ class QgsWFSCapabilities : public QObject
//! set authorization header
bool setAuthorization( QNetworkRequest &request ) const;

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

signals:
void gotCapabilities();

@@ -743,6 +743,13 @@ int QgsWFSProvider::describeFeatureTypeGET( const QString& uri, QString& geometr
return 1;
}
QNetworkReply* reply = QgsNetworkAccessManager::instance()->get( request );
if ( !mAuth.setAuthorizationReply( reply ) )
{
reply->deleteLater();
QgsMessageLog::logMessage( tr( "Network reply update failed for authentication config" ),
tr( "WFS" ) );
return 1;
}

connect( reply, SIGNAL( finished() ), this, SLOT( networkRequestFinished() ) );
while ( !mNetworkRequestFinished )
@@ -1341,6 +1348,14 @@ bool QgsWFSProvider::sendTransactionDocument( const QDomDocument& doc, QDomDocum

request.setHeader( QNetworkRequest::ContentTypeHeader, "text/xml" );
QNetworkReply* reply = QgsNetworkAccessManager::instance()->post( request, doc.toByteArray( -1 ) );
if ( !mAuth.setAuthorizationReply( reply ) )
{
reply->deleteLater();
QgsMessageLog::logMessage( tr( "Network reply update failed for authentication config" ),
tr( "WFS" ) );
return false;
}

QgsDebugMsg( "WFS transaction: " + doc.toByteArray( ) );

connect( reply, SIGNAL( finished() ), this, SLOT( networkRequestFinished() ) );
@@ -1479,6 +1494,14 @@ void QgsWFSProvider::getLayerCapabilities()
return;
}
QNetworkReply* reply = QgsNetworkAccessManager::instance()->get( request );
if ( !mAuth.setAuthorizationReply( reply ) )
{
reply->deleteLater();
mCapabilities = 0;
QgsMessageLog::logMessage( tr( "Network reply update failed for authentication config" ),
tr( "WFS" ) );
return;
}

connect( reply, SIGNAL( finished() ), this, SLOT( networkRequestFinished() ) );
while ( !mNetworkRequestFinished )
@@ -56,6 +56,16 @@ struct QgsWFSAuthorization
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;

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

@@ -2002,7 +2010,19 @@ void QgsWmsCapabilitiesDownload::capabilitiesReplyFinished()

QgsDebugMsg( QString( "redirected getcapabilities: %1 forceRefresh=%2" ).arg( redirect.toString() ).arg( mForceRefresh ) );
mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );
connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ), Qt::DirectConnection );

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;
}
@@ -455,6 +455,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;
@@ -2805,6 +2805,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;
@@ -3733,6 +3734,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 7e37564

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