Browse Source

!203 WebSecurityConfigurerAdapter 在Spring Security 5.7过时

Merge pull request !203 from 板砖/master
master
若依 2 years ago committed by Gitee
parent
commit
912f607062
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
  1. 18
      ruoyi-visual/ruoyi-monitor/src/main/java/com/ruoyi/modules/monitor/config/WebSecurityConfigurer.java

18
ruoyi-visual/ruoyi-monitor/src/main/java/com/ruoyi/modules/monitor/config/WebSecurityConfigurer.java

@ -1,9 +1,10 @@
package com.ruoyi.modules.monitor.config; package com.ruoyi.modules.monitor.config;
import de.codecentric.boot.admin.server.config.AdminServerProperties; import de.codecentric.boot.admin.server.config.AdminServerProperties;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
/** /**
@ -11,8 +12,8 @@ import org.springframework.security.web.authentication.SavedRequestAwareAuthenti
* *
* @author ruoyi * @author ruoyi
*/ */
@Configuration @EnableWebSecurity
public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter public class WebSecurityConfigurer
{ {
private final String adminContextPath; private final String adminContextPath;
@ -21,14 +22,14 @@ public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter
this.adminContextPath = adminServerProperties.getContextPath(); this.adminContextPath = adminServerProperties.getContextPath();
} }
@Override @Bean
protected void configure(HttpSecurity http) throws Exception public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception
{ {
SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler(); SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
successHandler.setTargetUrlParameter("redirectTo"); successHandler.setTargetUrlParameter("redirectTo");
successHandler.setDefaultTargetUrl(adminContextPath + "/"); successHandler.setDefaultTargetUrl(adminContextPath + "/");
http return httpSecurity
.headers().frameOptions().disable() .headers().frameOptions().disable()
.and().authorizeRequests() .and().authorizeRequests()
.antMatchers(adminContextPath + "/assets/**" .antMatchers(adminContextPath + "/assets/**"
@ -44,6 +45,7 @@ public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter
.and() .and()
.httpBasic().and() .httpBasic().and()
.csrf() .csrf()
.disable(); .disable()
.build();
} }
} }

Loading…
Cancel
Save