Spring Security upgrade to 5.7.x

tags: KeyOA-backend  spring  java  rear end

Spring Security upgrade to 5.7.x

Problem Description

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.

solution

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");
		}
}

The original configuration class cancels inheritanceWebSecurityConfigurerAdapter

@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");
		}
}

Re -configure HTTPSECURITY and WebSecurity

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");
    }
}

ConfigurationAuthenticationManager(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.

Intelligent Recommendation

Spring Security 3.2.x configuration

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...

Analysis of Spring Security 4.x

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...

Memo-Spring Security 4.x

2019 Unicorn Enterprise Heavy Recruitment Standards for Python Engineers >>> References Spring Security in Chinese Spring Security project Blog Spring Security Authentication Architecture Blo...

spring boot2.x configure spring security password

Database display: Get token interface: Note: Different multi-encoding methods, the following supports multi-encoding methods:  ...

Token refresh interface 401 after Spring Security upgrade

Add the following content in the custom authentication server configuration class...

More Recommendation

Spring 2.x upgrade to spring 4.x record

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...

Remember an elasticsearch cluster upgrade and x-pack security practices

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...

Spring Security 5.7 latest configuration details (can be used directly), WebSecurityConfigureradapter

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....

Spring Boot 1.x Upgrade to Spring Boot 2.0 Migration Guide

☆.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 ...

Upgrade from spring boot 1.x to spring boot 2.0

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...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top