11package com .codeit .team5 .mopl .config ;
22
33import com .codeit .team5 .mopl .auth .filter .JwtAuthenticationFilter ;
4+ import com .codeit .team5 .mopl .auth .handler .SpaCsrfTokenRequestHandler ;
45import com .codeit .team5 .mopl .auth .handler .UserAccessDeniedHandler ;
56import com .codeit .team5 .mopl .auth .handler .UserAuthenticationEntryPoint ;
67import com .codeit .team5 .mopl .auth .security .provider .MoplAuthenticationProvider ;
1617import org .springframework .security .web .SecurityFilterChain ;
1718import org .springframework .security .web .authentication .UsernamePasswordAuthenticationFilter ;
1819import org .springframework .security .web .csrf .CookieCsrfTokenRepository ;
19- import org .springframework .security .web .csrf .CsrfTokenRequestAttributeHandler ;
2020import org .springframework .security .web .servlet .util .matcher .PathPatternRequestMatcher ;
2121
2222@ Configuration
@@ -34,13 +34,10 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
3434 PathPatternRequestMatcher .Builder paths =
3535 PathPatternRequestMatcher .withDefaults ();
3636
37- CsrfTokenRequestAttributeHandler csrfTokenRequestHandler =
38- new CsrfTokenRequestAttributeHandler ();
39-
4037 return http
4138 .csrf (csrf -> csrf
4239 .csrfTokenRepository (CookieCsrfTokenRepository .withHttpOnlyFalse ())
43- .csrfTokenRequestHandler (csrfTokenRequestHandler )
40+ .csrfTokenRequestHandler (new SpaCsrfTokenRequestHandler () )
4441 .ignoringRequestMatchers (
4542 paths .matcher (HttpMethod .POST , "/api/auth/refresh" )
4643 )
@@ -55,18 +52,21 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
5552 )
5653 .authorizeHttpRequests (auth -> auth
5754 .requestMatchers ("/api/auth/sign-out" ).permitAll ()
55+
56+ .requestMatchers (HttpMethod .POST , "/api/users" ).permitAll ()
57+ .requestMatchers (HttpMethod .GET , "/api/users" ).hasRole ("ADMIN" )
58+ .requestMatchers (HttpMethod .PATCH , "/api/users/*/role" ).hasRole ("ADMIN" )
59+ .requestMatchers (HttpMethod .PATCH , "/api/users/*/locked" ).hasRole ("ADMIN" )
60+ .requestMatchers (HttpMethod .GET , "/api/users/*" ).authenticated ()
61+ .requestMatchers (HttpMethod .PATCH , "/api/users/*" ).authenticated ()
62+
63+ .requestMatchers ("/api/users/**" ).authenticated ()
5864 .requestMatchers ("/api/follows/**" ).authenticated ()
5965 .requestMatchers ("/api/notifications/**" ).authenticated ()
60- .requestMatchers (HttpMethod .PATCH , "/api/users/*" ).authenticated ()
61- .requestMatchers (HttpMethod .GET , "/api/users/*" ).authenticated ()
62- .requestMatchers ("/api/users" ).permitAll ()
66+
6367 .requestMatchers ("/api/auth/sign-in" ).permitAll ()
6468 .requestMatchers ("/api/auth/csrf-token" ).permitAll ()
6569 .requestMatchers ("/api/auth/refresh" ).permitAll ()
66- .requestMatchers (HttpMethod .PATCH , "/api/users/*/role" ).hasRole ("ADMIN" )
67- .requestMatchers (HttpMethod .PATCH , "/api/users/*/locked" ).hasRole ("ADMIN" )
68-
69- // Swagger, actuator 필요하면 추가
7070 .requestMatchers ("/swagger-ui/**" , "/v3/api-docs/**" ).permitAll ()
7171
7272 .anyRequest ().permitAll ()
0 commit comments