Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: admin token fix #235

Merged
merged 35 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f33cc2f
feat: νšŒμ›μ˜ λž­ν‚Ή redis에 μΆ”κ°€ 및 μ‚­μ œ, μ—…λ°μ΄νŠΈ κΈ°λŠ₯ μΆ”κ°€
parksey Nov 28, 2023
55bc1c5
Merge branch 'develop' of https://github.com/team-moabam/moabam-BE in…
parksey Nov 28, 2023
490b4a9
test: νšŒμ› 정보 λ³€κ²½ 및 μ‚­μ œ 좔가에 λ”°λ₯Έ λž­ν‚Ή μ°Έμ—¬, μ œμ™Έ ν…ŒμŠ€νŠΈ μ½”λ“œ μΆ”κ°€
parksey Nov 28, 2023
51fe353
feat: λž­ν‚Ήμ‹œμŠ€ν…œ API μΆ”κ°€ 및 λž­ν‚Ή 쑰회 κΈ°λŠ₯ μΆ”κ°€
parksey Nov 29, 2023
fbe427a
Merge branch 'develop' of https://github.com/team-moabam/moabam-BE in…
parksey Nov 29, 2023
0ac854c
feat: λž­ν‚Ή 쑰회 ν…ŒμŠ€νŠΈ μ½”λ“œ μΆ”κ°€ 및 λž­ν‚Ή μ—…λ°μ΄νŠΈ 둜직 각 μ—…λ°μ΄νŠΈ -> μŠ€μΌ€μ₯΄λŸ¬
parksey Nov 29, 2023
ff26e4d
Merge branch 'develop' of https://github.com/team-moabam/moabam-BE in…
parksey Nov 30, 2023
f585949
style: checkstyle μ—λŸ¬ fix
parksey Nov 30, 2023
f5783bb
refactor: 응닡 객체λͺ… λ³€κ²½ TopRankingInfoResponse -> TopRankingInfo
parksey Nov 30, 2023
b0c12ca
fix: λž­ν‚Ή μ—…λ°μ΄νŠΈ μ‹œκ°„ 15λΆ„ λ§€μ΄ˆλ§ˆλ‹€ λ™μž‘ν•˜λŠ” 방식 -> 15뢄에 ν•œ 번만 μ‹€ν–‰λ˜λ„λ‘ λ³€κ²½
parksey Nov 30, 2023
286820b
refactor: λž­ν‚Ή 응닡 λ°˜ν™˜ 객체 λ³€μˆ˜λ©΄ s 제거
parksey Nov 30, 2023
431c95b
refactor: ToprankingResponses 응닡 객체 λ°˜ν™˜λͺ… TopRankingResponse둜 λ³€κ²½
parksey Nov 30, 2023
2b8f721
fix: ObjectMapperμ—λŸ¬ μˆ˜μ •
parksey Nov 30, 2023
00c5705
Merge branch 'develop' of https://github.com/team-moabam/moabam-BE in…
parksey Nov 30, 2023
6057cc7
Merge branch 'develop' of https://github.com/team-moabam/moabam-BE in…
parksey Nov 30, 2023
3c995d4
fix: objectMapper μ‚­μ œ μΆ”κ°€
parksey Nov 30, 2023
96e402e
Merge branch 'develop' of https://github.com/team-moabam/moabam-BE in…
parksey Nov 30, 2023
89aef34
feat: μ–΄λ“œλ―Ό μ„œλΉ„μŠ€ 둜그인 κΈ°λŠ₯ μΆ”κ°€
parksey Dec 1, 2023
735f5f1
Merge branch 'develop' of https://github.com/team-moabam/moabam-BE in…
parksey Dec 1, 2023
4771e9e
refactor: μ–΄λ“œλ―Ό config μ—…λ°μ΄νŠΈ
parksey Dec 1, 2023
16a7eab
fix: test application.yml μˆ˜μ •
parksey Dec 1, 2023
fc0fcb0
test: stubμ—μ„œμ˜ νƒ€μž… 였λ₯˜ ν•΄κ²°
parksey Dec 1, 2023
fd99886
style: λ³€μˆ˜λ©΄ λ³€κ²½
parksey Dec 1, 2023
f58400f
Merge branch 'develop' of https://github.com/team-moabam/moabam-BE in…
parksey Dec 1, 2023
4e40928
Merge branch 'develop' of https://github.com/team-moabam/moabam-BE in…
parksey Dec 2, 2023
df92c4f
feat: μ–΄λ“œλ―Όκ³Ό 일반 μœ μ €κ°„ 토큰 생성, 검증 뢄리 및 둜그인 뢄리
parksey Dec 3, 2023
ca1819d
feat: νšŒμ› μΈμ¦μ‹œ 뱃지 생성기λŠ₯ μΆ”κ°€
parksey Dec 3, 2023
c627fe5
refactor: config μˆ˜μ •
parksey Dec 3, 2023
d772928
Merge branch 'develop' of https://github.com/team-moabam/moabam-BE in…
parksey Dec 3, 2023
4f51236
refactor: μ½”λ”© μŠ€νƒ€μΌ 재적용
parksey Dec 3, 2023
04ec9e4
Merge branch 'develop' of https://github.com/team-moabam/moabam-BE in…
parksey Dec 3, 2023
5e7ee6f
fix: 도메인 λ³€κ²½
parksey Dec 3, 2023
06b51d3
hotfix: μ„œλ²„ 도메인 λ³€κ²½
parksey Dec 3, 2023
dfe011f
Merge branch 'develop' of https://github.com/team-moabam/moabam-BE in…
parksey Dec 3, 2023
d44a8dd
feat: 둜그인 μΏ ν‚€ 도메인 κ΄€λ ¨ SameSiteλ₯Ό None으둜 λ³€κ²½
parksey Dec 3, 2023
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 @@ -76,7 +76,8 @@ public AuthorizationTokenResponse requestToken(AuthorizationCodeResponse authori
public AuthorizationTokenInfoResponse requestTokenInfo(AuthorizationTokenResponse authorizationTokenResponse) {
String tokenValue = generateTokenValue(authorizationTokenResponse.accessToken());
ResponseEntity<AuthorizationTokenInfoResponse> authorizationTokenInfoResponse =
oauth2AuthorizationServerRequestService.tokenInfoRequest(oAuthConfig.provider().tokenInfo(), tokenValue);
oauth2AuthorizationServerRequestService
.tokenInfoRequest(oAuthConfig.provider().tokenInfo(), tokenValue);

return authorizationTokenInfoResponse.getBody();
}
Expand All @@ -99,12 +100,12 @@ public void issueServiceToken(HttpServletResponse response, PublicClaim publicCl
String domain = getDomain(publicClaim.role());

response.addCookie(CookieUtils.typeCookie("Bearer", tokenConfig.getRefreshExpire(), domain));
response.addCookie(
CookieUtils.typeCookie("Test_be_erase", tokenConfig.getRefreshExpire(), publicClaim.role().name()));
response.addCookie(
CookieUtils.tokenCookie("access_token", accessToken, tokenConfig.getRefreshExpire(), domain));
response.addCookie(
CookieUtils.tokenCookie("refresh_token", refreshToken, tokenConfig.getRefreshExpire(), domain));
response.addCookie(CookieUtils
.tokenCookie("Test", publicClaim.role().name(), tokenConfig.getRefreshExpire(), domain));
response.addCookie(CookieUtils
.tokenCookie("access_token", accessToken, tokenConfig.getRefreshExpire(), domain));
response.addCookie(CookieUtils
.tokenCookie("refresh_token", refreshToken, tokenConfig.getRefreshExpire(), domain));
}

public void validTokenPair(Long id, String oldRefreshToken, Role role) {
Expand All @@ -117,8 +118,8 @@ public void validTokenPair(Long id, String oldRefreshToken, Role role) {
}
}

public void logout(AuthMember authMember, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
public void logout(AuthMember authMember,
HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
removeToken(httpServletRequest, httpServletResponse);
tokenRepository.delete(authMember.id(), authMember.role());
fcmService.deleteTokenByMemberId(authMember.id());
Expand Down Expand Up @@ -180,11 +181,13 @@ private String generateTokenValue(String token) {
}

private String generateQueryParamsWith(AuthorizationCodeRequest authorizationCodeRequest) {
UriComponentsBuilder authorizationCodeUri = UriComponentsBuilder.fromUriString(
oAuthConfig.provider().authorizationUri())
.queryParam("response_type", "code")
.queryParam("client_id", authorizationCodeRequest.clientId())
.queryParam("redirect_uri", authorizationCodeRequest.redirectUri());
UriComponentsBuilder authorizationCodeUri =
UriComponentsBuilder.fromUriString(
oAuthConfig.provider()
.authorizationUri())
.queryParam("response_type", "code")
.queryParam("client_id", authorizationCodeRequest.clientId())
.queryParam("redirect_uri", authorizationCodeRequest.redirectUri());

if (authorizationCodeRequest.scope() != null && !authorizationCodeRequest.scope().isEmpty()) {
String scopes = String.join(",", authorizationCodeRequest.scope());
Expand All @@ -201,8 +204,8 @@ private void validAuthorizationGrant(String code) {
}

private AuthorizationTokenResponse issueTokenToAuthorizationServer(String code, String redirectUri) {
AuthorizationTokenRequest authorizationTokenRequest = AuthorizationMapper.toAuthorizationTokenRequest(
oAuthConfig, code, redirectUri);
AuthorizationTokenRequest authorizationTokenRequest =
AuthorizationMapper.toAuthorizationTokenRequest(oAuthConfig, code, redirectUri);
MultiValueMap<String, String> uriParams = generateTokenRequest(authorizationTokenRequest);
ResponseEntity<AuthorizationTokenResponse> authorizationTokenResponse =
oauth2AuthorizationServerRequestService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private void invoke(HttpServletRequest httpServletRequest, HttpServletResponse h
Cookie[] cookies = getCookiesOrThrow(httpServletRequest);

if (!isTokenTypeBearer(cookies)) {
throw new UnauthorizedException(ErrorMessage.GRANT_FAILED);
throw new UnauthorizedException(ErrorMessage.TOKEN_TYPE_FAILED);
}

handleTokenAuthenticate(cookies, httpServletResponse, httpServletRequest);
Expand All @@ -92,7 +92,7 @@ private void handleTokenAuthenticate(Cookie[] cookies, HttpServletResponse httpS
String refreshToken = extractTokenFromCookie(cookies, "refresh_token");

if (authenticationService.isTokenExpire(refreshToken, publicClaim.role())) {
throw new UnauthorizedException(ErrorMessage.AUTHENTICATE_FAIL);
throw new UnauthorizedException(ErrorMessage.TOKEN_EXPIRE);
}

validInvalidMember(publicClaim, refreshToken, httpServletRequest);
Expand All @@ -117,14 +117,14 @@ private void validInvalidMember(PublicClaim publicClaim, String refreshToken,

private Cookie[] getCookiesOrThrow(HttpServletRequest httpServletRequest) {
return Optional.ofNullable(httpServletRequest.getCookies())
.orElseThrow(() -> new UnauthorizedException(ErrorMessage.GRANT_FAILED));
.orElseThrow(() -> new UnauthorizedException(ErrorMessage.COOKIE_NOT_FOUND));
}

private String extractTokenFromCookie(Cookie[] cookies, String tokenName) {
return Arrays.stream(cookies)
.filter(cookie -> tokenName.equals(cookie.getName()))
.map(Cookie::getValue)
.findFirst()
.orElseThrow(() -> new UnauthorizedException(ErrorMessage.AUTHENTICATE_FAIL));
.orElseThrow(() -> new UnauthorizedException(ErrorMessage.TOKEN_NOT_FOUND));
}
}
6 changes: 4 additions & 2 deletions src/main/java/com/moabam/global/common/util/CookieUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ public static Cookie tokenCookie(String name, String value, long expireTime, Str
cookie.setSecure(true);
cookie.setHttpOnly(true);
cookie.setPath("/");
cookie.setDomain(domain);
cookie.setMaxAge((int)expireTime);
cookie.setAttribute("SameSite", "Lax");
cookie.setAttribute("SameSite", "None");

return cookie;
}
Expand All @@ -23,8 +24,9 @@ public static Cookie typeCookie(String value, long expireTime, String domain) {
cookie.setSecure(true);
cookie.setHttpOnly(true);
cookie.setPath("/");
cookie.setDomain(domain);
cookie.setMaxAge((int)expireTime);
cookie.setAttribute("SameSite", "Lax");
cookie.setAttribute("SameSite", "None");

return cookie;
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/moabam/global/error/model/ErrorMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ public enum ErrorMessage {
LOGIN_FAILED("λ‘œκ·ΈμΈμ— μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€."),
LOGIN_FAILED_ADMIN_KEY("μ–΄λ“œλ―Όν‚€κ°€ λ‹¬λΌμš”"),
REQUEST_FAILED("λ„€νŠΈμ›Œν¬ μ ‘κ·Ό μ‹€νŒ¨μž…λ‹ˆλ‹€."),
TOKEN_TYPE_FAILED("토큰 타일이 μΌμΉ˜ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€."),
GRANT_FAILED("인가 μ½”λ“œ μ‹€νŒ¨"),
TOKEN_EXPIRE("토큰이 λ§Œλ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€."),
AUTHENTICATE_FAIL("인증 μ‹€νŒ¨"),
TOKEN_NOT_FOUND("토큰이 μ‘΄μž¬ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€."),
COOKIE_NOT_FOUND("μΏ ν‚€κ°€ μ—†μŠ΅λ‹ˆλ‹€"),
MEMBER_NOT_FOUND("μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” νšŒμ›μž…λ‹ˆλ‹€."),
MEMBER_NOT_FOUND_BY_MANAGER_OR_NULL("방의 λ§€λ‹ˆμ €κ±°λ‚˜ νšŒμ›μ΄ μ‘΄μž¬ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€."),
MEMBER_ROOM_EXCEED("μ°Έμ—¬ν•  수 μžˆλŠ” 방의 κ°œμˆ˜κ°€ λͺ¨λ‘ μ°ΌμŠ΅λ‹ˆλ‹€."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void create_test() {
() -> assertThat(cookie.getSecure()).isTrue(),
() -> assertThat(cookie.getPath()).isEqualTo("/"),
() -> assertThat(cookie.getMaxAge()).isEqualTo(10000),
() -> assertThat(cookie.getAttribute("SameSite")).isEqualTo("Lax")
() -> assertThat(cookie.getAttribute("SameSite")).isEqualTo("None")
);
}

Expand Down