Skip to content

Commit 6ee0102

Browse files
authored
๐Ÿ› [Fix] ํ† ํฐ ์—†๋Š” ๊ฒฝ์šฐ 400์œผ๋กœ ์—๋Ÿฌ ์ฒ˜๋ฆฌ (#116)
2 parents 05de7b6 + d33d3a7 commit 6ee0102

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

โ€Žsrc/main/java/org/withtime/be/withtimebe/domain/auth/service/command/AuthCommandServiceImpl.javaโ€Ž

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,18 @@ private Long getUserId(String token) {
104104
}
105105

106106
private String getAccessToken(HttpServletRequest request) {
107-
return CookieUtil.getCookie(request, AuthenticationConstants.ACCESS_TOKEN_NAME);
107+
return this.getInCookie(request, AuthenticationConstants.ACCESS_TOKEN_NAME);
108108
}
109109

110110
private String getRefreshToken(HttpServletRequest request) {
111-
return CookieUtil.getCookie(request, AuthenticationConstants.REFRESH_TOKEN_NAME);
111+
return this.getInCookie(request, AuthenticationConstants.REFRESH_TOKEN_NAME);
112+
}
113+
114+
private String getInCookie(HttpServletRequest request, String name) {
115+
String cookieValue = CookieUtil.getCookie(request, name);
116+
if (cookieValue == null) {
117+
throw new TokenException(TokenErrorCode.NOT_EXISTS_TOKEN);
118+
}
119+
return cookieValue;
112120
}
113121
}

โ€Žsrc/main/java/org/withtime/be/withtimebe/global/error/code/TokenErrorCode.javaโ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
public enum TokenErrorCode implements BaseErrorCode {
1010

1111
TOKEN_EXPIRED(HttpStatus.UNAUTHORIZED, "TOKEN401_1", "ํ† ํฐ์˜ ๊ธฐํ•œ์ด ๋งŒ๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค."),
12-
INVALID_REFRESH_TOKEN(HttpStatus.UNAUTHORIZED, "TOKEN401_2", "๋ฆฌํ”„๋ ˆ์‹œ ํ† ํฐ์ด ์œ ํšจํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.")
12+
INVALID_REFRESH_TOKEN(HttpStatus.UNAUTHORIZED, "TOKEN401_2", "๋ฆฌํ”„๋ ˆ์‹œ ํ† ํฐ์ด ์œ ํšจํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."),
13+
NOT_EXISTS_TOKEN(HttpStatus.BAD_REQUEST, "TOKEN400_1", "ํ† ํฐ์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."),
1314
;
1415

1516
private final HttpStatus httpStatus;

โ€Žsrc/main/java/org/withtime/be/withtimebe/global/security/handler/CustomLogoutHandler.javaโ€Ž

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.withtime.be.withtimebe.domain.auth.service.command.TokenStorageCommandService;
88
import org.withtime.be.withtimebe.domain.auth.service.query.TokenQueryService;
99
import org.withtime.be.withtimebe.domain.auth.service.query.TokenStorageQueryService;
10+
import org.withtime.be.withtimebe.global.error.code.TokenErrorCode;
11+
import org.withtime.be.withtimebe.global.error.exception.TokenException;
1012
import org.withtime.be.withtimebe.global.security.constants.AuthenticationConstants;
1113
import org.withtime.be.withtimebe.global.util.CookieUtil;
1214

@@ -39,9 +41,18 @@ private Long getUserId(String token) {
3941
}
4042

4143
private String getAccessToken(HttpServletRequest request) {
42-
return CookieUtil.getCookie(request, AuthenticationConstants.ACCESS_TOKEN_NAME);
44+
return this.getInCookie(request, AuthenticationConstants.ACCESS_TOKEN_NAME);
4345
}
4446

4547
private String getRefreshToken(HttpServletRequest request) {
46-
return CookieUtil.getCookie(request, AuthenticationConstants.REFRESH_TOKEN_NAME);
47-
}}
48+
return this.getInCookie(request, AuthenticationConstants.REFRESH_TOKEN_NAME);
49+
}
50+
51+
private String getInCookie(HttpServletRequest request, String name) {
52+
String cookieValue = CookieUtil.getCookie(request, name);
53+
if (cookieValue == null) {
54+
throw new TokenException(TokenErrorCode.NOT_EXISTS_TOKEN);
55+
}
56+
return cookieValue;
57+
}
58+
}

0 commit comments

Comments
ย (0)