Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,18 @@ private Long getUserId(String token) {
}

private String getAccessToken(HttpServletRequest request) {
return CookieUtil.getCookie(request, AuthenticationConstants.ACCESS_TOKEN_NAME);
return this.getInCookie(request, AuthenticationConstants.ACCESS_TOKEN_NAME);
}

private String getRefreshToken(HttpServletRequest request) {
return CookieUtil.getCookie(request, AuthenticationConstants.REFRESH_TOKEN_NAME);
return this.getInCookie(request, AuthenticationConstants.REFRESH_TOKEN_NAME);
}

private String getInCookie(HttpServletRequest request, String name) {
String cookieValue = CookieUtil.getCookie(request, name);
if (cookieValue == null) {
throw new TokenException(TokenErrorCode.NOT_EXISTS_TOKEN);
}
return cookieValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
public enum TokenErrorCode implements BaseErrorCode {

TOKEN_EXPIRED(HttpStatus.UNAUTHORIZED, "TOKEN401_1", "ν† ν°μ˜ κΈ°ν•œμ΄ λ§Œλ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€."),
INVALID_REFRESH_TOKEN(HttpStatus.UNAUTHORIZED, "TOKEN401_2", "λ¦¬ν”„λ ˆμ‹œ 토큰이 μœ νš¨ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.")
INVALID_REFRESH_TOKEN(HttpStatus.UNAUTHORIZED, "TOKEN401_2", "λ¦¬ν”„λ ˆμ‹œ 토큰이 μœ νš¨ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€."),
NOT_EXISTS_TOKEN(HttpStatus.BAD_REQUEST, "TOKEN400_1", "토큰이 μ‘΄μž¬ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€."),
;

private final HttpStatus httpStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.withtime.be.withtimebe.domain.auth.service.command.TokenStorageCommandService;
import org.withtime.be.withtimebe.domain.auth.service.query.TokenQueryService;
import org.withtime.be.withtimebe.domain.auth.service.query.TokenStorageQueryService;
import org.withtime.be.withtimebe.global.error.code.TokenErrorCode;
import org.withtime.be.withtimebe.global.error.exception.TokenException;
import org.withtime.be.withtimebe.global.security.constants.AuthenticationConstants;
import org.withtime.be.withtimebe.global.util.CookieUtil;

Expand Down Expand Up @@ -39,9 +41,18 @@ private Long getUserId(String token) {
}

private String getAccessToken(HttpServletRequest request) {
return CookieUtil.getCookie(request, AuthenticationConstants.ACCESS_TOKEN_NAME);
return this.getInCookie(request, AuthenticationConstants.ACCESS_TOKEN_NAME);
}

private String getRefreshToken(HttpServletRequest request) {
return CookieUtil.getCookie(request, AuthenticationConstants.REFRESH_TOKEN_NAME);
}}
return this.getInCookie(request, AuthenticationConstants.REFRESH_TOKEN_NAME);
}

private String getInCookie(HttpServletRequest request, String name) {
String cookieValue = CookieUtil.getCookie(request, name);
if (cookieValue == null) {
throw new TokenException(TokenErrorCode.NOT_EXISTS_TOKEN);
}
return cookieValue;
}
}