Use the ServerProperties to add prefixes to paths
when server.servletPath is set we need to add prefixes to the security filter paths, and the /error path. Conflicts: spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementSecurityAutoConfiguration.java
This commit is contained in:
@@ -23,6 +23,7 @@ import javax.servlet.Servlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.actuate.web.BasicErrorController;
|
||||
import org.springframework.boot.actuate.web.ErrorController;
|
||||
@@ -36,6 +37,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplicat
|
||||
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
|
||||
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
|
||||
import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration.DefaultTemplateResolverConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
|
||||
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
|
||||
@@ -73,6 +75,9 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom
|
||||
@Value("${error.path:/error}")
|
||||
private String errorPath = "/error";
|
||||
|
||||
@Autowired
|
||||
private ServerProperties properties;
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(value = ErrorController.class, search = SearchStrategy.CURRENT)
|
||||
public BasicErrorController basicErrorController() {
|
||||
@@ -81,7 +86,8 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom
|
||||
|
||||
@Override
|
||||
public void customize(ConfigurableEmbeddedServletContainer container) {
|
||||
container.addErrorPages(new ErrorPage(this.errorPath));
|
||||
container.addErrorPages(new ErrorPage(this.properties.getServletPrefix()
|
||||
+ this.errorPath));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -41,6 +41,7 @@ import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration
|
||||
import org.springframework.boot.autoconfigure.security.SecurityPrequisite;
|
||||
import org.springframework.boot.autoconfigure.security.SecurityProperties;
|
||||
import org.springframework.boot.autoconfigure.security.SpringBootWebSecurityConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -122,6 +123,9 @@ public class ManagementSecurityAutoConfiguration {
|
||||
@Autowired
|
||||
private SecurityProperties security;
|
||||
|
||||
@Autowired
|
||||
private ServerProperties server;
|
||||
|
||||
@Override
|
||||
public void configure(WebSecurity builder) throws Exception {
|
||||
}
|
||||
@@ -145,7 +149,8 @@ public class ManagementSecurityAutoConfiguration {
|
||||
if (this.errorController != null) {
|
||||
ignored.add(normalizePath(this.errorController.getErrorPath()));
|
||||
}
|
||||
ignoring.antMatchers(ignored.toArray(new String[0]));
|
||||
String[] paths = this.server.getPathsArray(ignored);
|
||||
ignoring.antMatchers(paths);
|
||||
}
|
||||
|
||||
private String normalizePath(String errorPath) {
|
||||
@@ -180,6 +185,9 @@ public class ManagementSecurityAutoConfiguration {
|
||||
@Autowired
|
||||
private ManagementServerProperties management;
|
||||
|
||||
@Autowired
|
||||
private ServerProperties server;
|
||||
|
||||
@Autowired(required = false)
|
||||
private EndpointHandlerMapping endpointHandlerMapping;
|
||||
|
||||
@@ -194,6 +202,7 @@ public class ManagementSecurityAutoConfiguration {
|
||||
http.requiresChannel().anyRequest().requiresSecure();
|
||||
}
|
||||
http.exceptionHandling().authenticationEntryPoint(entryPoint());
|
||||
paths = this.server.getPathsArray(paths);
|
||||
http.requestMatchers().antMatchers(paths);
|
||||
http.authorizeRequests().anyRequest()
|
||||
.hasRole(this.management.getSecurity().getRole()) //
|
||||
|
||||
Reference in New Issue
Block a user