tags: KeyOA-backend spring java rear end
WebSecurityConfigurerAdapterClass is a class often used in Spring Security, which is used to quickly configure WebSecurity. After upgrading to version 5.7, this class was abandoned, so some APIs provided could not be used. Provide what you need to do after upgrading Spring Security.
The original configuration class:
@Configuration
public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http.csrf().disable(); // omit other httpsecurity configuration
}
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/url");
}
}
WebSecurityConfigurerAdapter@Configuration
public class SpringSecurityConfig {
@Override
public void configure(HttpSecurity http) throws Exception {
http.csrf().disable(); // omit other httpsecurity configuration
}
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/url");
}
}
After completing the previous step, the abnormality of the Bean of the HTTPSECURITY type may not be found at runtime, so you need to add it to the original configuration class@EnableWebSecurityNote and modify the original configuration method at the same time. code show as below:
@Configuration
@EnableWebSecurity // If you can't find the abnormality of the HTTPSECURITY type bean, add this annotation
public class SpringSecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.csrf().disable();
return http.build();
}
@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
return (web) -> web.ignoring().antMatchers("/url");
}
}
AuthenticationManager(key step)After completing the above steps, there may still be an error in the authenticationManager type bean that may not be found. At this time, this bean needs to be exposed. The code is as follows:
@Configuration
@EnableWebSecurity // If you can't find the abnormality of the HTTPSECURITY type bean, add this annotation
public class SpringSecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.csrf().disable();
return http.build();
}
@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
return (web) -> web.ignoring().antMatchers("/url");
}
@Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration configuration) throws Exception {
return configuration.getAuthenticationManager();
}
}
At this time, the code can run successfully and no longer report an error.
Securing Web Applications with Spring Security [url]http://www.ibm.com/developerworks/cn/java/j-lo-springsecurity/[/url] SpringSecurity method layer 4 ways to use [url]http://blog.csdn.net/wyabc1986/a...
I. Overview Recently, using Spring security for fine-grained dynamic authority management, it took some time to sort out the process of spring security. In fact, spring security is mainly divided into...
2019 Unicorn Enterprise Heavy Recruitment Standards for Python Engineers >>> References Spring Security in Chinese Spring Security project Blog Spring Security Authentication Architecture Blo...
Database display: Get token interface: Note: Different multi-encoding methods, the following supports multi-encoding methods: ...
Add the following content in the custom authentication server configuration class...
First, the web.xml modification before fixing After modification Second, the applicationContext.xml modification Before namespace modification After the namespace is modified Second, the applicationCo...
1. Elasticsearch 6.3.0 1. Since the previously installed version 5.6.8 has no substantial use, that is to say there is no data. Therefore, no data migration operation is performed, only a new ES versi...
The latest version of Spring Security 5.7, still updated a lot of content. The previous WebSecurityConfigureradapter has been abandoned. When you use it, you can refer to the configuration file below....
☆.JDK version upgrade Spring Boot 1.x jdk 7 takes off Spring Boot 2.x jdk8 takes off ☆.Three-party library upgrade Spring Framework 5+ Tomcat 8.5+ Flyway 5+ Hibernate 5.2+ Thymeleaf 3+ More dependent ...
Spring boot 2.0 has been officially released. Compared with spring boot 1.x, there have been many changes. I will not introduce the specific changes in detail. I will introduce the upgrade of my sprin...