Skip to content

Commit

Permalink
Add support for additional paths for HomepageForwardingFilterConfig (#…
Browse files Browse the repository at this point in the history
…2136)

* Add support for excluding additional paths for HomepageForwardingFilterConfig

* chore: checkstyle + imports

Co-authored-by: Stephan Köninger <[email protected]>
  • Loading branch information
genuss and SteKoe authored Oct 17, 2022
1 parent 1acf87d commit 3990e05
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ public HomepageForwardingFilterConfig homepageForwardingFilterConfig() throws IO
.collect(Collectors.toList());
routesIncludes.add("");

List<String> routesExcludes = DEFAULT_UI_ROUTE_EXCLUDES.stream()
List<String> routesExcludes = Stream
.concat(DEFAULT_UI_ROUTE_EXCLUDES.stream(), this.adminUi.getAdditionalRouteExcludes().stream())
.map((path) -> webfluxBasePathSet ? webFluxBasePath + path : this.adminServer.path(path))
.collect(Collectors.toList());

Expand Down Expand Up @@ -217,8 +218,9 @@ public HomepageForwardingFilterConfig homepageForwardingFilterConfig() throws IO
.scan(this.adminUi.getExtensionResourceLocations());
List<String> routesIncludes = Stream.concat(DEFAULT_UI_ROUTES.stream(), extensionRoutes.stream())
.map(this.adminServer::path).collect(Collectors.toList());
List<String> routesExcludes = DEFAULT_UI_ROUTE_EXCLUDES.stream().map(this.adminServer::path)
.collect(Collectors.toList());
List<String> routesExcludes = Stream
.concat(DEFAULT_UI_ROUTE_EXCLUDES.stream(), this.adminUi.getAdditionalRouteExcludes().stream())
.map(this.adminServer::path).collect(Collectors.toList());

return new HomepageForwardingFilterConfig(homepage, routesIncludes, routesExcludes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ public class AdminServerUiProperties {

private PollTimer pollTimer = new PollTimer();

/**
* Additional routes to exclude from home page redirecting filter. Requests to these
* routes will not redirected to home page
*/
private List<String> additionalRouteExcludes = new ArrayList<>();

@lombok.Data
public static class PollTimer {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public class ReactiveAdminServerUiAutoConfigurationAdminContextPathTest
protected ReactiveWebApplicationContextRunner getContextRunner() {
return new ReactiveWebApplicationContextRunner()
.withPropertyValues("--spring.boot.admin.ui.available-languages=de",
"--spring.boot.admin.contextPath=test")
"--spring.boot.admin.contextPath=test",
"--spring.boot.admin.ui.additional-route-excludes[0]=/instances/*/actuator/some-extension/**")
.withBean(AdminServerProperties.class).withBean(WebFluxProperties.class)
.withConfiguration(AutoConfigurations.of(AdminServerUiAutoConfiguration.class));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public class ReactiveAdminServerUiAutoConfigurationBothPathsTest extends Reactiv
protected ReactiveWebApplicationContextRunner getContextRunner() {
return new ReactiveWebApplicationContextRunner()
.withPropertyValues("--spring.boot.admin.ui.available-languages=de",
"--spring.boot.admin.contextPath=different", "--spring.webflux.base-path=test")
"--spring.boot.admin.contextPath=different", "--spring.webflux.base-path=test",
"--spring.boot.admin.ui.additional-route-excludes[0]=/instances/*/actuator/some-extension/**")
.withBean(AdminServerProperties.class).withBean(WebFluxProperties.class)
.withConfiguration(AutoConfigurations.of(AdminServerUiAutoConfiguration.class));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public abstract class ReactiveAdminServerUiAutoConfigurationTest {

@ParameterizedTest
@CsvSource({ "/test/extensions/myextension", "/test/instances/1/actuator/heapdump",
"/test/instances/1/actuator/logfile" })
"/test/instances/1/actuator/logfile", "/test/instances/1/actuator/some-extension/file.html" })
public void contextPathIsRespectedInExcludedRoutes(String routeExcludes) {
MockServerHttpRequest serverHttpRequest = MockServerHttpRequest.get(routeExcludes)
.header(HttpHeaders.ACCEPT, MediaType.TEXT_HTML_VALUE).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public class ReactiveAdminServerUiAutoConfigurationWebfluxBasePathTest
@Override
protected ReactiveWebApplicationContextRunner getContextRunner() {
return new ReactiveWebApplicationContextRunner()
.withPropertyValues("--spring.boot.admin.ui.available-languages=de", "--spring.webflux.base-path=test")
.withPropertyValues("--spring.boot.admin.ui.available-languages=de", "--spring.webflux.base-path=test",
"--spring.boot.admin.ui.additional-route-excludes[0]=/instances/*/actuator/some-extension/**")
.withBean(AdminServerProperties.class).withBean(WebFluxProperties.class)
.withConfiguration(AutoConfigurations.of(AdminServerUiAutoConfiguration.class));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@
public class ServletAdminServerUiAutoConfigurationTest implements WithAssertions {

private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
.withPropertyValues("--spring.boot.admin.ui.available-languages=de", "--spring.boot.admin.contextPath=test")
.withPropertyValues("--spring.boot.admin.ui.available-languages=de", "--spring.boot.admin.contextPath=test",
"--spring.boot.admin.ui.additional-route-excludes[0]=/instances/*/actuator/some-extension/**")
.withBean(AdminServerProperties.class)
.withConfiguration(AutoConfigurations.of(AdminServerUiAutoConfiguration.class));

@ParameterizedTest
@CsvSource({ "/test/extensions/myextension", "/test/instances/1/actuator/heapdump",
"/test/instances/1/actuator/logfile" })
"/test/instances/1/actuator/logfile", "/test/instances/1/actuator/some-extension/file.html" })
public void contextPathIsRespectedInExcludedRoutes(String routeExcludes) {
MockHttpServletRequest httpServletRequest = spy(new MockHttpServletRequest("GET", routeExcludes));
httpServletRequest.addHeader(HttpHeaders.ACCEPT, MediaType.TEXT_HTML_VALUE);
Expand Down

0 comments on commit 3990e05

Please sign in to comment.