Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 1.25.x] [GWC-1344] Hide version info on embedded GWC home page (#1345) #1351

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -452,22 +452,26 @@ private void handleFrontPage(HttpServletRequest request, HttpServletResponse res
}

StringBuilder str = new StringBuilder();

String version = GeoWebCache.getVersion();
String commitId = GeoWebCache.getBuildRevision();
if (version == null) {
version = "{NO VERSION INFO IN MANIFEST}";
}
if (commitId == null) {
commitId = "{NO BUILD INFO IN MANIFEST}";
}

str.append("<html>\n"
+ ServletUtils.gwcHtmlHeader(baseUrl, "GWC Home")
+ "<body>\n"
+ ServletUtils.gwcHtmlLogoLink(baseUrl));
str.append("<h3>Welcome to GeoWebCache version " + version + ", build " + commitId + "</h3>\n");
str.append("<p><a href=\"http://geowebcache.org\">GeoWebCache</a> is an advanced tile cache for WMS servers.");
str.append("<h3>Welcome to GeoWebCache");
boolean isAdmin = this.securityDispatcher.isAdmin();
if (isAdmin) {
String version = GeoWebCache.getVersion();
String commitId = GeoWebCache.getBuildRevision();
if (version == null) {
version = "{NO VERSION INFO IN MANIFEST}";
}
if (commitId == null) {
commitId = "{NO BUILD INFO IN MANIFEST}";
}
str.append(" version ").append(version).append(", build ").append(commitId);
}
str.append("</h3>\n");
str.append(
"<p><a href=\"https://geowebcache.osgeo.org\">GeoWebCache</a> is an advanced tile cache for WMS servers. ");
str.append(
"It supports a large variety of protocols and formats, including WMS-C, WMTS, KML, Google Maps and Virtual Earth.</p>");
str.append("<h3>Automatically Generated Demos:</h3>\n");
Expand All @@ -477,25 +481,26 @@ private void handleFrontPage(HttpServletRequest request, HttpServletResponse res
str.append("<ul><li><a href=\""
+ baseUrl
+ "service/wmts?REQUEST=getcapabilities\">WMTS 1.0.0 GetCapabilities document</a></li>");
str.append("<li><a href=\"" + baseUrl + "service/tms/1.0.0\">TMS 1.0.0 document</a></li>");
str.append(
"<li><a href=\""
+ baseUrl
+ "service/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=getcapabilities&TILED=true\">WMS 1.1.1 GetCapabilities document</a></li>");
str.append("<li><a href=\"" + baseUrl + "service/tms/1.0.0\">TMS 1.0.0 document</a></li>");
str.append("<li>Note that the latter will only work with clients that are ");
str.append("<li>Note that the latter (WMS) will only work with clients that are ");
str.append("<a href=\"http://wiki.osgeo.org/wiki/WMS_Tiling_Client_Recommendation\">WMS-C capable</a>.</li>\n");
str.append("<li>Omitting tiled=true from the URL will omit the TileSet elements.</li></ul>\n");
if (runtimeStats != null) {
str.append("<h3>Runtime Statistics</h3>\n");
str.append(runtimeStats.getHTMLStats());
str.append("</table>\n");
}
if (!Boolean.parseBoolean(GeoWebCacheExtensions.getProperty("GEOWEBCACHE_HIDE_STORAGE_LOCATIONS"))) {
appendStorageLocations(str);
}

if (storageBroker != null) {
appendInternalCacheStats(str);
if (isAdmin) {
if (runtimeStats != null) {
str.append("<h3>Runtime Statistics</h3>\n");
str.append(runtimeStats.getHTMLStats());
str.append("</table>\n");
}
if (!Boolean.parseBoolean(GeoWebCacheExtensions.getProperty("GEOWEBCACHE_HIDE_STORAGE_LOCATIONS"))) {
appendStorageLocations(str);
}
if (storageBroker != null) {
appendInternalCacheStats(str);
}
}
str.append("</body></html>\n");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ public void checkSecurity(TileLayer layer, @Nullable BoundingBox extent, @Nullab
}
}

/**
* Checks if the current user is authenticated and is the administrator. Will return true if there are no active
* security filters.
*/
public boolean isAdmin() {
return getFilters().stream().allMatch(SecurityFilter::isAdmin);
}

@Override
public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ public interface SecurityFilter {
*/
public void checkSecurity(TileLayer layer, @Nullable BoundingBox extent, @Nullable SRS srs)
throws SecurityException, GeoWebCacheException;

/** Checks if the current user is authenticated and is the administrator. */
default boolean isAdmin() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
package org.geowebcache;

import static org.geowebcache.TestHelpers.hasStatus;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;

import java.util.Collections;
import javax.servlet.http.HttpServletResponse;
Expand Down Expand Up @@ -48,7 +50,28 @@ public class GeoWebCacheDispatcherTest {
public MockExtensionRule extensions = new MockExtensionRule();

@Test
public void testHomePage() throws Exception {
public void testHomePageUser() throws Exception {
String html = doTestHomePage(false);
assertThat(html, containsString("GWC Home"));
assertThat(html, containsString("Welcome to GeoWebCache"));
assertThat(html, not(containsString(" version ")));
assertThat(html, not(containsString(" build ")));
assertThat(html, not(containsString("Runtime Statistics")));
assertThat(html, not(containsString("Storage Locations")));
}

@Test
public void testHomePageAdmin() throws Exception {
String html = doTestHomePage(true);
assertThat(html, containsString("GWC Home"));
assertThat(html, containsString("Welcome to GeoWebCache"));
assertThat(html, containsString(" version "));
assertThat(html, containsString(" build "));
assertThat(html, containsString("Runtime Statistics"));
assertThat(html, containsString("Storage Locations"));
}

private String doTestHomePage(boolean isAdmin) throws Exception {
IMocksControl stubs = EasyMock.createControl(MockType.NICE);
TileLayerDispatcher tld = stubs.createMock("tld", TileLayerDispatcher.class);
GridSetBroker gsb = stubs.createMock("gsb", GridSetBroker.class);
Expand All @@ -59,6 +82,7 @@ public void testHomePage() throws Exception {
DefaultStorageFinder dfs = stubs.createMock("dfs", DefaultStorageFinder.class);
SecurityDispatcher secDisp = stubs.createMock("secDisp", SecurityDispatcher.class);

EasyMock.expect(secDisp.isAdmin()).andReturn(isAdmin);
EasyMock.expect(config.isRuntimeStatsEnabled()).andStubReturn(false);

MockHttpServletRequest request = new MockHttpServletRequest("GET", "/geowebcache/home");
Expand All @@ -79,6 +103,7 @@ public void testHomePage() throws Exception {
assertThat(response, hasStatus(HttpStatus.OK));

stubs.verify();
return response.getContentAsString();
}

@Test
Expand Down