mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-05 00:09:32 -04:00
[WFS] Fixes #15360 and other issues
- fixes authcfg params not passed to requests - fixes backward URI compatibility - fixes version parameter ignored in old style URI - check for "user" in addition to "username" in WFS URI (cherry-picked from f49bd5ca449e332aa547f9dac31b391e438d2b31)
This commit is contained in:
parent
863c73db8f
commit
56400b147b
@ -23,11 +23,13 @@ const QString QgsWFSConstants::XMLSCHEMA_NAMESPACE( "http://www.w3.org/2001/XMLS
|
||||
|
||||
const QString QgsWFSConstants::URI_PARAM_URL( "url" );
|
||||
const QString QgsWFSConstants::URI_PARAM_USERNAME( "username" );
|
||||
const QString QgsWFSConstants::URI_PARAM_USER( "user" );
|
||||
const QString QgsWFSConstants::URI_PARAM_PASSWORD( "password" );
|
||||
const QString QgsWFSConstants::URI_PARAM_AUTHCFG( "authcfg" );
|
||||
const QString QgsWFSConstants::URI_PARAM_VERSION( "version" );
|
||||
const QString QgsWFSConstants::URI_PARAM_TYPENAME( "typename" );
|
||||
const QString QgsWFSConstants::URI_PARAM_SRSNAME( "srsname" );
|
||||
const QString QgsWFSConstants::URI_PARAM_BBOX( "bbox" );
|
||||
const QString QgsWFSConstants::URI_PARAM_FILTER( "filter" );
|
||||
const QString QgsWFSConstants::URI_PARAM_RESTRICT_TO_REQUEST_BBOX( "retrictToRequestBBOX" );
|
||||
const QString QgsWFSConstants::URI_PARAM_MAXNUMFEATURES( "maxNumFeatures" );
|
||||
|
@ -29,12 +29,16 @@ struct QgsWFSConstants
|
||||
// URI parameters
|
||||
static const QString URI_PARAM_URL;
|
||||
static const QString URI_PARAM_USERNAME;
|
||||
// QgsDataSourceURI recognizes "user" instead of "username"
|
||||
// we are going to check both
|
||||
static const QString URI_PARAM_USER;
|
||||
static const QString URI_PARAM_PASSWORD;
|
||||
static const QString URI_PARAM_AUTHCFG;
|
||||
static const QString URI_PARAM_VERSION;
|
||||
static const QString URI_PARAM_TYPENAME;
|
||||
static const QString URI_PARAM_SRSNAME;
|
||||
static const QString URI_PARAM_FILTER;
|
||||
static const QString URI_PARAM_BBOX;
|
||||
static const QString URI_PARAM_RESTRICT_TO_REQUEST_BBOX;
|
||||
static const QString URI_PARAM_MAXNUMFEATURES;
|
||||
static const QString URI_PARAM_IGNOREAXISORIENTATION;
|
||||
|
@ -13,6 +13,8 @@
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "QtGlobal"
|
||||
|
||||
#include "qgswfsconstants.h"
|
||||
#include "qgswfsdatasourceuri.h"
|
||||
#include "qgsmessagelog.h"
|
||||
@ -25,11 +27,26 @@ QgsWFSDataSourceURI::QgsWFSDataSourceURI( const QString& uri )
|
||||
if ( !mURI.hasParam( QgsWFSConstants::URI_PARAM_URL ) )
|
||||
{
|
||||
QUrl url( uri );
|
||||
QString srsname = url.queryItemValue( "SRSNAME" );
|
||||
QString bbox = url.queryItemValue( "BBOX" );
|
||||
QString typeName = url.queryItemValue( "TYPENAME" );
|
||||
QString filter = url.queryItemValue( "FILTER" );
|
||||
// Transform all param keys to lowercase
|
||||
typedef QPair<QString, QString> queryItem;
|
||||
QList<queryItem> items( url.queryItems() );
|
||||
foreach ( queryItem item, items )
|
||||
{
|
||||
url.removeQueryItem( item.first );
|
||||
url.addQueryItem( item.first.toLower(), item.second );
|
||||
}
|
||||
|
||||
QString srsname = url.queryItemValue( QgsWFSConstants::URI_PARAM_SRSNAME );
|
||||
QString bbox = url.queryItemValue( QgsWFSConstants::URI_PARAM_BBOX );
|
||||
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.mUserName = url.queryItemValue( QgsWFSConstants::URI_PARAM_USER );
|
||||
}
|
||||
mAuth.mPassword = url.queryItemValue( QgsWFSConstants::URI_PARAM_PASSWORD );
|
||||
mAuth.mAuthCfg = url.queryItemValue( QgsWFSConstants::URI_PARAM_AUTHCFG );
|
||||
|
||||
@ -49,6 +66,7 @@ QgsWFSDataSourceURI::QgsWFSDataSourceURI( const QString& uri )
|
||||
mURI.setParam( QgsWFSConstants::URI_PARAM_URL, url.toEncoded() );
|
||||
setTypeName( typeName );
|
||||
setSRSName( srsname );
|
||||
setVersion( version );
|
||||
|
||||
//if the xml comes from the dialog, it needs to be a string to pass the validity test
|
||||
if ( filter.startsWith( '\'' ) && filter.endsWith( '\'' ) && filter.size() > 1 )
|
||||
@ -63,17 +81,32 @@ QgsWFSDataSourceURI::QgsWFSDataSourceURI( const QString& uri )
|
||||
}
|
||||
else
|
||||
{
|
||||
mAuth.mUserName = mURI.param( QgsWFSConstants::URI_PARAM_USERNAME );
|
||||
mAuth.mPassword = mURI.param( QgsWFSConstants::URI_PARAM_PASSWORD );
|
||||
mAuth.mAuthCfg = mURI.param( QgsWFSConstants::URI_PARAM_AUTHCFG );
|
||||
mAuth.mUserName = mURI.username();
|
||||
mAuth.mPassword = mURI.password();
|
||||
mAuth.mAuthCfg = mURI.authConfigId();
|
||||
}
|
||||
}
|
||||
|
||||
QString QgsWFSDataSourceURI::uri()
|
||||
const QString QgsWFSDataSourceURI::uri( bool expandAuthConfig ) const
|
||||
{
|
||||
return mURI.uri();
|
||||
QgsDataSourceUri theURI( mURI );
|
||||
// Add auth params back into the uri
|
||||
if ( ! mAuth.mAuthCfg.isEmpty() )
|
||||
{
|
||||
theURI.setAuthConfigId( mAuth.mAuthCfg );
|
||||
}
|
||||
if ( ! mAuth.mUserName.isEmpty() )
|
||||
{
|
||||
theURI.setUsername( mAuth.mUserName );
|
||||
}
|
||||
if ( ! mAuth.mPassword.isEmpty() )
|
||||
{
|
||||
theURI.setPassword( mAuth.mPassword );
|
||||
}
|
||||
return theURI.uri( expandAuthConfig );
|
||||
}
|
||||
|
||||
|
||||
QUrl QgsWFSDataSourceURI::baseURL( bool bIncludeServiceWFS ) const
|
||||
{
|
||||
QUrl url( mURI.param( QgsWFSConstants::URI_PARAM_URL ) );
|
||||
@ -122,6 +155,13 @@ void QgsWFSDataSourceURI::setSRSName( const QString& crsString )
|
||||
mURI.setParam( QgsWFSConstants::URI_PARAM_SRSNAME, crsString );
|
||||
}
|
||||
|
||||
void QgsWFSDataSourceURI::setVersion( const QString& versionString )
|
||||
{
|
||||
mURI.removeParam( QgsWFSConstants::URI_PARAM_VERSION );
|
||||
if ( !versionString.isEmpty() )
|
||||
mURI.setParam( QgsWFSConstants::URI_PARAM_VERSION, versionString );
|
||||
}
|
||||
|
||||
QString QgsWFSDataSourceURI::SRSName() const
|
||||
{
|
||||
return mURI.param( QgsWFSConstants::URI_PARAM_SRSNAME );
|
||||
|
@ -66,7 +66,7 @@ class QgsWFSDataSourceURI
|
||||
explicit QgsWFSDataSourceURI( const QString& uri );
|
||||
|
||||
/** Return the URI */
|
||||
QString uri();
|
||||
const QString uri( bool expandAuthConfig = true ) const;
|
||||
|
||||
/** Return base URL (with SERVICE=WFS parameter if bIncludeServiceWFS=true) */
|
||||
QUrl baseURL( bool bIncludeServiceWFS = true ) const;
|
||||
@ -92,6 +92,9 @@ class QgsWFSDataSourceURI
|
||||
/** Set SRS name (in the normalized form EPSG:xxxx) */
|
||||
void setSRSName( const QString& crsString );
|
||||
|
||||
/** Set version */
|
||||
void setVersion( const QString& versionString );
|
||||
|
||||
/** Get OGC filter xml or a QGIS expression */
|
||||
QString filter() const;
|
||||
|
||||
|
@ -1100,7 +1100,7 @@ bool QgsWFSProvider::describeFeatureType( QString& geometryAttribute, QgsFields&
|
||||
{
|
||||
fields.clear();
|
||||
|
||||
QgsWFSDescribeFeatureType describeFeatureType( mShared->mURI.uri() );
|
||||
QgsWFSDescribeFeatureType describeFeatureType( mShared->mURI.uri( false ) );
|
||||
if ( !describeFeatureType.requestFeatureType( mShared->mWFSVersion,
|
||||
mShared->mURI.typeName() ) )
|
||||
{
|
||||
@ -1329,7 +1329,7 @@ bool QgsWFSProvider::sendTransactionDocument( const QDomDocument& doc, QDomDocum
|
||||
return false;
|
||||
}
|
||||
|
||||
QgsWFSTransactionRequest request( mShared->mURI.uri() );
|
||||
QgsWFSTransactionRequest request( mShared->mURI.uri( false ) );
|
||||
return request.send( doc, serverResponse );
|
||||
}
|
||||
|
||||
@ -1432,7 +1432,7 @@ bool QgsWFSProvider::getCapabilities()
|
||||
|
||||
if ( mShared->mCaps.version.isEmpty() )
|
||||
{
|
||||
QgsWfsCapabilities getCapabilities( mShared->mURI.uri() );
|
||||
QgsWfsCapabilities getCapabilities( mShared->mURI.uri( false ) );
|
||||
if ( !getCapabilities.requestCapabilities( true ) )
|
||||
{
|
||||
QgsMessageLog::logMessage( tr( "GetCapabilities failed for url %1: %2" ).
|
||||
|
Loading…
x
Reference in New Issue
Block a user