diff --git a/geowebcache/core/src/main/java/org/geowebcache/GeoWebCacheDispatcher.java b/geowebcache/core/src/main/java/org/geowebcache/GeoWebCacheDispatcher.java
index 7aa51480b..57bebc3bc 100644
--- a/geowebcache/core/src/main/java/org/geowebcache/GeoWebCacheDispatcher.java
+++ b/geowebcache/core/src/main/java/org/geowebcache/GeoWebCacheDispatcher.java
@@ -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("\n"
+ ServletUtils.gwcHtmlHeader(baseUrl, "GWC Home")
+ "
\n"
+ ServletUtils.gwcHtmlLogoLink(baseUrl));
- str.append("Welcome to GeoWebCache version " + version + ", build " + commitId + "
\n");
+ str.append("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("
\n");
str.append(
"GeoWebCache is an advanced tile cache for WMS servers. ");
str.append(
@@ -486,17 +489,18 @@ private void handleFrontPage(HttpServletRequest request, HttpServletResponse res
str.append("
Note that the latter (WMS) will only work with clients that are ");
str.append("WMS-C capable.\n");
str.append("Omitting tiled=true from the URL will omit the TileSet elements.\n");
- if (runtimeStats != null) {
- str.append("Runtime Statistics
\n");
- str.append(runtimeStats.getHTMLStats());
- str.append("\n");
- }
- if (!Boolean.parseBoolean(GeoWebCacheExtensions.getProperty("GEOWEBCACHE_HIDE_STORAGE_LOCATIONS"))) {
- appendStorageLocations(str);
- }
-
- if (storageBroker != null) {
- appendInternalCacheStats(str);
+ if (isAdmin) {
+ if (runtimeStats != null) {
+ str.append("Runtime Statistics
\n");
+ str.append(runtimeStats.getHTMLStats());
+ str.append("\n");
+ }
+ if (!Boolean.parseBoolean(GeoWebCacheExtensions.getProperty("GEOWEBCACHE_HIDE_STORAGE_LOCATIONS"))) {
+ appendStorageLocations(str);
+ }
+ if (storageBroker != null) {
+ appendInternalCacheStats(str);
+ }
}
str.append("\n");
diff --git a/geowebcache/core/src/main/java/org/geowebcache/filter/security/SecurityDispatcher.java b/geowebcache/core/src/main/java/org/geowebcache/filter/security/SecurityDispatcher.java
index 2fb3a0f1f..d31bfcb95 100644
--- a/geowebcache/core/src/main/java/org/geowebcache/filter/security/SecurityDispatcher.java
+++ b/geowebcache/core/src/main/java/org/geowebcache/filter/security/SecurityDispatcher.java
@@ -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;
diff --git a/geowebcache/core/src/main/java/org/geowebcache/filter/security/SecurityFilter.java b/geowebcache/core/src/main/java/org/geowebcache/filter/security/SecurityFilter.java
index cf8e77336..e47fcc436 100644
--- a/geowebcache/core/src/main/java/org/geowebcache/filter/security/SecurityFilter.java
+++ b/geowebcache/core/src/main/java/org/geowebcache/filter/security/SecurityFilter.java
@@ -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;
+ }
}
diff --git a/geowebcache/core/src/test/java/org/geowebcache/GeoWebCacheDispatcherTest.java b/geowebcache/core/src/test/java/org/geowebcache/GeoWebCacheDispatcherTest.java
index a4f403f29..cd50af031 100644
--- a/geowebcache/core/src/test/java/org/geowebcache/GeoWebCacheDispatcherTest.java
+++ b/geowebcache/core/src/test/java/org/geowebcache/GeoWebCacheDispatcherTest.java
@@ -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;
@@ -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);
@@ -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");
@@ -79,6 +103,7 @@ public void testHomePage() throws Exception {
assertThat(response, hasStatus(HttpStatus.OK));
stubs.verify();
+ return response.getContentAsString();
}
@Test