5
5
import org .springframework .http .HttpMethod ;
6
6
import org .springframework .http .HttpStatus ;
7
7
import org .springframework .security .authentication .AuthenticationManager ;
8
- import org .springframework .security .config .annotation .authentication .builders . AuthenticationManagerBuilder ;
8
+ import org .springframework .security .config .annotation .authentication .configuration . AuthenticationConfiguration ;
9
9
import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
10
10
import org .springframework .security .config .annotation .web .configuration .EnableWebSecurity ;
11
- import org .springframework .security .config .annotation .web .configuration .WebSecurityConfigurerAdapter ;
12
11
import org .springframework .security .config .http .SessionCreationPolicy ;
13
- import org .springframework .security .core .userdetails .UserDetailsService ;
14
12
import org .springframework .security .crypto .bcrypt .BCryptPasswordEncoder ;
15
13
import org .springframework .security .crypto .password .PasswordEncoder ;
14
+ import org .springframework .security .web .SecurityFilterChain ;
16
15
import org .springframework .security .web .authentication .HttpStatusEntryPoint ;
17
16
import org .springframework .security .web .authentication .UsernamePasswordAuthenticationFilter ;
18
17
19
18
@ RequiredArgsConstructor
20
19
@ EnableWebSecurity
21
- public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
20
+ public class WebSecurityConfig {
22
21
23
- private final UserDetailsService userDetailsService ;
24
22
private final TokenAuthenticationFilter tokenAuthenticationFilter ;
25
23
26
- @ Override
27
- protected void configure ( AuthenticationManagerBuilder auth ) throws Exception {
28
- auth . userDetailsService ( userDetailsService ). passwordEncoder ( passwordEncoder () );
24
+ @ Bean
25
+ AuthenticationManager authenticationManager ( AuthenticationConfiguration authenticationConfiguration ) throws Exception {
26
+ return authenticationConfiguration . getAuthenticationManager ( );
29
27
}
30
28
31
- @ Override
32
- protected void configure (HttpSecurity http ) throws Exception {
29
+ @ Bean
30
+ SecurityFilterChain securityFilterChain (HttpSecurity http ) throws Exception {
33
31
http .authorizeRequests ()
34
32
.antMatchers (HttpMethod .POST , "/api/orders" ).hasAnyAuthority (ADMIN , USER )
35
33
.antMatchers (HttpMethod .GET , "/api/users/me" ).hasAnyAuthority (ADMIN , USER )
@@ -42,12 +40,7 @@ protected void configure(HttpSecurity http) throws Exception {
42
40
http .exceptionHandling (e -> e .authenticationEntryPoint (new HttpStatusEntryPoint (HttpStatus .UNAUTHORIZED )));
43
41
http .sessionManagement ().sessionCreationPolicy (SessionCreationPolicy .STATELESS );
44
42
http .cors ().and ().csrf ().disable ();
45
- }
46
-
47
- @ Bean
48
- @ Override
49
- public AuthenticationManager authenticationManagerBean () throws Exception {
50
- return super .authenticationManagerBean ();
43
+ return http .build ();
51
44
}
52
45
53
46
@ Bean
0 commit comments