Skip to content

Commit

Permalink
[GWC-1344] Hide version info on embedded GWC home page (#1345)
Browse files Browse the repository at this point in the history
  • Loading branch information
sikeoka authored Jan 23, 2025
1 parent c37b733 commit 034162e
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -452,21 +452,24 @@ 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("<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(
Expand All @@ -486,17 +489,18 @@ private void handleFrontPage(HttpServletRequest request, HttpServletResponse res
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 @@ -15,6 +15,8 @@

import static org.geowebcache.TestHelpers.hasStatus;
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

0 comments on commit 034162e

Please sign in to comment.