|
4 | 4 | import org.springframework.context.annotation.Bean; |
5 | 5 | import org.springframework.context.annotation.Configuration; |
6 | 6 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
| 7 | +import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; |
7 | 8 | import org.springframework.security.core.userdetails.User; |
8 | 9 | import org.springframework.security.core.userdetails.UserDetails; |
9 | 10 | import org.springframework.security.core.userdetails.UserDetailsService; |
10 | 11 | import org.springframework.security.crypto.factory.PasswordEncoderFactories; |
11 | 12 | import org.springframework.security.crypto.password.PasswordEncoder; |
12 | 13 | import org.springframework.security.provisioning.InMemoryUserDetailsManager; |
| 14 | +import org.springframework.security.web.SecurityFilterChain; |
| 15 | + |
| 16 | +import static org.springframework.security.config.Customizer.withDefaults; |
13 | 17 |
|
14 | 18 | @Configuration |
15 | | -@SuppressWarnings("deprecation") // WebSecurityConfigurerAdapter has been deprecated |
16 | | -public class SecurityConfiguration |
17 | | - extends org.springframework.security.config.annotation.web.configuration |
18 | | - .WebSecurityConfigurerAdapter { |
| 19 | +public class SecurityConfiguration { |
19 | 20 |
|
20 | | - // this API is meant to be consumed by non-browser clients thus the CSRF protection is not needed. |
21 | | - @Override |
| 21 | + @Bean |
22 | 22 | @SuppressWarnings("lgtm[java/spring-disabled-csrf-protection]") |
23 | | - protected void configure(final @NotNull HttpSecurity http) throws Exception { |
24 | | - http.csrf().disable().authorizeRequests().anyRequest().authenticated().and().httpBasic(); |
| 23 | + public @NotNull SecurityFilterChain securityFilterChain(final @NotNull HttpSecurity http) |
| 24 | + throws Exception { |
| 25 | + return http |
| 26 | + .csrf(AbstractHttpConfigurer::disable) |
| 27 | + .authorizeHttpRequests(auth -> auth.anyRequest().authenticated()) |
| 28 | + .httpBasic(withDefaults()) |
| 29 | + .build(); |
25 | 30 | } |
26 | 31 |
|
27 | 32 | @Bean |
28 | | - @Override |
29 | 33 | public @NotNull UserDetailsService userDetailsService() { |
30 | 34 | final PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder(); |
31 | 35 |
|
|
0 commit comments