Skip to content
Permalink
Browse files

[WFS provider] Fix auth config extra expansion and auth prioritization

  • Loading branch information
dakcarto committed Oct 13, 2016
1 parent 35f1749 commit 37b00eb602500950a99a531a4e9c2b6891247786
@@ -41,14 +41,19 @@ QgsWFSDataSourceURI::QgsWFSDataSourceURI( const QString& uri )
QString typeName = url.queryItemValue( QgsWFSConstants::URI_PARAM_TYPENAME );
QString version = url.queryItemValue( QgsWFSConstants::URI_PARAM_VERSION );
QString filter = url.queryItemValue( QgsWFSConstants::URI_PARAM_FILTER );
mAuth.mUserName = url.queryItemValue( QgsWFSConstants::URI_PARAM_USERNAME );
// In QgsDataSourceURI, the "username" param is named "user", check it
if ( mAuth.mUserName.isEmpty() )
mAuth.mAuthCfg = url.queryItemValue( QgsWFSConstants::URI_PARAM_AUTHCFG );
// NOTE: A defined authcfg overrides any older username/password auth
// Only check for older auth if it is undefined
if ( mAuth.mAuthCfg.isEmpty() )
{
mAuth.mUserName = url.queryItemValue( QgsWFSConstants::URI_PARAM_USER );
mAuth.mUserName = url.queryItemValue( QgsWFSConstants::URI_PARAM_USERNAME );
// In QgsDataSourceURI, the "username" param is named "user", check it
if ( mAuth.mUserName.isEmpty() )
{
mAuth.mUserName = url.queryItemValue( QgsWFSConstants::URI_PARAM_USER );
}
mAuth.mPassword = url.queryItemValue( QgsWFSConstants::URI_PARAM_PASSWORD );
}
mAuth.mPassword = url.queryItemValue( QgsWFSConstants::URI_PARAM_PASSWORD );
mAuth.mAuthCfg = url.queryItemValue( QgsWFSConstants::URI_PARAM_AUTHCFG );

// Now remove all stuff that is not the core URL
url.removeQueryItem( "SERVICE" );
@@ -90,19 +95,24 @@ QgsWFSDataSourceURI::QgsWFSDataSourceURI( const QString& uri )
const QString QgsWFSDataSourceURI::uri( bool expandAuthConfig ) const
{
QgsDataSourceUri theURI( mURI );
// Add auth params back into the uri
// Add authcfg param back into the uri (must be non-empty value)
if ( ! mAuth.mAuthCfg.isEmpty() )
{
theURI.setAuthConfigId( mAuth.mAuthCfg );
}
if ( ! mAuth.mUserName.isEmpty() )
{
theURI.setUsername( mAuth.mUserName );
}
if ( ! mAuth.mPassword.isEmpty() )
else
{
theURI.setPassword( mAuth.mPassword );
// Add any older username/password auth params back in (allow empty values)
if ( ! mAuth.mUserName.isNull() )
{
theURI.setUsername( mAuth.mUserName );
}
if ( ! mAuth.mPassword.isNull() )
{
theURI.setPassword( mAuth.mPassword );
}
}
// NOTE: avoid expanding authcfg here; it is handled during network access
return theURI.uri( expandAuthConfig );
}

@@ -35,11 +35,11 @@ struct QgsWFSAuthorization
//! set authorization header
bool setAuthorization( QNetworkRequest &request ) const
{
if ( !mAuthCfg.isEmpty() )
if ( !mAuthCfg.isEmpty() ) // must be non-empty value
{
return QgsAuthManager::instance()->updateNetworkRequest( request, mAuthCfg );
}
else if ( !mUserName.isNull() || !mPassword.isNull() )
else if ( !mUserName.isNull() || !mPassword.isNull() ) // allow empty values
{
request.setRawHeader( "Authorization", "Basic " + QString( "%1:%2" ).arg( mUserName, mPassword ).toLatin1().toBase64() );
}
@@ -65,8 +65,8 @@ class QgsWFSDataSourceURI

explicit QgsWFSDataSourceURI( const QString& uri );

/** Return the URI */
const QString uri( bool expandAuthConfig = true ) const;
/** Return the URI, avoiding expansion of authentication configuration, which is handled during network access */
const QString uri( bool expandAuthConfig = false ) const;

/** Return base URL (with SERVICE=WFS parameter if bIncludeServiceWFS=true) */
QUrl baseURL( bool bIncludeServiceWFS = true ) const;
@@ -1104,7 +1104,7 @@ bool QgsWFSProvider::describeFeatureType( QString& geometryAttribute, QgsFields&
{
fields.clear();

QgsWFSDescribeFeatureType describeFeatureType( mShared->mURI.uri( false ) );
QgsWFSDescribeFeatureType describeFeatureType( mShared->mURI.uri() );
if ( !describeFeatureType.requestFeatureType( mShared->mWFSVersion,
mShared->mURI.typeName() ) )
{
@@ -1340,7 +1340,7 @@ bool QgsWFSProvider::sendTransactionDocument( const QDomDocument& doc, QDomDocum
return false;
}

QgsWFSTransactionRequest request( mShared->mURI.uri( false ) );
QgsWFSTransactionRequest request( mShared->mURI.uri() );
return request.send( doc, serverResponse );
}

@@ -1443,7 +1443,7 @@ bool QgsWFSProvider::getCapabilities()

if ( mShared->mCaps.version.isEmpty() )
{
QgsWfsCapabilities getCapabilities( mShared->mURI.uri( false ) );
QgsWfsCapabilities getCapabilities( mShared->mURI.uri() );
const bool synchronous = true;
const bool forceRefresh = false;
if ( !getCapabilities.requestCapabilities( synchronous, forceRefresh ) )

0 comments on commit 37b00eb

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