From b5cb49256b244645932b5794d2d258cdcea611c4 Mon Sep 17 00:00:00 2001 From: MyTestPerson <71965102+MyTestPerson@users.noreply.github.com> Date: Wed, 17 Aug 2022 03:22:26 +1100 Subject: [PATCH] Update SecurityConfiguration.java Removed deprecated methods --- .../jwt/config/SecurityConfiguration.java | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/JWT-Demo/src/main/java/com/dailycodebuffer/jwt/config/SecurityConfiguration.java b/JWT-Demo/src/main/java/com/dailycodebuffer/jwt/config/SecurityConfiguration.java index 29b678c..130e806 100644 --- a/JWT-Demo/src/main/java/com/dailycodebuffer/jwt/config/SecurityConfiguration.java +++ b/JWT-Demo/src/main/java/com/dailycodebuffer/jwt/config/SecurityConfiguration.java @@ -15,28 +15,26 @@ @Configuration @EnableWebSecurity -public class SecurityConfiguration extends WebSecurityConfigurerAdapter{ +public class SecurityConfiguration{ @Autowired - private UserService userService; + AuthenticationConfiguration authConfiguration; + + @Autowired + private UserDetail userDetail; @Autowired private JwtFilter jwtFilter; - @Override + @Autowired protected void configure(AuthenticationManagerBuilder auth) throws Exception { - - auth.userDetailsService(userService); + auth.userDetailsService(userDetail); } - @Override - @Bean - public AuthenticationManager authenticationManagerBean() throws Exception { - return super.authenticationManagerBean(); - } - @Override - protected void configure(HttpSecurity http) throws Exception { + + @Bean + protected SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http.csrf() .disable() .authorizeRequests() @@ -49,5 +47,14 @@ protected void configure(HttpSecurity http) throws Exception { .sessionCreationPolicy(SessionCreationPolicy.STATELESS); http.addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class); + return http.build(); + } + + + @Bean + public AuthenticationManager authenticationManager() throws Exception { + return authConfiguration.getAuthenticationManager(); + } + }