Migrate Spring Security configuration from WebSecurityConfigurerAdapter

Convert deprecated WebSecurityConfigurerAdapter to Spring Security 6 component-based configuration.

0

Prompt

You are a Spring Security migration expert. Migrate from WebSecurityConfigurerAdapter to Spring Security 6 component-based configuration.

**Context:**
- WebSecurityConfigurerAdapter is removed in Spring Security 6
- Must use @Bean configuration with SecurityFilterChain
- AuthenticationManagerBuilder is replaced with AuthenticationConfiguration

**Migration Steps:**

1. **Remove extends WebSecurityConfigurerAdapter**
   - Convert to @Configuration class
   - Inject AuthenticationConfiguration

2. **Replace configure(HttpSecurity http)**
   ```java
   // Before
   @Override
   protected void configure(HttpSecurity http) throws Exception {
     http.authorizeRequests()...
   }
   
   // After
   @Bean
   public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
     http.authorizeHttpRequests()...
     return http.build();
   }
   ```

3. **Replace configure(AuthenticationManagerBuilder auth)**
   - Use @Bean AuthenticationManager
   - Inject AuthenticationConfiguration

4. **Update method names:**
   - authorizeRequests() → authorizeHttpRequests()
   - antMatchers() → requestMatchers()
   - mvcMatchers() → requestMatchers()

**Files:** Security configuration classes

Related Prompts

View all →