Skip to content

Commit b47ec99

Browse files
committed
test: 개발환경 보안 적용
1 parent e46db1a commit b47ec99

File tree

1 file changed

+34
-29
lines changed

1 file changed

+34
-29
lines changed

src/main/java/com/back/global/security/SecurityConfig.java

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
import java.util.Arrays;
1919

20+
import static org.springframework.http.HttpMethod.GET;
21+
import static org.springframework.http.HttpMethod.POST;
22+
2023
@Configuration
2124
@EnableWebSecurity
2225
@EnableMethodSecurity
@@ -59,36 +62,38 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
5962
.addFilterBefore(customAuthenticationFilter, UsernamePasswordAuthenticationFilter.class)
6063
.authorizeHttpRequests(auth -> auth
6164

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")
6296

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()
9297
)
9398
.formLogin(AbstractHttpConfigurer::disable)
9499
.httpBasic(AbstractHttpConfigurer::disable)

0 commit comments

Comments
 (0)