Skip to content

Commit e3164e9

Browse files
committedOct 12, 2016
[WFS provider] Fix auth config extra expansion and auth prioritization
1 parent 25794d4 commit e3164e9

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed
 

‎src/providers/wfs/qgswfsdatasourceuri.cpp

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,19 @@ QgsWFSDataSourceURI::QgsWFSDataSourceURI( const QString& uri )
4141
QString typeName = url.queryItemValue( QgsWFSConstants::URI_PARAM_TYPENAME );
4242
QString version = url.queryItemValue( QgsWFSConstants::URI_PARAM_VERSION );
4343
QString filter = url.queryItemValue( QgsWFSConstants::URI_PARAM_FILTER );
44-
mAuth.mUserName = url.queryItemValue( QgsWFSConstants::URI_PARAM_USERNAME );
45-
// In QgsDataSourceURI, the "username" param is named "user", check it
46-
if ( mAuth.mUserName.isEmpty() )
44+
mAuth.mAuthCfg = url.queryItemValue( QgsWFSConstants::URI_PARAM_AUTHCFG );
45+
// NOTE: A defined authcfg overrides any older username/password auth
46+
// Only check for older auth if it is undefined
47+
if ( mAuth.mAuthCfg.isEmpty() )
4748
{
48-
mAuth.mUserName = url.queryItemValue( QgsWFSConstants::URI_PARAM_USER );
49+
mAuth.mUserName = url.queryItemValue( QgsWFSConstants::URI_PARAM_USERNAME );
50+
// In QgsDataSourceURI, the "username" param is named "user", check it
51+
if ( mAuth.mUserName.isEmpty() )
52+
{
53+
mAuth.mUserName = url.queryItemValue( QgsWFSConstants::URI_PARAM_USER );
54+
}
55+
mAuth.mPassword = url.queryItemValue( QgsWFSConstants::URI_PARAM_PASSWORD );
4956
}
50-
mAuth.mPassword = url.queryItemValue( QgsWFSConstants::URI_PARAM_PASSWORD );
51-
mAuth.mAuthCfg = url.queryItemValue( QgsWFSConstants::URI_PARAM_AUTHCFG );
5257

5358
// Now remove all stuff that is not the core URL
5459
url.removeQueryItem( "SERVICE" );
@@ -90,19 +95,24 @@ QgsWFSDataSourceURI::QgsWFSDataSourceURI( const QString& uri )
9095
const QString QgsWFSDataSourceURI::uri( bool expandAuthConfig ) const
9196
{
9297
QgsDataSourceURI theURI( mURI );
93-
// Add auth params back into the uri
98+
// Add authcfg param back into the uri (must be non-empty value)
9499
if ( ! mAuth.mAuthCfg.isEmpty() )
95100
{
96101
theURI.setAuthConfigId( mAuth.mAuthCfg );
97102
}
98-
if ( ! mAuth.mUserName.isEmpty() )
99-
{
100-
theURI.setUsername( mAuth.mUserName );
101-
}
102-
if ( ! mAuth.mPassword.isEmpty() )
103+
else
103104
{
104-
theURI.setPassword( mAuth.mPassword );
105+
// Add any older username/password auth params back in (allow empty values)
106+
if ( ! mAuth.mUserName.isNull() )
107+
{
108+
theURI.setUsername( mAuth.mUserName );
109+
}
110+
if ( ! mAuth.mPassword.isNull() )
111+
{
112+
theURI.setPassword( mAuth.mPassword );
113+
}
105114
}
115+
// NOTE: avoid expanding authcfg here; it is handled during network access
106116
return theURI.uri( expandAuthConfig );
107117
}
108118

‎src/providers/wfs/qgswfsdatasourceuri.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ struct QgsWFSAuthorization
3535
//! set authorization header
3636
bool setAuthorization( QNetworkRequest &request ) const
3737
{
38-
if ( !mAuthCfg.isEmpty() )
38+
if ( !mAuthCfg.isEmpty() ) // must be non-empty value
3939
{
4040
return QgsAuthManager::instance()->updateNetworkRequest( request, mAuthCfg );
4141
}
42-
else if ( !mUserName.isNull() || !mPassword.isNull() )
42+
else if ( !mUserName.isNull() || !mPassword.isNull() ) // allow empty values
4343
{
4444
request.setRawHeader( "Authorization", "Basic " + QString( "%1:%2" ).arg( mUserName, mPassword ).toAscii().toBase64() );
4545
}
@@ -65,8 +65,8 @@ class QgsWFSDataSourceURI
6565

6666
explicit QgsWFSDataSourceURI( const QString& uri );
6767

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

7171
/** Return base URL (with SERVICE=WFS parameter if bIncludeServiceWFS=true) */
7272
QUrl baseURL( bool bIncludeServiceWFS = true ) const;

‎src/providers/wfs/qgswfsprovider.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,7 @@ bool QgsWFSProvider::describeFeatureType( QString& geometryAttribute, QgsFields&
11011101
{
11021102
fields.clear();
11031103

1104-
QgsWFSDescribeFeatureType describeFeatureType( mShared->mURI.uri( false ) );
1104+
QgsWFSDescribeFeatureType describeFeatureType( mShared->mURI.uri() );
11051105
if ( !describeFeatureType.requestFeatureType( mShared->mWFSVersion,
11061106
mShared->mURI.typeName() ) )
11071107
{
@@ -1337,7 +1337,7 @@ bool QgsWFSProvider::sendTransactionDocument( const QDomDocument& doc, QDomDocum
13371337
return false;
13381338
}
13391339

1340-
QgsWFSTransactionRequest request( mShared->mURI.uri( false ) );
1340+
QgsWFSTransactionRequest request( mShared->mURI.uri() );
13411341
return request.send( doc, serverResponse );
13421342
}
13431343

@@ -1440,7 +1440,7 @@ bool QgsWFSProvider::getCapabilities()
14401440

14411441
if ( mShared->mCaps.version.isEmpty() )
14421442
{
1443-
QgsWFSCapabilities getCapabilities( mShared->mURI.uri( false ) );
1443+
QgsWFSCapabilities getCapabilities( mShared->mURI.uri() );
14441444
const bool synchronous = true;
14451445
const bool forceRefresh = false;
14461446
if ( !getCapabilities.requestCapabilities( synchronous, forceRefresh ) )

0 commit comments

Comments
 (0)
Please sign in to comment.