0

I am new to spring and was learning how to use JWT from a youtube tutorial and in that tutorial they were extending the security configuration with this deprecated abstract class i saw the documentation and they are using beans now but i am not getting how i can replicate this exact code with beans, i will really be gratefull if i can get some help in that.

import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;

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.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

@Configuration
@EnableWebSecurity
@RequiredArgsConstructor
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    private final UserDetailsService userDetailsService;
    private final BCryptPasswordEncoder bCryptPasswordEncoder;

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder);
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        super.configure(http);
    }
}
Sahil Verma
  • 140
  • 1
  • 8

1 Answers1

1

Take a look, I think there is enough information here and here

  • i also have this bit of code previously i was taking the authentication manager from the suer class `WebSecurityConfigurerAdapter` now from where i can use... i need it for `http.addFilter(new CustomAuthenticationFIter(authenticationManager()));` ```java @Bean public AuthenticationManager authenticationManager() throws Exception { return super.authenticationManagerBean(); } ``` here previously i was getting the `authenticationManager` from `super.authenticationManagerBean()` but now how can i get it – Sahil Verma Jul 25 '22 at 21:02
  • try @Bean public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception { return authenticationConfiguration.getAuthenticationManager(); } – Islam Khabibullin Jul 26 '22 at 06:48