From 1b706f4a4c1bd340dd8648827accbc74c3ecc5c3 Mon Sep 17 00:00:00 2001 From: javahongxi Date: Thu, 13 Aug 2020 07:52:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AF=E5=9C=A8=E9=9D=9EWeb=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../whatsmars-boot-sample-actuator/pom.xml | 1 + .../actuator/ActuatorAutoConfiguration.java | 9 ++++++- .../actuator/filter/ActuatorFilter.java | 24 +++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 whatsmars-spring-boot-samples/whatsmars-boot-sample-actuator/src/main/java/org/hongxi/whatsmars/boot/sample/actuator/filter/ActuatorFilter.java diff --git a/whatsmars-spring-boot-samples/whatsmars-boot-sample-actuator/pom.xml b/whatsmars-spring-boot-samples/whatsmars-boot-sample-actuator/pom.xml index 917d2842..fb8fe35c 100644 --- a/whatsmars-spring-boot-samples/whatsmars-boot-sample-actuator/pom.xml +++ b/whatsmars-spring-boot-samples/whatsmars-boot-sample-actuator/pom.xml @@ -18,6 +18,7 @@ org.springframework.boot spring-boot-starter-web + true org.springframework.boot diff --git a/whatsmars-spring-boot-samples/whatsmars-boot-sample-actuator/src/main/java/org/hongxi/whatsmars/boot/sample/actuator/ActuatorAutoConfiguration.java b/whatsmars-spring-boot-samples/whatsmars-boot-sample-actuator/src/main/java/org/hongxi/whatsmars/boot/sample/actuator/ActuatorAutoConfiguration.java index cb669145..6c045c88 100644 --- a/whatsmars-spring-boot-samples/whatsmars-boot-sample-actuator/src/main/java/org/hongxi/whatsmars/boot/sample/actuator/ActuatorAutoConfiguration.java +++ b/whatsmars-spring-boot-samples/whatsmars-boot-sample-actuator/src/main/java/org/hongxi/whatsmars/boot/sample/actuator/ActuatorAutoConfiguration.java @@ -1,5 +1,6 @@ package org.hongxi.whatsmars.boot.sample.actuator; +import org.hongxi.whatsmars.boot.sample.actuator.filter.ActuatorFilter; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -10,15 +11,21 @@ import org.springframework.security.config.annotation.web.WebSecurityConfigurer; * Created by shenhongxi on 2020/7/17. */ @Configuration -@ConditionalOnWebApplication public class ActuatorAutoConfiguration { @Order(99) @Bean + @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) public WebSecurityConfigurer standardWebSecurityConfigurer() { return new StandardWebSecurityConfigurer(); } + @Bean + @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) + public ActuatorFilter actuatorFilter() { + return new ActuatorFilter(); + } + @Bean public ActuatorReporter actuatorReporter() { return new ActuatorReporter(); diff --git a/whatsmars-spring-boot-samples/whatsmars-boot-sample-actuator/src/main/java/org/hongxi/whatsmars/boot/sample/actuator/filter/ActuatorFilter.java b/whatsmars-spring-boot-samples/whatsmars-boot-sample-actuator/src/main/java/org/hongxi/whatsmars/boot/sample/actuator/filter/ActuatorFilter.java new file mode 100644 index 00000000..8f4c4a02 --- /dev/null +++ b/whatsmars-spring-boot-samples/whatsmars-boot-sample-actuator/src/main/java/org/hongxi/whatsmars/boot/sample/actuator/filter/ActuatorFilter.java @@ -0,0 +1,24 @@ +package org.hongxi.whatsmars.boot.sample.actuator.filter; + +import org.springframework.http.HttpStatus; +import org.springframework.web.filter.OncePerRequestFilter; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * Created by shenhongxi on 2020/8/13. + */ +public class ActuatorFilter extends OncePerRequestFilter { + @Override + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { +// if (request.getServletPath().startsWith("/actuator")) { +// response.sendError(HttpStatus.FORBIDDEN.value()); +// } else { +// filterChain.doFilter(request, response); +// } + } +} -- GitLab