From 68d4b2d24c4ac5dd4add4780afd8b273fe08059a Mon Sep 17 00:00:00 2001
From: JEECG <445654970@qq.com>
Date: Tue, 7 Jul 2026 21:56:22 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9E=B6=E6=9E=84=E5=8D=87=E7=BA=A7springboot4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../jeecg-visual/jeecg-cloud-monitor/pom.xml | 5 +-
.../monitor/JeecgMonitorApplication.java | 7 +-
.../monitor/config/SecuritySecureConfig.java | 72 +++++++++----------
3 files changed, 42 insertions(+), 42 deletions(-)
diff --git a/jeecg-boot/jeecg-server-cloud/jeecg-visual/jeecg-cloud-monitor/pom.xml b/jeecg-boot/jeecg-server-cloud/jeecg-visual/jeecg-cloud-monitor/pom.xml
index 0acc55d6b..ebdf7f9a3 100644
--- a/jeecg-boot/jeecg-server-cloud/jeecg-visual/jeecg-cloud-monitor/pom.xml
+++ b/jeecg-boot/jeecg-server-cloud/jeecg-visual/jeecg-cloud-monitor/pom.xml
@@ -19,7 +19,7 @@
de.codecentric
spring-boot-admin-starter-server
- 3.5.2
+ 4.1.1
com.alibaba.cloud
@@ -59,6 +59,9 @@
org.springframework.boot
spring-boot-maven-plugin
+
+ org.jeecg.monitor.JeecgMonitorApplication
+
diff --git a/jeecg-boot/jeecg-server-cloud/jeecg-visual/jeecg-cloud-monitor/src/main/java/org/jeecg/monitor/JeecgMonitorApplication.java b/jeecg-boot/jeecg-server-cloud/jeecg-visual/jeecg-cloud-monitor/src/main/java/org/jeecg/monitor/JeecgMonitorApplication.java
index 4b5e9a716..e4c7bfb98 100644
--- a/jeecg-boot/jeecg-server-cloud/jeecg-visual/jeecg-cloud-monitor/src/main/java/org/jeecg/monitor/JeecgMonitorApplication.java
+++ b/jeecg-boot/jeecg-server-cloud/jeecg-visual/jeecg-cloud-monitor/src/main/java/org/jeecg/monitor/JeecgMonitorApplication.java
@@ -5,14 +5,13 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
- * 监控服务
- * @author zyf
- * @date: 2022/4/21 10:55
+ * @author scott
*/
@SpringBootApplication
@EnableAdminServer
public class JeecgMonitorApplication {
+
public static void main(String[] args) {
SpringApplication.run(JeecgMonitorApplication.class, args);
}
-}
\ No newline at end of file
+}
diff --git a/jeecg-boot/jeecg-server-cloud/jeecg-visual/jeecg-cloud-monitor/src/main/java/org/jeecg/monitor/config/SecuritySecureConfig.java b/jeecg-boot/jeecg-server-cloud/jeecg-visual/jeecg-cloud-monitor/src/main/java/org/jeecg/monitor/config/SecuritySecureConfig.java
index dda1672a3..05517100b 100644
--- a/jeecg-boot/jeecg-server-cloud/jeecg-visual/jeecg-cloud-monitor/src/main/java/org/jeecg/monitor/config/SecuritySecureConfig.java
+++ b/jeecg-boot/jeecg-server-cloud/jeecg-visual/jeecg-cloud-monitor/src/main/java/org/jeecg/monitor/config/SecuritySecureConfig.java
@@ -4,10 +4,14 @@ import de.codecentric.boot.admin.server.config.AdminServerProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.Customizer;
-import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.web.SecurityFilterChain;
-import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
-import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
+import org.springframework.security.config.web.server.ServerHttpSecurity;
+import org.springframework.security.web.server.SecurityWebFilterChain;
+import org.springframework.security.web.server.authentication.RedirectServerAuthenticationSuccessHandler;
+import org.springframework.security.web.server.authentication.ServerAuthenticationSuccessHandler;
+import org.springframework.security.web.server.authentication.logout.RedirectServerLogoutSuccessHandler;
+import org.springframework.security.web.server.authentication.logout.ServerLogoutSuccessHandler;
+
+import java.net.URI;
/**
* @author scott
@@ -15,49 +19,43 @@ import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
@Configuration
public class SecuritySecureConfig {
- private final String adminContextPath;
+ private final AdminServerProperties adminServer;
public SecuritySecureConfig(AdminServerProperties adminServerProperties) {
- this.adminContextPath = adminServerProperties.getContextPath();
+ this.adminServer = adminServerProperties;
}
@Bean
- public SecurityFilterChain configure(HttpSecurity http) throws Exception {
- // 登录成功处理类
- SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
- successHandler.setTargetUrlParameter("redirectTo");
- successHandler.setDefaultTargetUrl(adminContextPath + "/");
-
- http
- // authorizeRequests() 已废弃,使用 authorizeHttpRequests()
- .authorizeHttpRequests(authorize -> authorize
- //静态文件允许访问
- .requestMatchers(adminContextPath + "/assets/**").permitAll()
- //登录页面允许访问
- .requestMatchers(adminContextPath + "/login", "/css/**", "/js/**", "/image/*").permitAll()
- //其他所有请求需要登录
- .anyRequest().authenticated()
+ public SecurityWebFilterChain configure(ServerHttpSecurity http) {
+ return http
+ .authorizeExchange(authorize -> authorize
+ .pathMatchers(adminServer.path("/assets/**")).permitAll()
+ .pathMatchers(adminServer.path("/login")).permitAll()
+ .pathMatchers("/actuator/health/**").permitAll()
+ .anyExchange().authenticated()
)
- //登录页面配置,用于替换security默认页面
.formLogin(formLogin -> formLogin
- .loginPage(adminContextPath + "/login")
- .successHandler(successHandler)
+ .loginPage(adminServer.path("/login"))
+ .authenticationSuccessHandler(loginSuccessHandler(adminServer.path("/")))
)
- //登出页面配置,用于替换security默认页面
.logout(logout -> logout
- .logoutUrl(adminContextPath + "/logout")
+ .logoutUrl(adminServer.path("/logout"))
+ .logoutSuccessHandler(logoutSuccessHandler(adminServer.path("/login?logout")))
)
.httpBasic(Customizer.withDefaults())
- .csrf(csrf -> csrf
- .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
- .ignoringRequestMatchers(
- "/instances",
- "/actuator/**"
- )
- );
-
- return http.build();
-
+ .csrf(ServerHttpSecurity.CsrfSpec::disable)
+ .build();
}
-}
\ No newline at end of file
+ private ServerAuthenticationSuccessHandler loginSuccessHandler(String uri) {
+ RedirectServerAuthenticationSuccessHandler handler = new RedirectServerAuthenticationSuccessHandler();
+ handler.setLocation(URI.create(uri));
+ return handler;
+ }
+
+ private ServerLogoutSuccessHandler logoutSuccessHandler(String uri) {
+ RedirectServerLogoutSuccessHandler handler = new RedirectServerLogoutSuccessHandler();
+ handler.setLogoutSuccessUrl(URI.create(uri));
+ return handler;
+ }
+}