-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 로깅 시 UUID가 아닌 회원 번호가 기록되도록 변경 (#428)
* feat: logging 시 memberId가 나오도록 기능 추가 * feat: logging 시 memberId 및 identifier가 함께 나오도록 변경 * refactor: lombok getter 적용
- Loading branch information
Showing
7 changed files
with
84 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
backend/src/main/java/com/zzang/chongdae/logging/domain/MemberIdentifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.zzang.chongdae.logging.domain; | ||
|
||
import jakarta.servlet.http.Cookie; | ||
import java.util.Arrays; | ||
import java.util.Base64; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class MemberIdentifier { | ||
|
||
public static String ACCESS_TOKEN_NAME = "access_token"; | ||
public static String ID_NOT_FOUND_INFO = "Not Found"; | ||
|
||
private final String idInfo; | ||
|
||
public MemberIdentifier(Cookie[] cookies) { | ||
this.idInfo = buildIdInfo(cookies); | ||
} | ||
|
||
private String buildIdInfo(Cookie[] cookies) { | ||
if (cookies == null) { | ||
return ID_NOT_FOUND_INFO; | ||
} | ||
return Arrays.stream(cookies) | ||
.filter(cookie -> ACCESS_TOKEN_NAME.equals(cookie.getName())) | ||
.findFirst() | ||
.map(this::getAccessTokenInfo) | ||
.orElseGet(() -> ID_NOT_FOUND_INFO); | ||
} | ||
|
||
private String getAccessTokenInfo(Cookie cookie) { | ||
String jwtToken = cookie.getValue(); | ||
String[] tokenParts = jwtToken.split("\\."); | ||
if (tokenParts.length == 3) { | ||
String payload = new String(Base64.getUrlDecoder().decode(tokenParts[1])); | ||
return payload; | ||
} | ||
return ID_NOT_FOUND_INFO; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
backend/src/main/java/com/zzang/chongdae/logging/dto/LoggingErrorResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
backend/src/main/java/com/zzang/chongdae/logging/dto/LoggingInfoFailResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
backend/src/main/java/com/zzang/chongdae/logging/dto/LoggingInfoSuccessResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
backend/src/main/java/com/zzang/chongdae/logging/dto/LoggingWarnResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters