1

In my project when I am trying to define the bean for AuthenticationManager by overriding the AuthenticationManagerBean() method it is showing the below error,

The method authenticationManagerBean() of type SecurityConfiguration must override or implement a supertype method

While the method I am defining is given below,

 @Bean(name = BeanIds.AUTHENTICATION_MANAGER)
 @Override
 public AuthenticationManager authenticationManagerBean() throws Exception {
    return super.authenticationManagerBean();
 }


My entire SecurityConfiguaration class is given below,

package com.toorjaridwan.introvertreadersauth.Configuration;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.BeanIds;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import com.toorjaridwan.introvertreadersauth.Service.UserDetailService;

@Configuration
@EnableWebSecurity
public class SecurityConfiguration {

    @Autowired
    private UserDetailService userDetailService;

    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(userDetailService);
    }

    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable().authorizeRequests().antMatchers("/authenticate").permitAll()
        .anyRequest().authenticated();
    }

       @Bean(name = BeanIds.AUTHENTICATION_MANAGER)
       @Override
       public AuthenticationManager authenticationManagerBean() throws Exception {
           return super.authenticationManagerBean();
       }

    @Bean
    public PasswordEncoder passwordEncoder() {
        return NoOpPasswordEncoder.getInstance();
    }

}


In a previous project which used Spring Boot version 2.1.9, everything went smoothly, no issue at all. Now I am using Spring Boot version 2.2.6. I do not know if it is the reason.

When searching for solution I came across this and this. I found things to be as similar as I did.

I am running a 64 bit Ubuntu 16.04 LTS and Java version 1.8

Ratnadeep
  • 1,125
  • 1
  • 15
  • 30

1 Answers1

2

try adding

extends WebSecurityConfigurerAdapter

to your configuration class

lane.maxwell
  • 5,002
  • 1
  • 20
  • 30
  • 1
    WebSecurityConfigurerAdapter is now deprecated, what do we do now that the security config doesn't extend WebSecurityConfigurerAdapter? – Phong Phuong Jun 19 '22 at 23:52
  • @PhongPhuong Read up on this document, https://spring.io/blog/2022/02/21/spring-security-without-the-websecurityconfigureradapter – lane.maxwell Jun 20 '22 at 00:18
  • I did look at that but there bits and pieces of code missing in the examples. I followed this and fixed the AuthenticationManagerBean(): https://stackoverflow.com/questions/72381114/spring-security-upgrading-the-deprecated-websecurityconfigureradapter-in-spring – Phong Phuong Jun 20 '22 at 00:35