88import org .springframework .security .config .http .SessionCreationPolicy ;
99import org .springframework .security .web .SecurityFilterChain ;
1010
11+ import static org .springframework .security .config .Customizer .withDefaults ;
12+
1113@ Configuration
1214@ EnableMethodSecurity
1315public class SecurityConfig {
@@ -25,32 +27,26 @@ public class SecurityConfig {
2527
2628 @ Bean
2729 protected SecurityFilterChain filterChain (HttpSecurity http ) throws Exception {
28- http .cors ()
29- .and ()
30- .csrf ()
31- .ignoringRequestMatchers (CSRF_WHITELIST )
32- .and ()
33- .authorizeHttpRequests ()
34- .requestMatchers (HttpMethod .POST , "/organizations/**" )
35- .permitAll ()
36- .requestMatchers (AUTH_WHITELIST )
37- .permitAll ()
38- .and ()
39- .authorizeHttpRequests ()
40- .anyRequest ()
41- .authenticated ()
42- .and ()
43- .sessionManagement ()
44- .sessionCreationPolicy (SessionCreationPolicy .STATELESS )
45- .and ()
46- .oauth2ResourceServer ()
47- .jwt ()
48- .and ()
49- .and ()
50- .headers ()
51- .xssProtection ()
52- .and ()
53- .contentSecurityPolicy ("script-src 'self'" );
30+ http .cors (withDefaults ())
31+ .csrf (csrfConfigure -> csrfConfigure .ignoringRequestMatchers (CSRF_WHITELIST ))
32+ .authorizeHttpRequests (
33+ authorizeRequests ->
34+ authorizeRequests .requestMatchers (HttpMethod .POST , "/organizations/**" ).permitAll ())
35+ .authorizeHttpRequests (
36+ authorizeRequests -> authorizeRequests .requestMatchers (AUTH_WHITELIST ).permitAll ())
37+ .authorizeHttpRequests (authorizeRequests -> authorizeRequests .anyRequest ().authenticated ())
38+ .sessionManagement (
39+ sessionManagement ->
40+ sessionManagement .sessionCreationPolicy (SessionCreationPolicy .STATELESS ))
41+ .oauth2ResourceServer (
42+ oAuth2ResourceServerConfigurer -> oAuth2ResourceServerConfigurer .jwt (withDefaults ()))
43+ .headers (
44+ headers ->
45+ headers
46+ .xssProtection (withDefaults ())
47+ .contentSecurityPolicy (
48+ contentSecurityPolicyConfig ->
49+ contentSecurityPolicyConfig .policyDirectives ("script-src 'self'" )));
5450 return http .build ();
5551 }
5652}
0 commit comments