Skip to content

Commit

Permalink
fix: 만료된 엑세스 토큰에 대한 응답 통일 (#140)
Browse files Browse the repository at this point in the history
* fix : 만료된 엑세스 토큰에 대한 응답 통일

* fix : 응답 에러를 UNAUTHORIZED로 변경
  • Loading branch information
iiqcov authored Jul 14, 2024
1 parent 5d1bada commit 3a9b5dd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.api.pickle.global.error.exception.CustomException;
import com.api.pickle.global.error.exception.ErrorCode;
import com.api.pickle.global.util.JwtUtil;
import io.jsonwebtoken.ExpiredJwtException;
import lombok.RequiredArgsConstructor;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
Expand Down Expand Up @@ -53,11 +52,9 @@ public void setAuthenticationToken(Long memberId, MemberRole role) {
SecurityContextHolder.getContext().setAuthentication(token);
}

public AccessTokenDto retrieveAccessToken(String accessTokenValue) throws ExpiredJwtException{
public AccessTokenDto retrieveAccessToken(String accessTokenValue) {
try {
return jwtUtil.parseAccessToken(accessTokenValue);
} catch (ExpiredJwtException e) {
throw e;
} catch (Exception e) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public enum ErrorCode {
EXPIRED_JWT_TOKEN(HttpStatus.UNAUTHORIZED, "만료된 JWT 토큰입니다."),
MISSING_JWT_TOKEN(HttpStatus.UNAUTHORIZED, "토큰 정보가 존재하지 않습니다."),

AUTH_NOT_FOUND(HttpStatus.INTERNAL_SERVER_ERROR, "시큐리티 인증 정보를 찾을 수 없습니다."),
AUTH_NOT_FOUND(HttpStatus.UNAUTHORIZED, "시큐리티 인증 정보를 찾을 수 없습니다."),


MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 회원을 찾을 수 없습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

import com.api.pickle.domain.auth.application.JwtTokenService;
import com.api.pickle.domain.auth.dto.AccessTokenDto;
import com.api.pickle.global.error.exception.CustomException;
import com.api.pickle.global.error.exception.ErrorCode;
import io.jsonwebtoken.ExpiredJwtException;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
Expand All @@ -28,13 +25,9 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
String accessTokenHeaderValue = extractAccessTokenFromHeader(request);

if (accessTokenHeaderValue != null){
try {
AccessTokenDto accessTokenDto = jwtTokenService.retrieveAccessToken(accessTokenHeaderValue);
if (accessTokenDto != null){
jwtTokenService.setAuthenticationToken(accessTokenDto.getMemberId(), accessTokenDto.getMemberRole());
}
} catch (ExpiredJwtException e) {
throw new CustomException(ErrorCode.EXPIRED_JWT_TOKEN);
AccessTokenDto accessTokenDto = jwtTokenService.retrieveAccessToken(accessTokenHeaderValue);
if (accessTokenDto != null){
jwtTokenService.setAuthenticationToken(accessTokenDto.getMemberId(), accessTokenDto.getMemberRole());
}
}

Expand Down

0 comments on commit 3a9b5dd

Please sign in to comment.