usage.rst 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. .. _params_extractor_usage:
  2. Using the Parameters Extractor module
  3. =====================================
  4. This module allow us to entering specific request parameters as URL path fragments instead of using the query string.
  5. For example, we want to be able to apply a cql_filter using a URL in the following form::
  6. /geoserver/<workspace>/<layer>/<filter>/ows?service=WMS&version=1.3.0&request=GetMap
  7. As a simple example of usage, if the <filter> is something like::
  8. K_140M
  9. the URL would become::
  10. /geoserver/<workspace>/<layer>/K_140M/ows?service=WMS&version=1.3.0&request=GetMap
  11. and this module will translate the URL to this new one::
  12. /geoserver/<workspace>/<layer>/ows?service=WMS&version=1.3.0&request=GetMap&cql_filter=seq='K140M'
  13. This module is configured by a set of rules that will be applied to the incoming URLs. Note that a get capabilities result will include the original URL maintaining the extra filter.
  14. This module also gives the possibility to echo existing URL parameters to the result of a get capabilities result. As an example, by default the following get capabilities request (note the existing cql_filter parameter)::
  15. /geoserver/ows?service=wms&version=1.3.0&request=GetCapabilities&cql_filter=CFCC=%27D68%27
  16. will return a get capabilities document were the URLs will be of the type::
  17. /geoserver/ows?SERVICE=WMS&
  18. if this module is configured to echo an existing cql_filter parameter the result would be::
  19. /geoserver/ows?SERVICE=WMS&CQL_FILTER=CFCC%3D%27D68%27&
  20. This module is configured using three types of rules: echo parameter rules, basic rules and advanced rules. All of them can be managed in this module UI which is integrated in GeoServer UI.
  21. Echo Parameter Rules
  22. -----------------------------------
  23. Echo parameter rules are very simple, they allow us to define that a certain existing URL parameter should be echoed to a get capabilities result. This type of rules only required one mandatory parameter which is the name of the existing URL parameter that should be echoed to a get capabilities result.
  24. Example of an echo parameter rule:
  25. .. figure:: images/echo_rule.png
  26. :align: center
  27. *Example of a echo parameter rule defined in the UI*
  28. This rule will echo the cql_filter of this URL::
  29. /geoserver/ows?service=wms&version=1.3.0&request=GetCapabilities&cql_filter=CFCC=%27D68%27
  30. to the get capabilities result::
  31. /geoserver/ows?SERVICE=WMS&CQL_FILTER=CFCC%3D%27D68%27&
  32. Basic Rules
  33. -----------------------------------
  34. Basic rules allow us to handle simple uses cases where we only want to extract a parameter from the URL.
  35. A basic rule is defined by three mandatory attributes:
  36. .. list-table::
  37. :widths: 20 80
  38. * - **Attribute**
  39. - **Description**
  40. * - ``Position``
  41. - The position of the URL base path element to be selected
  42. * - ``Parameter``
  43. - The name of the parameter produced by this rule
  44. * - ``Transform``
  45. - Expression that defines the value of the parameter, use {PARAMETER} as a placeholder for the selected path element
  46. For commodity is also possible when defining this type of rules to configure that an existing parameter in the URL should be echoed to a get capabilities result.
  47. Example of a basic rule:
  48. .. figure:: images/basic_rule.png
  49. :align: center
  50. *Example of a basic rule defined in the UI*
  51. This rule will transform the URL::
  52. /geoserver/tiger/wms/H11?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap
  53. in::
  54. /geoserver/tiger/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&CQL_FILTER=CFCC%3D%27H11%27
  55. Advanced Rules
  56. -----------------------------------
  57. Advanced rules allow us to handle more complex uses cases where more flexibility is required.
  58. An advanced rule is defined by three mandatory attributes and four optional ones:
  59. .. list-table::
  60. :widths: 10 80 10
  61. * - **Attribute**
  62. - **Description**
  63. - **Mandatory**
  64. * - ``Match``
  65. - Regex match expression with groups, for example ^(?:/[^/]*){3}(/([^/]+)).*$ selects the URL base path third element
  66. - Yes
  67. * - ``Activation``
  68. - If defined this rule will only be applied to URLs that match this regex expression
  69. - No
  70. * - ``Parameter``
  71. - The name of the parameter produced by this rule
  72. - Yes
  73. * - ``Transform``
  74. - Expression that defines the value of the parameter, use $1 ... $n as placeholders for groups defined in the match expression
  75. - Yes
  76. * - ``Remove``
  77. - The match expression group to be removed from URL, by default 1
  78. - No
  79. * - ``Combine``
  80. - Defines how to combine parameter existing value ($1 existing value, $2 new value), by default the value is overridden
  81. - No
  82. * - ``Repeat``
  83. - If defined, Combine is applied not only once, but for every layer included in the LAYERS parameter, this allows filling parameters that require a value for each layer (e.g. STYLES or CQL_FILTER)
  84. - No
  85. For commodity is also possible when defining this type of rules to configure that an existing parameter in the URL should be echoed to a get capabilities result.
  86. Example of an advanced rule:
  87. .. figure:: images/advanced_rule.png
  88. :align: center
  89. *Example of an advanced rule defined in the UI*
  90. This rule will transform the URL::
  91. /geoserver/tiger/wms/H11?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&CQL_FILTER=CFCC%3D%27D68%27
  92. in::
  93. /geoserver/tiger/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&CQL_FILTER=CFCC%3D%27D68%27+or+CFCC%3D%27H11%27
  94. No that this rule will also echo an existing cql_filter parameter to the get capabilities result.
  95. Example of an advanced rule with repeat:
  96. .. figure:: images/advanced_rule_repeat.png
  97. :align: center
  98. *Example of an advanced rule with repeat defined in the UI*
  99. This rule will transform the URL::
  100. /geoserver/wms/H11?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&LAYERS=tiger,other
  101. in::
  102. /geoserver/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&LAYERS=tiger,otherCQL_FILTER=CFCC%3D%27D68%27%3BCFCC%3D%27H11%27
  103. Rules Management
  104. -----------------------------
  105. Rules can be managed and tested in the rules management UI. Besides the basic operations like add, remove and update is also possible to activate or deactivate rules. A deactivated rule will be ignored by this module.
  106. Follow a print screen of the rules management UI with all the rules previously defined:
  107. .. figure:: images/rules_management.png
  108. :align: center
  109. *Rules management UI*
  110. Note that the first rule (the advanced one) is not active.
  111. REST API
  112. --------
  113. The rules and echo parameters can also be managed by means of a REST API found at
  114. ``geoserver/rest/params-extractor``. Documentation for it is available in
  115. :api:`Swagger format <params-extractor.yaml>`
  116. Intercepting the security filters chain
  117. ---------------------------------------
  118. By default, the params-extractor module does not interact with the security authentication filters.
  119. This is because the params-extractor filter is called later in the GeoServer filters chain.
  120. If you want params-extractor to work before the security filter chain, you have to configure it as
  121. a standard servlet filter in the GeoServer WEB-INF/web.xml file.
  122. This can be done adding the following to your current web.xml (immediately after the ``Set Character Encoding`` filter) and restarting GeoServer:
  123. .. code-block:: xml
  124. <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
  125. <web-app>
  126. ...
  127. <filter>
  128. <filter-name>ExtractParams</filter-name>
  129. <filter-class>org.geoserver.params.extractor.Filter</filter-class>
  130. </filter>
  131. ...
  132. <filter-mapping>
  133. <filter-name>ExtractParams</filter-name>
  134. <url-pattern>/*</url-pattern>
  135. </filter-mapping>
  136. ...
  137. </web-app>