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

[GWC-1344] Hide version info on embedded GWC home page #1345

Merged
merged 1 commit into from
Jan 23, 2025
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,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
}
}

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know, if GWC is deployed stand-alone, there are indeed no SecurityFilter, the only implementation I'm aware of is in GeoServer (which you have updated accordingly in the GS counterpart).

I'm asking because I don't want to give the wrong impression in the GWC release notes... the commit message should probably be something along the lines of "Support hiding GWC version when integrated in GeoServer".
(we use the commit messages to build the GWC release notes)

* 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
Loading