|
17 | 17 |
|
18 | 18 | import java.util.Arrays; |
19 | 19 |
|
| 20 | +import static org.springframework.http.HttpMethod.GET; |
| 21 | +import static org.springframework.http.HttpMethod.POST; |
| 22 | + |
20 | 23 | @Configuration |
21 | 24 | @EnableWebSecurity |
22 | 25 | @EnableMethodSecurity |
@@ -59,36 +62,38 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { |
59 | 62 | .addFilterBefore(customAuthenticationFilter, UsernamePasswordAuthenticationFilter.class) |
60 | 63 | .authorizeHttpRequests(auth -> auth |
61 | 64 |
|
| 65 | + // OAuth, GET POST 둘 다 사용 |
| 66 | + .requestMatchers("/oauth2/**").permitAll() |
| 67 | + .requestMatchers("/login/oauth2/**").permitAll() |
| 68 | + |
| 69 | + //르프레시 갱신 및 칵테일 검색 |
| 70 | + .requestMatchers(POST, "/user/auth/refresh").permitAll() |
| 71 | + .requestMatchers(POST, "/cocktails/search").permitAll() |
| 72 | + |
| 73 | + // share은 인증 필요 |
| 74 | + .requestMatchers(GET, "/cocktails/{id}/share").authenticated() |
| 75 | + |
| 76 | + // 권한 불필요 - 조회 API |
| 77 | + .requestMatchers(GET, "/").permitAll() |
| 78 | + .requestMatchers(GET, "/actuator/**").permitAll() |
| 79 | + |
| 80 | + .requestMatchers(GET, "/cocktails/**").permitAll() |
| 81 | + |
| 82 | + .requestMatchers(GET, "/posts").permitAll() |
| 83 | + .requestMatchers(GET, "/posts/{postId}").permitAll() |
| 84 | + .requestMatchers(GET, "/posts/{postId}/comments").permitAll() |
| 85 | + .requestMatchers(GET, "/posts/{postId}/comments/{commentId}").permitAll() |
| 86 | + .requestMatchers(GET, "/cocktails/{cocktailId}/comments").permitAll() |
| 87 | + .requestMatchers(GET, "/cocktails/{cocktailId}/comments/{cocktailCommentId}").permitAll() |
| 88 | + .requestMatchers(GET, "/category").permitAll() |
| 89 | + |
| 90 | + // 나머지 모든 API는 인증 필요 |
| 91 | + .anyRequest().authenticated() |
| 92 | + |
| 93 | + |
| 94 | +// 회원 or 인증된 사용자만 가능 |
| 95 | +// .requestMatchers("/admin/**").hasRole("ADMIN") |
62 | 96 |
|
63 | | - .requestMatchers("/user/auth/logout").authenticated() |
64 | | - /* |
65 | | - .requestMatchers("/").permitAll() |
66 | | - .requestMatchers("/h2-console/**").permitAll() |
67 | | - .requestMatchers("/actuator/**").permitAll() |
68 | | - .requestMatchers("/oauth2/**").permitAll() |
69 | | - .requestMatchers("/login/oauth2/**").permitAll() |
70 | | - .requestMatchers("/swagger-ui/**", "/api-docs/**").permitAll() |
71 | | - .requestMatchers("/user/auth/refresh").permitAll() |
72 | | - .requestMatchers("/user/auth/me").permitAll() |
73 | | -
|
74 | | - // 권한 불필요 - 조회 API |
75 | | - .requestMatchers(GET, "/cocktails/**").permitAll() |
76 | | - .requestMatchers(POST, "/cocktails/search").permitAll() |
77 | | - .requestMatchers(GET, "/posts").permitAll() |
78 | | - .requestMatchers(GET, "/posts/{postId}").permitAll() |
79 | | - .requestMatchers(GET, "/posts/{postId}/comments").permitAll() |
80 | | - .requestMatchers(GET, "/posts/{postId}/comments/{commentId}").permitAll() |
81 | | - .requestMatchers(GET, "/cocktails/{cocktailId}/comments").permitAll() |
82 | | - .requestMatchers(GET, "/cocktails/{cocktailId}/comments/{cocktailCommentId}").permitAll() |
83 | | -
|
84 | | - // 회원 or 인증된 사용자만 가능 |
85 | | - .requestMatchers("/admin/**").hasRole("ADMIN") |
86 | | -
|
87 | | - // 나머지 모든 API는 인증 필요 |
88 | | - .anyRequest().authenticated() |
89 | | - */ |
90 | | - // 개발 편의성을 위해 모든 요청 허용 |
91 | | - .anyRequest().permitAll() |
92 | 97 | ) |
93 | 98 | .formLogin(AbstractHttpConfigurer::disable) |
94 | 99 | .httpBasic(AbstractHttpConfigurer::disable) |
|
0 commit comments