Przeglądaj źródła

!203 WebSecurityConfigurerAdapter 在Spring Security 5.7过时
Merge pull request !203 from 板砖/master

若依 3 lat temu
rodzic
commit
912f607062

+ 25 - 23
ruoyi-visual/ruoyi-monitor/src/main/java/com/ruoyi/modules/monitor/config/WebSecurityConfigurer.java

@@ -1,9 +1,10 @@
1
 package com.ruoyi.modules.monitor.config;
1
 package com.ruoyi.modules.monitor.config;
2
 
2
 
3
 import de.codecentric.boot.admin.server.config.AdminServerProperties;
3
 import de.codecentric.boot.admin.server.config.AdminServerProperties;
4
-import org.springframework.context.annotation.Configuration;
4
+import org.springframework.context.annotation.Bean;
5
 import org.springframework.security.config.annotation.web.builders.HttpSecurity;
5
 import org.springframework.security.config.annotation.web.builders.HttpSecurity;
6
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
6
+import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
7
+import org.springframework.security.web.SecurityFilterChain;
7
 import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
8
 import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
8
 
9
 
9
 /**
10
 /**
@@ -11,8 +12,8 @@ import org.springframework.security.web.authentication.SavedRequestAwareAuthenti
11
  * 
12
  * 
12
  * @author ruoyi
13
  * @author ruoyi
13
  */
14
  */
14
-@Configuration
15
-public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter
15
+@EnableWebSecurity
16
+public class WebSecurityConfigurer
16
 {
17
 {
17
     private final String adminContextPath;
18
     private final String adminContextPath;
18
 
19
 
@@ -21,29 +22,30 @@ public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter
21
         this.adminContextPath = adminServerProperties.getContextPath();
22
         this.adminContextPath = adminServerProperties.getContextPath();
22
     }
23
     }
23
 
24
 
24
-    @Override
25
-    protected void configure(HttpSecurity http) throws Exception
25
+    @Bean
26
+    public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception
26
     {
27
     {
27
         SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
28
         SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
28
         successHandler.setTargetUrlParameter("redirectTo");
29
         successHandler.setTargetUrlParameter("redirectTo");
29
         successHandler.setDefaultTargetUrl(adminContextPath + "/");
30
         successHandler.setDefaultTargetUrl(adminContextPath + "/");
30
 
31
 
31
-        http
32
-            .headers().frameOptions().disable()
33
-            .and().authorizeRequests()
34
-            .antMatchers(adminContextPath + "/assets/**"
35
-                , adminContextPath + "/login"
36
-                , adminContextPath + "/actuator/**"
37
-                , adminContextPath + "/instances/**"
38
-            ).permitAll()
39
-            .anyRequest().authenticated()
40
-            .and()
41
-            .formLogin().loginPage(adminContextPath + "/login")
42
-            .successHandler(successHandler).and()
43
-            .logout().logoutUrl(adminContextPath + "/logout")
44
-            .and()
45
-            .httpBasic().and()
46
-            .csrf()
47
-            .disable();
32
+        return httpSecurity
33
+                .headers().frameOptions().disable()
34
+                .and().authorizeRequests()
35
+                .antMatchers(adminContextPath + "/assets/**"
36
+                        , adminContextPath + "/login"
37
+                        , adminContextPath + "/actuator/**"
38
+                        , adminContextPath + "/instances/**"
39
+                ).permitAll()
40
+                .anyRequest().authenticated()
41
+                .and()
42
+                .formLogin().loginPage(adminContextPath + "/login")
43
+                .successHandler(successHandler).and()
44
+                .logout().logoutUrl(adminContextPath + "/logout")
45
+                .and()
46
+                .httpBasic().and()
47
+                .csrf()
48
+                .disable()
49
+                .build();
48
     }
50
     }
49
 }
51
 }