Skip to content

Commit ac0a112

Browse files
committed
[GWC-1344] Hide version info on GWC home page
1 parent 76c34e0 commit ac0a112

File tree

4 files changed

+65
-23
lines changed

4 files changed

+65
-23
lines changed

geowebcache/core/src/main/java/org/geowebcache/GeoWebCacheDispatcher.java

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -452,21 +452,24 @@ private void handleFrontPage(HttpServletRequest request, HttpServletResponse res
452452
}
453453

454454
StringBuilder str = new StringBuilder();
455-
456-
String version = GeoWebCache.getVersion();
457-
String commitId = GeoWebCache.getBuildRevision();
458-
if (version == null) {
459-
version = "{NO VERSION INFO IN MANIFEST}";
460-
}
461-
if (commitId == null) {
462-
commitId = "{NO BUILD INFO IN MANIFEST}";
463-
}
464-
465455
str.append("<html>\n"
466456
+ ServletUtils.gwcHtmlHeader(baseUrl, "GWC Home")
467457
+ "<body>\n"
468458
+ ServletUtils.gwcHtmlLogoLink(baseUrl));
469-
str.append("<h3>Welcome to GeoWebCache version " + version + ", build " + commitId + "</h3>\n");
459+
str.append("<h3>Welcome to GeoWebCache");
460+
boolean isAdmin = this.securityDispatcher.isAdmin();
461+
if (isAdmin) {
462+
String version = GeoWebCache.getVersion();
463+
String commitId = GeoWebCache.getBuildRevision();
464+
if (version == null) {
465+
version = "{NO VERSION INFO IN MANIFEST}";
466+
}
467+
if (commitId == null) {
468+
commitId = "{NO BUILD INFO IN MANIFEST}";
469+
}
470+
str.append(" version ").append(version).append(", build ").append(commitId);
471+
}
472+
str.append("</h3>\n");
470473
str.append(
471474
"<p><a href=\"https://geowebcache.osgeo.org\">GeoWebCache</a> is an advanced tile cache for WMS servers. ");
472475
str.append(
@@ -486,17 +489,18 @@ private void handleFrontPage(HttpServletRequest request, HttpServletResponse res
486489
str.append("<li>Note that the latter (WMS) will only work with clients that are ");
487490
str.append("<a href=\"http://wiki.osgeo.org/wiki/WMS_Tiling_Client_Recommendation\">WMS-C capable</a>.</li>\n");
488491
str.append("<li>Omitting tiled=true from the URL will omit the TileSet elements.</li></ul>\n");
489-
if (runtimeStats != null) {
490-
str.append("<h3>Runtime Statistics</h3>\n");
491-
str.append(runtimeStats.getHTMLStats());
492-
str.append("</table>\n");
493-
}
494-
if (!Boolean.parseBoolean(GeoWebCacheExtensions.getProperty("GEOWEBCACHE_HIDE_STORAGE_LOCATIONS"))) {
495-
appendStorageLocations(str);
496-
}
497-
498-
if (storageBroker != null) {
499-
appendInternalCacheStats(str);
492+
if (isAdmin) {
493+
if (runtimeStats != null) {
494+
str.append("<h3>Runtime Statistics</h3>\n");
495+
str.append(runtimeStats.getHTMLStats());
496+
str.append("</table>\n");
497+
}
498+
if (!Boolean.parseBoolean(GeoWebCacheExtensions.getProperty("GEOWEBCACHE_HIDE_STORAGE_LOCATIONS"))) {
499+
appendStorageLocations(str);
500+
}
501+
if (storageBroker != null) {
502+
appendInternalCacheStats(str);
503+
}
500504
}
501505
str.append("</body></html>\n");
502506

geowebcache/core/src/main/java/org/geowebcache/filter/security/SecurityDispatcher.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ public void checkSecurity(TileLayer layer, @Nullable BoundingBox extent, @Nullab
7373
}
7474
}
7575

76+
/**
77+
* Checks if the current user is authenticated and is the administrator. Will return true if there are no active
78+
* security filters.
79+
*/
80+
public boolean isAdmin() {
81+
return getFilters().stream().allMatch(SecurityFilter::isAdmin);
82+
}
83+
7684
@Override
7785
public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException {
7886
this.applicationContext = applicationContext;

geowebcache/core/src/main/java/org/geowebcache/filter/security/SecurityFilter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ public interface SecurityFilter {
2828
*/
2929
public void checkSecurity(TileLayer layer, @Nullable BoundingBox extent, @Nullable SRS srs)
3030
throws SecurityException, GeoWebCacheException;
31+
32+
/** Checks if the current user is authenticated and is the administrator. */
33+
default boolean isAdmin() {
34+
return false;
35+
}
3136
}

geowebcache/core/src/test/java/org/geowebcache/GeoWebCacheDispatcherTest.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
import static org.geowebcache.TestHelpers.hasStatus;
1717
import static org.hamcrest.MatcherAssert.assertThat;
18+
import static org.hamcrest.Matchers.containsString;
19+
import static org.hamcrest.Matchers.not;
1820

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

5052
@Test
51-
public void testHomePage() throws Exception {
53+
public void testHomePageUser() throws Exception {
54+
String html = doTestHomePage(false);
55+
assertThat(html, containsString("GWC Home"));
56+
assertThat(html, containsString("Welcome to GeoWebCache"));
57+
assertThat(html, not(containsString(" version ")));
58+
assertThat(html, not(containsString(" build ")));
59+
assertThat(html, not(containsString("Runtime Statistics")));
60+
assertThat(html, not(containsString("Storage Locations")));
61+
}
62+
63+
@Test
64+
public void testHomePageAdmin() throws Exception {
65+
String html = doTestHomePage(true);
66+
assertThat(html, containsString("GWC Home"));
67+
assertThat(html, containsString("Welcome to GeoWebCache"));
68+
assertThat(html, containsString(" version "));
69+
assertThat(html, containsString(" build "));
70+
assertThat(html, containsString("Runtime Statistics"));
71+
assertThat(html, containsString("Storage Locations"));
72+
}
73+
74+
private String doTestHomePage(boolean isAdmin) throws Exception {
5275
IMocksControl stubs = EasyMock.createControl(MockType.NICE);
5376
TileLayerDispatcher tld = stubs.createMock("tld", TileLayerDispatcher.class);
5477
GridSetBroker gsb = stubs.createMock("gsb", GridSetBroker.class);
@@ -59,6 +82,7 @@ public void testHomePage() throws Exception {
5982
DefaultStorageFinder dfs = stubs.createMock("dfs", DefaultStorageFinder.class);
6083
SecurityDispatcher secDisp = stubs.createMock("secDisp", SecurityDispatcher.class);
6184

85+
EasyMock.expect(secDisp.isAdmin()).andReturn(isAdmin);
6286
EasyMock.expect(config.isRuntimeStatsEnabled()).andStubReturn(false);
6387

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

81105
stubs.verify();
106+
return response.getContentAsString();
82107
}
83108

84109
@Test

0 commit comments

Comments
 (0)