|
26 | 26 | import org.springframework.context.annotation.Bean;
|
27 | 27 | import org.springframework.context.annotation.Configuration;
|
28 | 28 | import org.springframework.core.annotation.Order;
|
| 29 | +import org.springframework.security.authentication.AuthenticationManager; |
29 | 30 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
30 | 31 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
31 | 32 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
32 |
| -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; |
33 | 33 | import org.springframework.security.config.http.SessionCreationPolicy;
|
34 | 34 | import org.springframework.security.core.userdetails.UserDetailsService;
|
35 | 35 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
| 36 | +import org.springframework.security.web.SecurityFilterChain; |
36 | 37 | import org.springframework.web.cors.CorsConfiguration;
|
37 | 38 | import org.springframework.web.cors.CorsConfigurationSource;
|
38 | 39 | import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
|
42 | 43 | @Configuration
|
43 | 44 | @EnableWebSecurity
|
44 | 45 | @Order(200)
|
45 |
| -public class WebSecurity extends WebSecurityConfigurerAdapter { |
| 46 | +public class WebSecurity { |
46 | 47 |
|
47 | 48 |
|
48 | 49 | public static final String TokenPrefix = "Bearer ";
|
@@ -71,33 +72,33 @@ public WebSecurity(UserDetailsService userDetailsService) {
|
71 | 72 | }
|
72 | 73 |
|
73 | 74 |
|
74 |
| - @Override |
75 |
| - protected void configure(HttpSecurity http) |
76 |
| - throws Exception { |
| 75 | + @Bean |
| 76 | + public SecurityFilterChain securityWebFilterChain(HttpSecurity http, AuthenticationManager authenticationManager) throws Exception { |
77 | 77 | String apiDocsPath = configProperties.getApiDocs().getPath();
|
78 | 78 | http.cors()
|
79 | 79 | .and()
|
80 | 80 | .csrf()
|
81 | 81 | .disable()
|
82 | 82 | .authorizeRequests()
|
83 |
| - .antMatchers(apiDocsPath + ALL_PATTERN) |
| 83 | + .requestMatchers(apiDocsPath + ALL_PATTERN) |
84 | 84 | .permitAll()
|
85 |
| - .antMatchers(apiDocsPath.substring(0, apiDocsPath.lastIndexOf("/") + 1) + "api-docs.yaml") |
| 85 | + .requestMatchers(apiDocsPath.substring(0, apiDocsPath.lastIndexOf("/") + 1) + "api-docs.yaml") |
86 | 86 | .permitAll()
|
87 | 87 | .anyRequest()
|
88 | 88 | .authenticated()
|
89 | 89 | .and()
|
90 | 90 | .exceptionHandling()
|
91 | 91 | .and()
|
92 |
| - .addFilter(new JWTAuthenticationFilter(authenticationManager(), lifetime, key)) |
93 |
| - .addFilter(new JWTAuthorizationFilter(authenticationManager(), key)) |
| 92 | + .addFilter(new JWTAuthenticationFilter(authenticationManager, lifetime, key)) |
| 93 | + .addFilter(new JWTAuthorizationFilter(authenticationManager, key)) |
94 | 94 | // this disables session creation on Spring Security
|
95 | 95 | .sessionManagement()
|
96 | 96 | .sessionCreationPolicy(SessionCreationPolicy.STATELESS);
|
| 97 | + return http.build(); |
97 | 98 | }
|
98 | 99 |
|
99 | 100 |
|
100 |
| - @Override |
| 101 | + @Autowired |
101 | 102 | public void configure(AuthenticationManagerBuilder auth)
|
102 | 103 | throws Exception {
|
103 | 104 | auth.userDetailsService(userDetailsService).passwordEncoder(new BCryptPasswordEncoder());
|
|
0 commit comments