Skip to content

Fail fast when both management 'base path' and 'endpoint mapping' are set to '/' #45251

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

Closed
wants to merge 1 commit into from
Closed
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 @@ -69,6 +69,7 @@
*
* @author Andy Wilkinson
* @author Phillip Webb
* @author Yongjun Hong
* @since 2.0.0
*/
@ManagementContextConfiguration(proxyBeanMethods = false)
Expand All @@ -93,6 +94,18 @@ public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(WebEndpoint
allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
String basePath = webEndpointProperties.getBasePath();
EndpointMapping endpointMapping = new EndpointMapping(basePath);

if (basePath.isEmpty() && ManagementPortType.get(environment).equals(ManagementPortType.SAME)) {
for (ExposableWebEndpoint endpoint : webEndpoints) {
if ("/".equals(endpoint.getRootPath())) {
throw new IllegalStateException(
"Management endpoints and endpoint path are both mapped to '/' on the server port which will "
+ "block access to other endpoints. Please use a different path for management endpoints or "
+ "map them to a dedicated management port.");
}
}
}

boolean shouldRegisterLinksMapping = shouldRegisterLinksMapping(webEndpointProperties, environment, basePath);
return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes,
corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package smoketest.actuator;

import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.BeanCreationException;
import org.springframework.boot.SpringApplication;

import static org.assertj.core.api.Assertions.assertThatThrownBy;

/**
* Verifies that an exception is thrown when management and server endpoint paths
* conflict.
*
* @author Yongjun Hong
*/
class ManagementEndpointConflictSmokeTest {

@Test
void shouldThrowExceptionWhenManagementAndServerPathsConflict() {
assertThatThrownBy(() -> {
SpringApplication.run(SampleActuatorApplication.class, "--management.endpoints.web.base-path=/",
"--management.endpoints.web.path-mapping.health=/");
}).isInstanceOf(BeanCreationException.class)
.hasMessageContaining("Management endpoints and endpoint path are both mapped to '/'");
}

}
Loading