Skip to content
Permalink
Browse files

WMS server: add user setting if custom datasources are allowed in wms…

… requests
  • Loading branch information
mhugent committed Nov 10, 2016
1 parent 72fddb8 commit b0644ea4383f03e2a9785c5f7146a6470ceb1020
@@ -123,6 +123,8 @@ class QgsWmsConfigParser

virtual bool useLayerIds() const = 0;

virtual bool allowRequestDefinedDatasources() const;

private:

QgsWmsConfigParser();
@@ -111,6 +111,8 @@ class QgsWmsProjectParser : public QgsWmsConfigParser

bool useLayerIds() const /*override*/ ;

bool allowRequestDefinedDatasources() const;

private:

/** Returns an ID-list of layers which are not queryable (comes from <properties> -> <Identify> -> <disabledLayers in the project file*/
@@ -527,6 +527,9 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
bool addWktGeometry = QgsProject::instance()->readBoolEntry( QStringLiteral( "WMSAddWktGeometry" ), QStringLiteral( "/" ) );
mAddWktGeometryCheckBox->setChecked( addWktGeometry );

bool requestDefinedSources = QgsProject::instance()->readBoolEntry( "WMSRequestDefinedDataSources", "/", false );
mAllowRequestDefinedDataSourcesBox->setChecked( requestDefinedSources );

bool segmentizeFeatureInfoGeometry = QgsProject::instance()->readBoolEntry( QStringLiteral( "WMSSegmentizeFeatureInfoGeometry" ), QStringLiteral( "/" ) );
mSegmentizeFeatureInfoGeometryCheckBox->setChecked( segmentizeFeatureInfoGeometry );

@@ -1077,6 +1080,7 @@ void QgsProjectProperties::apply()
}

QgsProject::instance()->writeEntry( QStringLiteral( "WMSAddWktGeometry" ), QStringLiteral( "/" ), mAddWktGeometryCheckBox->isChecked() );
QgsProject::instance()->writeEntry( "WMSRequestDefinedDataSources", "/", mAllowRequestDefinedDataSourcesBox->isChecked() );
QgsProject::instance()->writeEntry( QStringLiteral( "WMSSegmentizeFeatureInfoGeometry" ), QStringLiteral( "/" ), mSegmentizeFeatureInfoGeometryCheckBox->isChecked() );
QgsProject::instance()->writeEntry( QStringLiteral( "WMSUseLayerIDs" ), QStringLiteral( "/" ), mWmsUseLayerIDs->isChecked() );

@@ -20,6 +20,7 @@
#include "qgsconfigparserutils.h"
#include "qgslogger.h"
#include "qgsmapserviceexception.h"
#include "qgsmessagelog.h"
#include "qgsrasterlayer.h"
#include "qgsrenderer.h"
#include "qgssinglesymbolrenderer.h"
@@ -1204,6 +1205,17 @@ QDomElement QgsSLDConfigParser::findUserLayerElement( const QString& layerName )

QgsMapLayer* QgsSLDConfigParser::mapLayerFromUserLayer( const QDomElement& userLayerElem, const QString& layerName, bool allowCaching ) const
{
if ( !mFallbackParser )
{
return 0;
}

if ( !mFallbackParser->allowRequestDefinedDatasources() )
{
QgsMessageLog::logMessage( "The project configuration does not allow datasources defined in the request", "Server", QgsMessageLog::CRITICAL );
return 0;
}

QgsDebugMsg( "Entering." );
QgsMSLayerBuilder* layerBuilder = nullptr;
QDomElement builderRootElement;
@@ -1358,6 +1370,15 @@ void QgsSLDConfigParser::setCrsForLayer( const QDomElement& layerElem, QgsMapLay
}
}

bool QgsSLDConfigParser::allowRequestDefinedDatasources() const
{
if ( mFallbackParser )
{
return mFallbackParser->allowRequestDefinedDatasources();
}
return false;
}




@@ -133,6 +133,8 @@ class QgsSLDConfigParser : public QgsWmsConfigParser

void serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const override;

bool allowRequestDefinedDatasources() const;

private:

//! SLD as dom document
@@ -139,6 +139,8 @@ class SERVER_EXPORT QgsWmsConfigParser

virtual bool useLayerIds() const = 0;

virtual bool allowRequestDefinedDatasources() const { return false; }

//! Adds highlight layers to the layer registry and to the layer set. Returns the ids of the newly created layers (for later removal)
static QStringList addHighlightLayers( const QMap<QString, QString>& parameterMap, QStringList& layerSet, const QString& parameterPrefix = QString() );
static void removeHighlightLayers( const QStringList& layerIds );
@@ -2481,3 +2481,24 @@ QString QgsWmsProjectParser::getCapaServiceUrl( QDomDocument& doc ) const

