Skip to content

Commit 6afed44

Browse files
committed
refactor: security 설정(일단 개발 편의성 위해 permit all)
1 parent 9272dbb commit 6afed44

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,28 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
5353

5454
private void work(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
5555
String uri = request.getRequestURI();
56+
String method = request.getMethod();
5657

57-
// SecurityConfig에서 permitAll()로 설정된 경로들은 필터를 통과시키기
58+
// 개발 편의성을 위해 모든 요청 통과 (SecurityConfig에서 모든 요청 permitAll)
59+
/*
5860
if (
5961
uri.startsWith("/h2-console") ||
6062
uri.startsWith("/login/oauth2/") ||
6163
uri.startsWith("/oauth2/") ||
6264
uri.startsWith("/actuator/") ||
6365
uri.startsWith("/swagger-ui/") ||
6466
uri.startsWith("/api-docs/") ||
65-
uri.startsWith("/user/") ||
66-
uri.startsWith("/cocktails/") ||
67-
uri.startsWith("/chatbot/") ||
68-
uri.equals("/")
67+
uri.equals("/") ||
68+
// 조회 API들 - 권한 불필요
69+
(method.equals("GET") && uri.startsWith("/cocktails")) ||
70+
(method.equals("POST") && uri.equals("/cocktails/search")) ||
71+
(method.equals("GET") && uri.startsWith("/posts")) ||
72+
(method.equals("GET") && uri.contains("/comments"))
6973
) {
7074
filterChain.doFilter(request, response);
7175
return;
7276
}
77+
*/
7378

7479
// 쿠키에서 accessToken 가져오기
7580
String accessToken = rq.getCookieValue("accessToken", "");

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,33 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
5151
) // OAuth 인증시 필요할때만 세션 사용
5252

5353
.authorizeHttpRequests(auth -> auth
54+
// 개발 편의성을 위해 모든 요청 허용
55+
.anyRequest().permitAll()
56+
57+
/*
5458
.requestMatchers("/").permitAll()
5559
.requestMatchers("/h2-console/**").permitAll()
5660
.requestMatchers("/actuator/**").permitAll()
5761
.requestMatchers("/oauth2/**").permitAll()
5862
.requestMatchers("/login/oauth2/**").permitAll()
5963
.requestMatchers("/swagger-ui/**", "/api-docs/**").permitAll()
60-
.requestMatchers("/user/**").permitAll()
61-
.requestMatchers("/cocktails/**").permitAll()
62-
.requestMatchers("/chatbot/**").permitAll()
64+
65+
// 권한 불필요 - 조회 API
66+
.requestMatchers(GET, "/cocktails/**").permitAll()
67+
.requestMatchers(POST, "/cocktails/search").permitAll()
68+
.requestMatchers(GET, "/posts").permitAll()
69+
.requestMatchers(GET, "/posts/{postId}").permitAll()
70+
.requestMatchers(GET, "/posts/{postId}/comments").permitAll()
71+
.requestMatchers(GET, "/posts/{postId}/comments/{commentId}").permitAll()
72+
.requestMatchers(GET, "/cocktails/{cocktailId}/comments").permitAll()
73+
.requestMatchers(GET, "/cocktails/{cocktailId}/comments/{cocktailCommentId}").permitAll()
6374
6475
// 회원 or 인증된 사용자만 가능
6576
.requestMatchers("/admin/**").hasRole("ADMIN")
6677
67-
//그 외에는 인증해야함
78+
// 나머지 모든 API는 인증 필요
6879
.anyRequest().authenticated()
80+
*/
6981
)
7082
.formLogin(AbstractHttpConfigurer::disable)
7183
.httpBasic(AbstractHttpConfigurer::disable)

0 commit comments

Comments
 (0)