Skip to content

Commit ee4a9ed

Browse files
authored
Allow parameter filters to be private and not exposed in capabilities OL preview and the like (#1545)
1 parent 8ada171 commit ee4a9ed

6 files changed

Lines changed: 31 additions & 1 deletion

File tree

geowebcache/core/src/main/java/org/geowebcache/demo/Demo.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,9 @@ private static String makeModifiableParameters(TileLayer tl) {
406406
doc.append("<table>\n");
407407
for (ParameterFilter pf : parameterFilters) {
408408
Assert.notNull(pf, "The parameter filter must be non null");
409+
if (!pf.isUserVisible()) {
410+
continue;
411+
}
409412
String key = pf.getKey();
410413
String defaultValue = pf.getDefaultValue();
411414
List<String> legalValues = pf.getLegalValues();

geowebcache/core/src/main/java/org/geowebcache/filter/parameters/ParameterFilter.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ public String getKey() {
5656
return key;
5757
}
5858

59+
/**
60+
* Whether this filter should be shown to clients in user-facing surfaces (preview, seed form, WMS/WMTS
61+
* capabilities). Synthetic filters that exist only to partition the cache should return {@code false} so they stay
62+
* out of those surfaces while still taking part in cache key computation. One example of such a parameter is an
63+
* internal filter matching the current security setup, or whatever other machinery might change the contents of a
64+
* tile (e.g., a dispatcher callback clipping rasters as a home-grown security system).
65+
*/
66+
public boolean isUserVisible() {
67+
return true;
68+
}
69+
5970
/** Get the default value to use if the parameter is not specified. */
6071
public String getDefaultValue() {
6172
if (defaultValue == null) return "";

geowebcache/rest/src/main/java/org/geowebcache/rest/service/FormService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ private void makeModifiableParameters(StringBuilder doc, TileLayer tl) {
337337
doc.append("<table>");
338338
for (ParameterFilter pf : parameterFilters) {
339339
Assert.notNull(pf, "Parameter filter must be non null");
340+
if (!pf.isUserVisible()) {
341+
continue;
342+
}
340343
String key = pf.getKey();
341344
String defaultValue = pf.getDefaultValue();
342345
List<String> legalValues = pf.getLegalValues();

geowebcache/wms/src/main/java/org/geowebcache/service/wms/WMSGetCapabilities.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,9 @@ private void capabilityLayerInner(XMLBuilder xml, TileLayer layer) throws GeoWeb
542542
StringBuilder dims = new StringBuilder();
543543
StringBuilder extents = new StringBuilder();
544544
for (ParameterFilter parameterFilter : layer.getParameterFilters()) {
545+
if (!parameterFilter.isUserVisible()) {
546+
continue;
547+
}
545548
if (parameterFilter instanceof WMSDimensionProvider provider) {
546549
provider.appendDimensionElement(dims, " ");
547550
provider.appendExtentElement(extents, " ");

geowebcache/wmts/src/main/java/org/geowebcache/service/wmts/WMTSGetCapabilities.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,11 @@ private void layer(XMLBuilder xml, TileLayer layer, String baseurl, Set<GridSet>
470470
}
471471
}
472472

473-
// We need the filters for styles and dimensions
473+
// We need the filters for styles and dimensions; drop synthetic, non user-visible ones (e.g. security)
474474
List<ParameterFilter> filters = layer.getParameterFilters();
475+
if (filters != null) {
476+
filters = filters.stream().filter(ParameterFilter::isUserVisible).toList();
477+
}
475478

476479
layerStyles(xml, layer, filters);
477480

geowebcache/wmts/src/test/java/org/geowebcache/service/wmts/WMTSServiceTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@ public void testGetCapUnboundedStyleFilter() throws Exception {
755755
List<String> gridSetNames = Arrays.asList("GlobalCRS84Pixel", "GlobalCRS84Scale", "EPSG:4326");
756756

757757
ParameterFilter styleFilter = mock(ParameterFilter.class);
758+
when(styleFilter.isUserVisible()).thenReturn(true);
758759
when(styleFilter.getKey()).thenReturn("STYLES");
759760
when(styleFilter.getDefaultValue()).thenReturn("Foo");
760761
when(styleFilter.getLegalValues()).thenReturn(null);
@@ -813,6 +814,7 @@ public void testGetCapEmptyStyleFilter() throws Exception {
813814
List<String> gridSetNames = Arrays.asList("GlobalCRS84Pixel", "GlobalCRS84Scale", "EPSG:4326");
814815

815816
ParameterFilter styleFilter = mock(ParameterFilter.class);
817+
when(styleFilter.isUserVisible()).thenReturn(true);
816818
when(styleFilter.getKey()).thenReturn("STYLES");
817819
when(styleFilter.getDefaultValue()).thenReturn("Foo");
818820
when(styleFilter.getLegalValues()).thenReturn(Collections.emptyList());
@@ -871,6 +873,7 @@ public void testGetCapMultipleStyles() throws Exception {
871873
List<String> gridSetNames = Arrays.asList("GlobalCRS84Pixel", "GlobalCRS84Scale", "EPSG:4326");
872874

873875
ParameterFilter styleFilter = mock(ParameterFilter.class);
876+
when(styleFilter.isUserVisible()).thenReturn(true);
874877
when(styleFilter.getKey()).thenReturn("STYLES");
875878
when(styleFilter.getDefaultValue()).thenReturn("Foo");
876879
when(styleFilter.getLegalValues()).thenReturn(Arrays.asList("Foo", "Bar", "Baz"));
@@ -972,16 +975,19 @@ public void testGetCapWithMultipleDimensions() throws Exception {
972975
List<String> gridSetNames = Arrays.asList("GlobalCRS84Pixel", "GlobalCRS84Scale", "EPSG:4326");
973976

974977
ParameterFilter styleFilter = mock(ParameterFilter.class);
978+
when(styleFilter.isUserVisible()).thenReturn(true);
975979
when(styleFilter.getKey()).thenReturn("STYLES");
976980
when(styleFilter.getDefaultValue()).thenReturn("Foo");
977981
when(styleFilter.getLegalValues()).thenReturn(Arrays.asList("Foo", "Bar", "Baz"));
978982

979983
ParameterFilter elevationDimension = mock(ParameterFilter.class);
984+
when(elevationDimension.isUserVisible()).thenReturn(true);
980985
when(elevationDimension.getKey()).thenReturn("elevation");
981986
when(elevationDimension.getDefaultValue()).thenReturn("0");
982987
when(elevationDimension.getLegalValues()).thenReturn(Arrays.asList("0", "200", "400", "600"));
983988

984989
ParameterFilter timeDimension = mock(ParameterFilter.class);
990+
when(timeDimension.isUserVisible()).thenReturn(true);
985991
when(timeDimension.getKey()).thenReturn("time");
986992
when(timeDimension.getDefaultValue()).thenReturn("2016-02-23T03:00:00.00");
987993
when(timeDimension.getLegalValues()).thenReturn(Collections.emptyList());
@@ -1049,6 +1055,7 @@ public void testGetTileWithStyle() throws Exception {
10491055
List<String> gridSetNames = Arrays.asList("GlobalCRS84Pixel", "GlobalCRS84Scale", "EPSG:4326");
10501056

10511057
ParameterFilter styleFilter = mock(ParameterFilter.class);
1058+
when(styleFilter.isUserVisible()).thenReturn(true);
10521059
when(styleFilter.getKey()).thenReturn("STYLES");
10531060
when(styleFilter.getDefaultValue()).thenReturn("Foo");
10541061
when(styleFilter.getLegalValues()).thenReturn(Arrays.asList("Foo", "Bar", "Baz"));

0 commit comments

Comments
 (0)