Skip to content

Commit

Permalink
[MERGE] fix/#41 -> dev
Browse files Browse the repository at this point in the history
[FIX/#41] JWT 필터 내 whilelist 처리 오류 해결
  • Loading branch information
sung-silver authored Jan 17, 2025
2 parents 9cd43e2 + 10231bc commit e6974ae
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package sopt.makers.authentication.support.code.support.failure;

import static lombok.AccessLevel.PRIVATE;

import sopt.makers.authentication.support.code.base.*;

import org.springframework.http.*;

import lombok.*;

@Getter
@RequiredArgsConstructor(access = PRIVATE)
public enum CommonFailure implements FailureCode {
INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "서버 내부 오류입니다");
private final HttpStatus status;
private final String message;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,20 @@ private SystemConstant() {}
private static final String API_PATH_PREFIX = "/api";
private static final String API_VERSION = "/v1";

public static final String API_DEFAULT_PREFIX = API_PATH_PREFIX + API_VERSION;
private static final String API_DEFAULT_PREFIX = API_PATH_PREFIX + API_VERSION;

private static final String PATH_ACTUATOR = "/actuator";
private static final String PATH_AUTH = API_DEFAULT_PREFIX + "/auth";
public static final String PATH_AUTH = API_DEFAULT_PREFIX + "/auth";
private static final String PATH_ERROR = "/error";
private static final String PATH_TEST = "/test";
private static final String PATH_GET_REGISTER_SOCIAL_PLATFORM =
API_PATH_PREFIX + "/social/accounts/social";

public static List<String> WHITE_PATHS =
List.of(PATH_ACTUATOR, PATH_AUTH, PATH_GET_REGISTER_SOCIAL_PLATFORM, PATH_ERROR, PATH_TEST);

public static final String PATTERN_ALL = "/**";
public static final String PATTERN_ERROR_PATH = PATH_ERROR + PATTERN_ALL;
public static final String PATTERN_ACTUATOR = PATH_ACTUATOR + PATTERN_ALL;
public static final String PATTERN_AUTH = PATH_AUTH + PATTERN_ALL;
public static final String PATTERN_TEST = API_DEFAULT_PREFIX + PATH_TEST + PATTERN_ALL;
public static final String PATTERN_ROOT_PATH = "/";

public static final List<String> WHITELIST_WILDCARD =
List.of(PATH_ERROR, PATH_ACTUATOR, PATH_AUTH, PATH_TEST);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package sopt.makers.authentication.support.exception;

import static sopt.makers.authentication.support.code.support.failure.CommonFailure.INTERNAL_SERVER_ERROR;

import sopt.makers.authentication.support.common.api.BaseResponse;
import sopt.makers.authentication.support.exception.domain.AuthException;
import sopt.makers.authentication.support.exception.base.*;

import org.springframework.http.ResponseEntity;
import org.springframework.http.*;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

Expand All @@ -12,9 +14,15 @@
@Slf4j
@RestControllerAdvice
public class ApplicationExceptionHandler {
@ExceptionHandler(RuntimeException.class)
ResponseEntity<BaseResponse<?>> handleInternalException(final RuntimeException e) {
log.error(e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(BaseResponse.ofFailure(INTERNAL_SERVER_ERROR));
}

@ExceptionHandler(AuthException.class)
ResponseEntity<BaseResponse<?>> authFailureException(final AuthException e) {
@ExceptionHandler(BaseException.class)
ResponseEntity<BaseResponse<?>> handleBusinessException(final BaseException e) {
log.error(e.getError().getMessage());
return ResponseEntity.status(e.getError().getStatus().value())
.body(BaseResponse.ofFailure(e.getError()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package sopt.makers.authentication.support.security.filter;

import static sopt.makers.authentication.support.constant.SystemConstant.WHITE_PATHS;
import static sopt.makers.authentication.support.constant.SystemConstant.WHITELIST_WILDCARD;

import sopt.makers.authentication.support.jwt.provider.JwtAuthAccessTokenProvider;
import sopt.makers.authentication.support.security.authentication.CustomAuthentication;
Expand Down Expand Up @@ -31,6 +31,11 @@ protected void doFilterInternal(
final HttpServletRequest request, final HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {

if (shouldNotFilter(request)) {
filterChain.doFilter(request, response);
return;
}

String authorizationToken = getAuthorizationToken(request);
CustomAuthentication authentication = authTokenProvider.parse(authorizationToken);

Expand All @@ -46,8 +51,8 @@ public boolean shouldNotFilter(HttpServletRequest request) {
}

private boolean isWhiteRequest(final HttpServletRequest request) {
String url = request.getRequestURL().toString();
return WHITE_PATHS.stream().anyMatch(url::contains);
String uri = request.getRequestURI();
return WHITELIST_WILDCARD.stream().anyMatch(uri::startsWith);
}

/**
Expand Down

0 comments on commit e6974ae

Please sign in to comment.