return url;
}

bool QgsWmsProjectParser::allowRequestDefinedDatasources() const
{
if ( !mProjectParser->xmlDocument() )
{
return false;
}

QDomElement propertiesElem = mProjectParser->propertiesElem();
if ( propertiesElem.isNull() )
{
return false;
}
QDomElement dsElem = propertiesElem.firstChildElement( "WMSRequestDefinedDataSources" );
if ( dsElem.isNull() )
{
return false;
}

return ( dsElem.text().compare( "true", Qt::CaseInsensitive ) == 0 );
}
@@ -127,6 +127,8 @@ class SERVER_EXPORT QgsWmsProjectParser : public QgsWmsConfigParser

bool useLayerIds() const override { return mProjectParser->useLayerIds(); }

bool allowRequestDefinedDatasources() const;

private:
QgsServerProjectParser* mProjectParser;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
@@ -1894,6 +1894,11 @@ QImage* QgsWmsServer::initializeRendering( QStringList& layersList, QStringList&
QString gml = mParameters.value( QStringLiteral( "GML" ) );
if ( !gml.isEmpty() )
{
if ( !mConfigParser->allowRequestDefinedDatasources() )
{
QgsMessageLog::logMessage( "The project configuration does not allow datasources defined in the request", "Server", QgsMessageLog::CRITICAL );
return 0;
}
QDomDocument* gmlDoc = new QDomDocument();
if ( gmlDoc->setContent( gml, true ) )
{
@@ -1238,7 +1238,7 @@
</widget>
</item>
<item row="0" column="0" rowspan="8">
<widget class="QgsColorSchemeList" name="mTreeProjectColors" native="true"/>
<widget class="QgsColorSchemeList" name="mTreeProjectColors"/>
</item>
<item row="4" column="1">
<widget class="QToolButton" name="mButtonImportColors">
@@ -1294,9 +1294,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-961</y>
<y>-912</y>
<width>674</width>
<height>2470</height>
<height>2497</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_13">
@@ -1845,7 +1845,7 @@
</property>
</widget>
</item>
<item row="11" column="0" colspan="2">
<item row="12" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<widget class="QLabel" name="mWMSImageQualityLabel">
@@ -1879,7 +1879,7 @@
</property>
</widget>
</item>
<item row="10" column="0" colspan="2">
<item row="11" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="1">
<widget class="QLabel" name="mMaxWidthLabel">
@@ -1926,7 +1926,7 @@
</item>
</layout>
</item>
<item row="8" column="0" colspan="2">
<item row="9" column="0" colspan="2">
<layout class="QHBoxLayout" name="grpWMSPrecision">
<item>
<widget class="QLabel" name="label_5">
@@ -1950,7 +1950,7 @@
</item>
</layout>
</item>
<item row="9" column="0" colspan="2">
<item row="10" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="mWMSUrlLabel">
@@ -2096,13 +2096,20 @@
</layout>
</widget>
</item>
<item row="7" column="0">
<item row="8" column="0">
<widget class="QCheckBox" name="mSegmentizeFeatureInfoGeometryCheckBox">
<property name="text">
<string>Segmentize feature info geometry</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QCheckBox" name="mAllowRequestDefinedDataSourcesBox">
<property name="text">
<string>Allow defining datasources in server requests</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@@ -2359,8 +2366,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>694</width>
<height>779</height>
<width>141</width>
<height>54</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_17">
@@ -2486,39 +2493,39 @@
</widget>
<customwidgets>
<customwidget>
<class>QgsCollapsibleGroupBox</class>
<extends>QGroupBox</extends>
<header>qgscollapsiblegroupbox.h</header>
<class>QgsProjectionSelector</class>
<extends>QWidget</extends>
<header>qgsprojectionselector.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbutton.h</header>
<class>QgsCollapsibleGroupBox</class>
<extends>QGroupBox</extends>
<header>qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsColorSchemeList</class>
<class>QgsCodeEditorPython</class>
<extends>QWidget</extends>
<header location="global">qgscolorschemelist.h</header>
<header>qgscodeeditorpython.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsVariableEditorWidget</class>
<extends>QWidget</extends>
<header location="global">qgsvariableeditorwidget.h</header>
<class>QgsColorSchemeList</class>
<extends>QTreeView</extends>
<header>qgscolorschemelist.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsCodeEditorPython</class>
<extends>QWidget</extends>
<header>qgscodeeditorpython.h</header>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsProjectionSelector</class>
<class>QgsVariableEditorWidget</class>
<extends>QWidget</extends>
<header>qgsprojectionselector.h</header>
<header location="global">qgsvariableeditorwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>

0 comments on commit b0644ea

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