Skip to content

Commit

Permalink
merge: 쿠키 사용 이슈 #112
Browse files Browse the repository at this point in the history
[FIX] 쿠키 사용 이슈 #112
  • Loading branch information
sjk4618 authored Jan 21, 2025
2 parents 96f1d9a + cb1c4a4 commit 8a4041a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.context.SecurityContextHolder;
Expand All @@ -19,6 +21,37 @@
public class OptionalAuthenticationFilter extends OncePerRequestFilter { //로그인 상관 X
private final JwtProvider jwtProvider;

private static final String ACCESS_TOKEN = "accessToken";

// 필터를 건너뛸 API 경로 목록
private static final List<String> EXCLUDED_PATHS = List.of(
"/api/v1/store/likes/latest/*",
"/api/v1/store/likes/popularity/*",
"/api/v1/store/likes/coordinate",
"/api/v1/store/likes/cake/latest/*",
"/api/v1/store/likes/cake/popularity/*",
"/api/v1/store/likes/*",
"/api/v1/cake/likes/*",
"/api/v1/cake/likes/latest/*",
"/api/v1/cake/likes/popularity/*",
"/api/v1/user/name-email",

"/api/v1/store/rank",
"/api/v1/store/coordinate-list/*",
"/api/v1/store/station",
"/api/v1/store/*/select/coordinate",
"/api/v1/store/*/size",
"/api/v1/store/*/information",
"/api/v1/store/*/kakaoLink"
);

@Override
protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException {
String requestURI = request.getRequestURI();
// 요청 경로가 제외 목록에 포함되어 있는지 확인
return EXCLUDED_PATHS.contains(requestURI);
}

@Override
protected void doFilterInternal(
@NonNull HttpServletRequest request,
Expand All @@ -41,7 +74,7 @@ public String getAccessTokenFromCookie(@NonNull HttpServletRequest request) {
final Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals("accessToken")) {
if (ACCESS_TOKEN.equals(cookie.getName())) {
return cookie.getValue();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.context.SecurityContextHolder;
Expand All @@ -20,6 +22,36 @@
public class RequiredAuthenticationFilter extends OncePerRequestFilter {
private final JwtProvider jwtProvider; //로그인 필수

// 필터를 건너뛸 API 경로 목록
private static final List<String> EXCLUDED_PATHS = List.of(
"/api/v1/cake/rank",
"/api/v1/store/latest/*",
"/api/v1/store/popularity/*",
"/api/v1/cake/station/latest/*",
"/api/v1/cake/station/popularity/*",
"/api/v1/store/select/*",
"/api/v1/cake/latest/*",
"/api/v1/cake/popularity/*",
"/api/v1/cake/select/*",
"/api/v1/store/design/*",

"/api/v1/store/rank",
"/api/v1/store/coordinate-list/*",
"/api/v1/store/station",
"/api/v1/store/*/select/coordinate",
"/api/v1/store/*/size",
"/api/v1/store/*/information",
"/api/v1/store/*/kakaoLink"

);

@Override
protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException {
String requestURI = request.getRequestURI();
// 요청 경로가 제외 목록에 포함되어 있는지 확인
return EXCLUDED_PATHS.contains(requestURI);
}

@Override
protected void doFilterInternal(
@NonNull HttpServletRequest request,
Expand Down
2 changes: 0 additions & 2 deletions cakey-api/src/main/java/com/cakey/config/FilterConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public FilterRegistrationBean<OptionalAuthenticationFilter> optionalAuthenticati
"/api/v1/cake/popularity/*",
"/api/v1/cake/select/*",
"/api/v1/store/design/*"


);

/// 필터 우선순위 설정
Expand Down

0 comments on commit 8a4041a

Please sign in to comment.