From 0aaf9bba6ae1cb74a040cad6baa1730c37168422 Mon Sep 17 00:00:00 2001 From: jhon3242 Date: Tue, 22 Oct 2024 13:30:44 +0900 Subject: [PATCH 01/15] =?UTF-8?q?feat:=20=EC=BF=A0=ED=82=A4=20=EB=B3=B4?= =?UTF-8?q?=EC=95=88=20=EC=98=B5=EC=85=98=20=EC=84=A4=EC=A0=95=20#357?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ddangkong/controller/room/RejoinCookieEncryptor.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/ddangkong/controller/room/RejoinCookieEncryptor.java b/backend/src/main/java/ddangkong/controller/room/RejoinCookieEncryptor.java index ba7da2731..d7725cd61 100644 --- a/backend/src/main/java/ddangkong/controller/room/RejoinCookieEncryptor.java +++ b/backend/src/main/java/ddangkong/controller/room/RejoinCookieEncryptor.java @@ -18,7 +18,10 @@ public RejoinCookieEncryptor(EncryptionUtils encryptionUtils, @Value("${cookie.r public Cookie getEncodedCookie(Object value) { String encrypt = encryptionUtils.encrypt(String.valueOf(value)); - return new Cookie(rejoinKey, encrypt); + Cookie cookie = new Cookie(rejoinKey, encrypt); + cookie.setHttpOnly(true); + cookie.setSecure(true); + return cookie; } public Long getDecodedCookieValue(String cookieValue) { From fa8adfbf6b2c9cd5a1935c871dfc02953128d63b Mon Sep 17 00:00:00 2001 From: jhon3242 Date: Tue, 22 Oct 2024 13:31:33 +0900 Subject: [PATCH 02/15] =?UTF-8?q?feat:=20Cors=EB=A5=BC=20=EB=B0=B0?= =?UTF-8?q?=EC=97=B4=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20#357?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/java/ddangkong/config/CorsConfig.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/ddangkong/config/CorsConfig.java b/backend/src/main/java/ddangkong/config/CorsConfig.java index 2cbba1faf..2090098e3 100644 --- a/backend/src/main/java/ddangkong/config/CorsConfig.java +++ b/backend/src/main/java/ddangkong/config/CorsConfig.java @@ -9,9 +9,9 @@ @Configuration public class CorsConfig implements WebMvcConfigurer { - private final String corsOrigin; + private final String[] corsOrigin; - public CorsConfig(@Value("${cors.origin}") String corsOrigin) { + public CorsConfig(@Value("${cors.origin}") String[] corsOrigin) { this.corsOrigin = corsOrigin; } @@ -22,6 +22,7 @@ public void addCorsMappings(CorsRegistry registry) { .allowedMethods( HttpMethod.GET.name(), HttpMethod.POST.name(), HttpMethod.PATCH.name(), HttpMethod.DELETE.name() ) + .allowCredentials(true) .allowedHeaders("*"); } } From 3f8d9f73d1901093cce2cef6c53fa5b4b3494b15 Mon Sep 17 00:00:00 2001 From: jhon3242 Date: Tue, 22 Oct 2024 13:36:05 +0900 Subject: [PATCH 03/15] =?UTF-8?q?feat:=20allowedOriginPatterns=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20#357?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/java/ddangkong/config/CorsConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/ddangkong/config/CorsConfig.java b/backend/src/main/java/ddangkong/config/CorsConfig.java index 2090098e3..0065883ab 100644 --- a/backend/src/main/java/ddangkong/config/CorsConfig.java +++ b/backend/src/main/java/ddangkong/config/CorsConfig.java @@ -18,7 +18,7 @@ public CorsConfig(@Value("${cors.origin}") String[] corsOrigin) { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") - .allowedOrigins(corsOrigin) + .allowedOriginPatterns(corsOrigin) .allowedMethods( HttpMethod.GET.name(), HttpMethod.POST.name(), HttpMethod.PATCH.name(), HttpMethod.DELETE.name() ) From 8c395c11d25891227009eeb5d484f97b52dae921 Mon Sep 17 00:00:00 2001 From: jhon3242 Date: Tue, 22 Oct 2024 14:17:48 +0900 Subject: [PATCH 04/15] =?UTF-8?q?feat:=20=EC=BF=A0=ED=82=A4=20sameSite=20?= =?UTF-8?q?=EC=98=B5=EC=85=98=20=EC=B6=94=EA=B0=80=20#357?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/room/RejoinCookieEncryptor.java | 15 +++++++++------ .../ddangkong/controller/room/RoomController.java | 7 ++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/backend/src/main/java/ddangkong/controller/room/RejoinCookieEncryptor.java b/backend/src/main/java/ddangkong/controller/room/RejoinCookieEncryptor.java index d7725cd61..f062c7269 100644 --- a/backend/src/main/java/ddangkong/controller/room/RejoinCookieEncryptor.java +++ b/backend/src/main/java/ddangkong/controller/room/RejoinCookieEncryptor.java @@ -1,12 +1,14 @@ package ddangkong.controller.room; -import jakarta.servlet.http.Cookie; import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.ResponseCookie; import org.springframework.stereotype.Component; @Component public class RejoinCookieEncryptor { + private static final String SAME_SITE_OPTION = "None"; + private final EncryptionUtils encryptionUtils; private final String rejoinKey; @@ -16,12 +18,13 @@ public RejoinCookieEncryptor(EncryptionUtils encryptionUtils, @Value("${cookie.r this.rejoinKey = rejoinKey; } - public Cookie getEncodedCookie(Object value) { + public ResponseCookie getEncodedCookie(Object value) { String encrypt = encryptionUtils.encrypt(String.valueOf(value)); - Cookie cookie = new Cookie(rejoinKey, encrypt); - cookie.setHttpOnly(true); - cookie.setSecure(true); - return cookie; + return ResponseCookie.from(rejoinKey, encrypt) + .httpOnly(true) + .secure(true) + .sameSite(SAME_SITE_OPTION) + .build(); } public Long getDecodedCookieValue(String cookieValue) { diff --git a/backend/src/main/java/ddangkong/controller/room/RoomController.java b/backend/src/main/java/ddangkong/controller/room/RoomController.java index c03067eb1..a79d80d86 100644 --- a/backend/src/main/java/ddangkong/controller/room/RoomController.java +++ b/backend/src/main/java/ddangkong/controller/room/RoomController.java @@ -9,13 +9,14 @@ import ddangkong.facade.room.dto.RoomSettingRequest; import ddangkong.facade.room.dto.RoomStatusResponse; import ddangkong.facade.room.dto.RoundFinishedResponse; -import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.Valid; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Positive; import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseCookie; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.CookieValue; import org.springframework.web.bind.annotation.DeleteMapping; @@ -118,7 +119,7 @@ public InitialRoomResponse isInitialRoom(@PathVariable @Positive Long roomId) { } private void setEncryptCookie(HttpServletResponse response, Object cookieValue) { - Cookie encodedCookie = rejoinCookieEncryptor.getEncodedCookie(cookieValue); - response.addCookie(encodedCookie); + ResponseCookie encodedCookie = rejoinCookieEncryptor.getEncodedCookie(cookieValue); + response.addHeader(HttpHeaders.SET_COOKIE, encodedCookie.toString()); } } From 553358e6a3d3516b389486a2840f08cbb04127e6 Mon Sep 17 00:00:00 2001 From: jhon3242 Date: Tue, 22 Oct 2024 15:50:40 +0900 Subject: [PATCH 05/15] =?UTF-8?q?feat:=20=EC=BF=A0=ED=82=A4=EB=A5=BC=20?= =?UTF-8?q?=ED=86=B5=ED=95=9C=20=EC=9C=A0=EC=A0=80=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20API=20=EB=B3=80=EA=B2=BD=20#357?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/docs/asciidoc/room.adoc | 12 ++++++------ .../ddangkong/controller/room/RoomController.java | 7 ++++--- .../main/java/ddangkong/facade/room/RoomFacade.java | 5 +++-- .../facade/room/dto/RoomMemberResponse.java | 10 ++++++++++ .../controller/room/RoomControllerTest.java | 4 ++-- .../documentation/room/RoomDocumentationTest.java | 13 +++++++------ .../java/ddangkong/facade/room/RoomFacadeTest.java | 11 ++++++----- 7 files changed, 38 insertions(+), 24 deletions(-) create mode 100644 backend/src/main/java/ddangkong/facade/room/dto/RoomMemberResponse.java diff --git a/backend/src/docs/asciidoc/room.adoc b/backend/src/docs/asciidoc/room.adoc index 43d8fe7d7..c45037af3 100644 --- a/backend/src/docs/asciidoc/room.adoc +++ b/backend/src/docs/asciidoc/room.adoc @@ -58,27 +58,27 @@ include::{snippets}/room/join/response-cookies.adoc[] ''' -=== 방 재참여 +=== 사용자 정보 조회 ==== curl -include::{snippets}/room/rejoin/curl-request.adoc[] +include::{snippets}/room/member/curl-request.adoc[] ==== request -include::{snippets}/room/rejoin/http-request.adoc[] +include::{snippets}/room/member/http-request.adoc[] request cookies -include::{snippets}/room/rejoin/request-cookies.adoc[] +include::{snippets}/room/member/request-cookies.adoc[] ==== response -include::{snippets}/room/rejoin/http-response.adoc[] +include::{snippets}/room/member/http-response.adoc[] response fields -include::{snippets}/room/join/response-fields.adoc[] +include::{snippets}/room/member/response-fields.adoc[] ''' diff --git a/backend/src/main/java/ddangkong/controller/room/RoomController.java b/backend/src/main/java/ddangkong/controller/room/RoomController.java index a79d80d86..30fe58b8a 100644 --- a/backend/src/main/java/ddangkong/controller/room/RoomController.java +++ b/backend/src/main/java/ddangkong/controller/room/RoomController.java @@ -6,6 +6,7 @@ import ddangkong.facade.room.dto.RoomInfoResponse; import ddangkong.facade.room.dto.RoomJoinRequest; import ddangkong.facade.room.dto.RoomJoinResponse; +import ddangkong.facade.room.dto.RoomMemberResponse; import ddangkong.facade.room.dto.RoomSettingRequest; import ddangkong.facade.room.dto.RoomStatusResponse; import ddangkong.facade.room.dto.RoundFinishedResponse; @@ -47,9 +48,9 @@ public RoomJoinResponse createRoom(@Valid @RequestBody RoomJoinRequest request, return roomJoinResponse; } - @GetMapping("/balances/rooms/rejoin") - public RoomJoinResponse rejoinRoom(@CookieValue(name = "${cookie.rejoin-key}") String cookieValue) { - return roomFacade.rejoinRoom(rejoinCookieEncryptor.getDecodedCookieValue(cookieValue)); + @GetMapping("/balances/rooms/member") + public RoomMemberResponse getRoomMemberInfo(@CookieValue(name = "${cookie.rejoin-key}") String cookieValue) { + return roomFacade.getRoomMemberInfo(rejoinCookieEncryptor.getDecodedCookieValue(cookieValue)); } @Polling diff --git a/backend/src/main/java/ddangkong/facade/room/RoomFacade.java b/backend/src/main/java/ddangkong/facade/room/RoomFacade.java index f0464d4e0..a4ce9fa18 100644 --- a/backend/src/main/java/ddangkong/facade/room/RoomFacade.java +++ b/backend/src/main/java/ddangkong/facade/room/RoomFacade.java @@ -8,6 +8,7 @@ import ddangkong.facade.room.dto.InitialRoomResponse; import ddangkong.facade.room.dto.RoomInfoResponse; import ddangkong.facade.room.dto.RoomJoinResponse; +import ddangkong.facade.room.dto.RoomMemberResponse; import ddangkong.facade.room.dto.RoomSettingRequest; import ddangkong.facade.room.dto.RoomStatusResponse; import ddangkong.facade.room.dto.RoundFinishedResponse; @@ -53,10 +54,10 @@ public RoomJoinResponse joinRoom(String nickname, String uuid) { } @Transactional(readOnly = true) - public RoomJoinResponse rejoinRoom(Long memberId) { + public RoomMemberResponse getRoomMemberInfo(Long memberId) { Member member = memberService.getMemberById(memberId); Room room = member.getRoom(); - return new RoomJoinResponse(room.getId(), room.getUuid(), new MemberResponse(member)); + return new RoomMemberResponse(room.getId(), room.getUuid(), new MemberResponse(member)); } @Transactional diff --git a/backend/src/main/java/ddangkong/facade/room/dto/RoomMemberResponse.java b/backend/src/main/java/ddangkong/facade/room/dto/RoomMemberResponse.java new file mode 100644 index 000000000..9552c307f --- /dev/null +++ b/backend/src/main/java/ddangkong/facade/room/dto/RoomMemberResponse.java @@ -0,0 +1,10 @@ +package ddangkong.facade.room.dto; + +import ddangkong.facade.room.member.dto.MemberResponse; + +public record RoomMemberResponse( + Long roomId, + String roomUuid, + MemberResponse member +) { +} diff --git a/backend/src/test/java/ddangkong/controller/room/RoomControllerTest.java b/backend/src/test/java/ddangkong/controller/room/RoomControllerTest.java index 4d18b6b1c..2be367756 100644 --- a/backend/src/test/java/ddangkong/controller/room/RoomControllerTest.java +++ b/backend/src/test/java/ddangkong/controller/room/RoomControllerTest.java @@ -349,7 +349,7 @@ class 쿠키 { } @Test - void 쿠키를_통해_방에_재참여_할_수_있다() { + void 쿠키를_통해_사용자_정보를_조회_할_수_있다() { // given RoomJoinRequest body = new RoomJoinRequest("참가자"); String cookie = RestAssured.given().log().all() @@ -362,7 +362,7 @@ class 쿠키 { RoomJoinResponse roomJoinResponse = RestAssured.given().log().all() .contentType(ContentType.JSON) .cookie("test_cookie", cookie) - .when().get("/api/balances/rooms/rejoin") + .when().get("/api/balances/rooms/member") .then().contentType(ContentType.JSON).log().all() .statusCode(200) .extract().as(RoomJoinResponse.class); diff --git a/backend/src/test/java/ddangkong/documentation/room/RoomDocumentationTest.java b/backend/src/test/java/ddangkong/documentation/room/RoomDocumentationTest.java index 3695c983b..74cdc63b0 100644 --- a/backend/src/test/java/ddangkong/documentation/room/RoomDocumentationTest.java +++ b/backend/src/test/java/ddangkong/documentation/room/RoomDocumentationTest.java @@ -37,6 +37,7 @@ import ddangkong.facade.room.dto.RoomInfoResponse; import ddangkong.facade.room.dto.RoomJoinRequest; import ddangkong.facade.room.dto.RoomJoinResponse; +import ddangkong.facade.room.dto.RoomMemberResponse; import ddangkong.facade.room.dto.RoomSettingRequest; import ddangkong.facade.room.dto.RoomSettingResponse; import ddangkong.facade.room.dto.RoomStatusResponse; @@ -218,16 +219,16 @@ class 방_참여 { } @Nested - class 방_재참여 { + class 사용자_정보_조회 { - private static final String ENDPOINT = "/api/balances/rooms/rejoin"; + private static final String ENDPOINT = "/api/balances/rooms/member"; @Test - void 방에_재참여하여_유저_정보를_조회한다() throws Exception { + void 사용자_정보를_조회한다() throws Exception { // given - RoomJoinResponse response = new RoomJoinResponse(1L, "488fd79f92a34131bf2a628bd58c5d2c", + RoomMemberResponse response = new RoomMemberResponse(1L, "488fd79f92a34131bf2a628bd58c5d2c", new MemberResponse(2L, "타콩", false)); - when(roomFacade.rejoinRoom(anyLong())).thenReturn(response); + when(roomFacade.getRoomMemberInfo(anyLong())).thenReturn(response); //when & then mockMvc.perform(get(ENDPOINT) @@ -235,7 +236,7 @@ class 방_재참여 { .cookie(new Cookie("test_cookie", "oNnHwjSR1G4E5L8Mute61w==")) ) .andExpect(status().isOk()) - .andDo(document("room/rejoin", + .andDo(document("room/member", requestCookies( cookieWithName("test_cookie").description("사용자 인증에 필요한 쿠키(쿠키의 키 값은 UUID로 예측할 수 없는 값이 들어감)") ), diff --git a/backend/src/test/java/ddangkong/facade/room/RoomFacadeTest.java b/backend/src/test/java/ddangkong/facade/room/RoomFacadeTest.java index 2d93e253d..3d3c0bda4 100644 --- a/backend/src/test/java/ddangkong/facade/room/RoomFacadeTest.java +++ b/backend/src/test/java/ddangkong/facade/room/RoomFacadeTest.java @@ -26,6 +26,7 @@ import ddangkong.facade.room.dto.InitialRoomResponse; import ddangkong.facade.room.dto.RoomInfoResponse; import ddangkong.facade.room.dto.RoomJoinResponse; +import ddangkong.facade.room.dto.RoomMemberResponse; import ddangkong.facade.room.dto.RoomSettingRequest; import ddangkong.facade.room.dto.RoomStatusResponse; import ddangkong.facade.room.dto.RoundFinishedResponse; @@ -126,10 +127,10 @@ class 방_참여 { } @Nested - class 방_재참여 { + class 사용자_정보_조회 { @Test - void 이전_방에_재참여한다() { + void 사용자_정보를_조회한다() { // given String nickname = "나는참가자"; String uuid = "uuid4"; @@ -137,7 +138,7 @@ class 방_재참여 { roomFacade.joinRoom(nickname, uuid); // when - RoomJoinResponse actual = roomFacade.rejoinRoom(14L); + RoomMemberResponse actual = roomFacade.getRoomMemberInfo(14L); // then assertAll( @@ -148,12 +149,12 @@ class 방_재참여 { } @Test - void 존재하지_않는_아이디로_방에_재참여할_수_없다() { + void 존재하지_않는_아이디로_사용자_정보를_조회할_수_없다() { // given Long notExistMemberId = 0L; // when & then - assertThatThrownBy(() -> roomFacade.rejoinRoom(notExistMemberId)) + assertThatThrownBy(() -> roomFacade.getRoomMemberInfo(notExistMemberId)) .isExactlyInstanceOf(InvalidMemberIdException.class); } } From 26697fba158e93c7abaa058954f17cdc08b129e7 Mon Sep 17 00:00:00 2001 From: jhon3242 Date: Wed, 23 Oct 2024 16:05:33 +0900 Subject: [PATCH 06/15] =?UTF-8?q?feat:=20=EC=BF=A0=ED=82=A4=20=EA=B2=BD?= =?UTF-8?q?=EB=A1=9C=20=EC=84=A4=EC=A0=95=20#357=20=EC=BF=A0=ED=82=A4=20?= =?UTF-8?q?=EA=B2=BD=EB=A1=9C=EB=A5=BC=20=EC=84=A4=EC=A0=95=ED=95=B4?= =?UTF-8?q?=EB=91=90=EC=A7=80=20=EC=95=8A=EC=9C=BC=EB=A9=B4=20=EB=94=94?= =?UTF-8?q?=ED=8F=B4=ED=8A=B8=EB=A1=9C=20=ED=95=B4=EB=8B=B9=20API=EB=A5=BC?= =?UTF-8?q?=20=ED=98=B8=EC=B6=9C=ED=95=9C=20endpoint=EB=A1=9C=20=EB=90=98?= =?UTF-8?q?=EB=8A=94=EB=8D=B0=20=EC=9D=B4=EB=9F=AC=EB=A9=B4=20=EC=9D=B4?= =?UTF-8?q?=ED=9B=84=20=EB=8B=A4=EB=A5=B8=20endpoint=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=ED=95=98=EA=B8=B0=20=EC=96=B4=EB=A0=A4?= =?UTF-8?q?=EC=9B=80.=20=EB=94=B0=EB=9D=BC=EC=84=9C=20=EC=BF=A0=ED=82=A4?= =?UTF-8?q?=EB=A5=BC=20=ED=99=9C=EC=9A=A9=ED=95=A0=20Path=EB=A5=BC=20?= =?UTF-8?q?=EC=A7=80=EC=A0=95=ED=95=98=EC=97=AC=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/ddangkong/controller/room/RejoinCookieEncryptor.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/src/main/java/ddangkong/controller/room/RejoinCookieEncryptor.java b/backend/src/main/java/ddangkong/controller/room/RejoinCookieEncryptor.java index f062c7269..344f28ba6 100644 --- a/backend/src/main/java/ddangkong/controller/room/RejoinCookieEncryptor.java +++ b/backend/src/main/java/ddangkong/controller/room/RejoinCookieEncryptor.java @@ -8,6 +8,7 @@ public class RejoinCookieEncryptor { private static final String SAME_SITE_OPTION = "None"; + private static final String DEFAULT_PATH = "/balances/rooms"; private final EncryptionUtils encryptionUtils; @@ -23,6 +24,7 @@ public ResponseCookie getEncodedCookie(Object value) { return ResponseCookie.from(rejoinKey, encrypt) .httpOnly(true) .secure(true) + .path(DEFAULT_PATH) .sameSite(SAME_SITE_OPTION) .build(); } From cad8787d4543f44462e5fa9247d3476c6b67e6bb Mon Sep 17 00:00:00 2001 From: jhon3242 Date: Wed, 23 Oct 2024 20:09:50 +0900 Subject: [PATCH 07/15] =?UTF-8?q?fix:=20=EC=BF=A0=ED=82=A4=20=EA=B2=BD?= =?UTF-8?q?=EB=A1=9C=20=EC=84=A4=EC=A0=95=20=EC=88=98=EC=A0=95=20#357?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/ddangkong/controller/room/RejoinCookieEncryptor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/ddangkong/controller/room/RejoinCookieEncryptor.java b/backend/src/main/java/ddangkong/controller/room/RejoinCookieEncryptor.java index 344f28ba6..7adfea6c9 100644 --- a/backend/src/main/java/ddangkong/controller/room/RejoinCookieEncryptor.java +++ b/backend/src/main/java/ddangkong/controller/room/RejoinCookieEncryptor.java @@ -8,7 +8,7 @@ public class RejoinCookieEncryptor { private static final String SAME_SITE_OPTION = "None"; - private static final String DEFAULT_PATH = "/balances/rooms"; + private static final String DEFAULT_PATH = "/api/balances/rooms"; private final EncryptionUtils encryptionUtils; From 1f0501f5c3b043698fb7393714b490e5cd7c0e11 Mon Sep 17 00:00:00 2001 From: jhon3242 Date: Thu, 24 Oct 2024 10:14:45 +0900 Subject: [PATCH 08/15] =?UTF-8?q?feat:=20=EA=B2=BD=EB=A1=9C=EC=97=90=20?= =?UTF-8?q?=EB=94=B0=EB=A5=B8=20=EC=BF=A0=ED=82=A4=20SameSite=20=EC=98=B5?= =?UTF-8?q?=EC=85=98=20=EB=B3=80=EA=B2=BD=20#357?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/room/RoomController.java | 23 ++++++---- ...or.java => RoomMemberCookieEncryptor.java} | 19 +++++--- .../room/RoomMemberCookieEncryptorTest.java | 45 +++++++++++++++++++ .../room/RoomDocumentationTest.java | 4 +- 4 files changed, 76 insertions(+), 15 deletions(-) rename backend/src/main/java/ddangkong/controller/room/{RejoinCookieEncryptor.java => RoomMemberCookieEncryptor.java} (58%) create mode 100644 backend/src/test/java/ddangkong/controller/room/RoomMemberCookieEncryptorTest.java diff --git a/backend/src/main/java/ddangkong/controller/room/RoomController.java b/backend/src/main/java/ddangkong/controller/room/RoomController.java index 30fe58b8a..66c744ee4 100644 --- a/backend/src/main/java/ddangkong/controller/room/RoomController.java +++ b/backend/src/main/java/ddangkong/controller/room/RoomController.java @@ -10,6 +10,7 @@ import ddangkong.facade.room.dto.RoomSettingRequest; import ddangkong.facade.room.dto.RoomStatusResponse; import ddangkong.facade.room.dto.RoundFinishedResponse; +import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.Valid; import jakarta.validation.constraints.NotBlank; @@ -38,19 +39,21 @@ public class RoomController { private final RoomFacade roomFacade; - private final RejoinCookieEncryptor rejoinCookieEncryptor; + private final RoomMemberCookieEncryptor roomMemberCookieEncryptor; @ResponseStatus(HttpStatus.CREATED) @PostMapping("/balances/rooms") - public RoomJoinResponse createRoom(@Valid @RequestBody RoomJoinRequest request, HttpServletResponse response) { + public RoomJoinResponse createRoom(@Valid @RequestBody RoomJoinRequest request, + HttpServletRequest httpRequest, + HttpServletResponse httpResponse) { RoomJoinResponse roomJoinResponse = roomFacade.createRoom(request.nickname()); - setEncryptCookie(response, roomJoinResponse.member().memberId()); + setEncryptCookie(httpRequest, httpResponse, roomJoinResponse.member().memberId()); return roomJoinResponse; } @GetMapping("/balances/rooms/member") public RoomMemberResponse getRoomMemberInfo(@CookieValue(name = "${cookie.rejoin-key}") String cookieValue) { - return roomFacade.getRoomMemberInfo(rejoinCookieEncryptor.getDecodedCookieValue(cookieValue)); + return roomFacade.getRoomMemberInfo(roomMemberCookieEncryptor.getDecodedCookieValue(cookieValue)); } @Polling @@ -70,9 +73,10 @@ public void updateRoomSetting(@PathVariable @Positive Long roomId, @PostMapping("/balances/rooms/{uuid}/members") public RoomJoinResponse joinRoom(@PathVariable String uuid, @Valid @RequestBody RoomJoinRequest request, - HttpServletResponse response) { + HttpServletRequest httpRequest, + HttpServletResponse httpResponse) { RoomJoinResponse roomJoinResponse = roomFacade.joinRoom(request.nickname(), uuid); - setEncryptCookie(response, roomJoinResponse.member().memberId()); + setEncryptCookie(httpRequest, httpResponse, roomJoinResponse.member().memberId()); return roomJoinResponse; } @@ -119,8 +123,11 @@ public InitialRoomResponse isInitialRoom(@PathVariable @Positive Long roomId) { return roomFacade.isInitialRoom(roomId); } - private void setEncryptCookie(HttpServletResponse response, Object cookieValue) { - ResponseCookie encodedCookie = rejoinCookieEncryptor.getEncodedCookie(cookieValue); + private void setEncryptCookie(HttpServletRequest request, + HttpServletResponse response, + Object cookieValue) { + String requestURI = request.getRequestURI(); + ResponseCookie encodedCookie = roomMemberCookieEncryptor.getEncodedCookie(cookieValue, requestURI); response.addHeader(HttpHeaders.SET_COOKIE, encodedCookie.toString()); } } diff --git a/backend/src/main/java/ddangkong/controller/room/RejoinCookieEncryptor.java b/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java similarity index 58% rename from backend/src/main/java/ddangkong/controller/room/RejoinCookieEncryptor.java rename to backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java index 7adfea6c9..9fce0c3d0 100644 --- a/backend/src/main/java/ddangkong/controller/room/RejoinCookieEncryptor.java +++ b/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java @@ -5,30 +5,39 @@ import org.springframework.stereotype.Component; @Component -public class RejoinCookieEncryptor { +public class RoomMemberCookieEncryptor { - private static final String SAME_SITE_OPTION = "None"; private static final String DEFAULT_PATH = "/api/balances/rooms"; + private static final String NONE = "None"; + private static final String LAX = "Lax"; + private static final String LOCALHOST = "localhost"; private final EncryptionUtils encryptionUtils; private final String rejoinKey; - public RejoinCookieEncryptor(EncryptionUtils encryptionUtils, @Value("${cookie.rejoin-key}") String rejoinKey) { + public RoomMemberCookieEncryptor(EncryptionUtils encryptionUtils, @Value("${cookie.rejoin-key}") String rejoinKey) { this.encryptionUtils = encryptionUtils; this.rejoinKey = rejoinKey; } - public ResponseCookie getEncodedCookie(Object value) { + public ResponseCookie getEncodedCookie(Object value, String requestURI) { String encrypt = encryptionUtils.encrypt(String.valueOf(value)); return ResponseCookie.from(rejoinKey, encrypt) .httpOnly(true) .secure(true) .path(DEFAULT_PATH) - .sameSite(SAME_SITE_OPTION) + .sameSite(getSameSiteOption(requestURI)) .build(); } + private String getSameSiteOption(String uri) { + if (uri.equals(LOCALHOST)) { + return NONE; + } + return LAX; + } + public Long getDecodedCookieValue(String cookieValue) { return Long.parseLong(encryptionUtils.decrypt(cookieValue)); } diff --git a/backend/src/test/java/ddangkong/controller/room/RoomMemberCookieEncryptorTest.java b/backend/src/test/java/ddangkong/controller/room/RoomMemberCookieEncryptorTest.java new file mode 100644 index 000000000..db88078e0 --- /dev/null +++ b/backend/src/test/java/ddangkong/controller/room/RoomMemberCookieEncryptorTest.java @@ -0,0 +1,45 @@ +package ddangkong.controller.room; + +import static org.assertj.core.api.Assertions.assertThat; + +import ddangkong.controller.BaseControllerTest; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseCookie; + +class RoomMemberCookieEncryptorTest extends BaseControllerTest { + + @Autowired + private RoomMemberCookieEncryptor roomMemberCookieEncryptor; + + @Nested + class 방_멤버_쿠키_암호화 { + + @Test + void 로컬_환경인_경우_SameSite는_None_이다() { + // given + String value = "ThisIsMySecretKe"; + String uri = "localhost"; + + // when + ResponseCookie encodedCookie = roomMemberCookieEncryptor.getEncodedCookie(value, uri); + + // then + assertThat(encodedCookie.getSameSite()).isEqualTo("None"); + } + + @Test + void 로컬_환경이_아닌_경우_SameSite는_Lax_이다() { + // given + String value = "ThisIsMySecretKe"; + String uri = "ddangkong.kr"; + + // when + ResponseCookie encodedCookie = roomMemberCookieEncryptor.getEncodedCookie(value, uri); + + // then + assertThat(encodedCookie.getSameSite()).isEqualTo("Lax"); + } + } +} diff --git a/backend/src/test/java/ddangkong/documentation/room/RoomDocumentationTest.java b/backend/src/test/java/ddangkong/documentation/room/RoomDocumentationTest.java index 74cdc63b0..97249127c 100644 --- a/backend/src/test/java/ddangkong/documentation/room/RoomDocumentationTest.java +++ b/backend/src/test/java/ddangkong/documentation/room/RoomDocumentationTest.java @@ -26,7 +26,7 @@ import static org.springframework.restdocs.request.RequestDocumentation.queryParameters; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import ddangkong.controller.room.RejoinCookieEncryptor; +import ddangkong.controller.room.RoomMemberCookieEncryptor; import ddangkong.controller.room.EncryptionUtils; import ddangkong.controller.room.RoomController; import ddangkong.documentation.BaseDocumentationTest; @@ -54,7 +54,7 @@ import org.springframework.http.MediaType; @WebMvcTest(value = RoomController.class) -@Import(value = {RejoinCookieEncryptor.class, EncryptionUtils.class}) +@Import(value = {RoomMemberCookieEncryptor.class, EncryptionUtils.class}) class RoomDocumentationTest extends BaseDocumentationTest { @MockBean From c447c393d619c7a5e071ef2f277e90b311612e46 Mon Sep 17 00:00:00 2001 From: jhon3242 Date: Thu, 24 Oct 2024 10:21:48 +0900 Subject: [PATCH 09/15] =?UTF-8?q?fix:=20localhost=20uri=20=ED=99=95?= =?UTF-8?q?=EC=9D=B8=20=EB=B0=A9=EC=8B=9D=20=EB=B3=80=EA=B2=BD=20#357?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ddangkong/controller/room/RoomMemberCookieEncryptor.java | 4 ++-- .../controller/room/RoomMemberCookieEncryptorTest.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java b/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java index 9fce0c3d0..72465a5b7 100644 --- a/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java +++ b/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java @@ -10,7 +10,7 @@ public class RoomMemberCookieEncryptor { private static final String DEFAULT_PATH = "/api/balances/rooms"; private static final String NONE = "None"; private static final String LAX = "Lax"; - private static final String LOCALHOST = "localhost"; + private static final String LOCALHOST = "http://localhost"; private final EncryptionUtils encryptionUtils; @@ -32,7 +32,7 @@ public ResponseCookie getEncodedCookie(Object value, String requestURI) { } private String getSameSiteOption(String uri) { - if (uri.equals(LOCALHOST)) { + if (uri.startsWith(LOCALHOST)) { return NONE; } return LAX; diff --git a/backend/src/test/java/ddangkong/controller/room/RoomMemberCookieEncryptorTest.java b/backend/src/test/java/ddangkong/controller/room/RoomMemberCookieEncryptorTest.java index db88078e0..68d564fec 100644 --- a/backend/src/test/java/ddangkong/controller/room/RoomMemberCookieEncryptorTest.java +++ b/backend/src/test/java/ddangkong/controller/room/RoomMemberCookieEncryptorTest.java @@ -20,7 +20,7 @@ class 방_멤버_쿠키_암호화 { void 로컬_환경인_경우_SameSite는_None_이다() { // given String value = "ThisIsMySecretKe"; - String uri = "localhost"; + String uri = "http://localhost:3306/api"; // when ResponseCookie encodedCookie = roomMemberCookieEncryptor.getEncodedCookie(value, uri); From 7836c326cf7732c19299f97ff5224498fdbf6aaa Mon Sep 17 00:00:00 2001 From: jhon3242 Date: Thu, 24 Oct 2024 10:27:30 +0900 Subject: [PATCH 10/15] =?UTF-8?q?fix:=20uri=20->=20url=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20#357?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/ddangkong/controller/room/RoomController.java | 4 ++-- .../ddangkong/controller/room/RoomMemberCookieEncryptor.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/ddangkong/controller/room/RoomController.java b/backend/src/main/java/ddangkong/controller/room/RoomController.java index 66c744ee4..6cd1f1a03 100644 --- a/backend/src/main/java/ddangkong/controller/room/RoomController.java +++ b/backend/src/main/java/ddangkong/controller/room/RoomController.java @@ -126,8 +126,8 @@ public InitialRoomResponse isInitialRoom(@PathVariable @Positive Long roomId) { private void setEncryptCookie(HttpServletRequest request, HttpServletResponse response, Object cookieValue) { - String requestURI = request.getRequestURI(); - ResponseCookie encodedCookie = roomMemberCookieEncryptor.getEncodedCookie(cookieValue, requestURI); + String requestURL = request.getRequestURL().toString(); + ResponseCookie encodedCookie = roomMemberCookieEncryptor.getEncodedCookie(cookieValue, requestURL); response.addHeader(HttpHeaders.SET_COOKIE, encodedCookie.toString()); } } diff --git a/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java b/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java index 72465a5b7..498805c81 100644 --- a/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java +++ b/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java @@ -21,13 +21,13 @@ public RoomMemberCookieEncryptor(EncryptionUtils encryptionUtils, @Value("${cook this.rejoinKey = rejoinKey; } - public ResponseCookie getEncodedCookie(Object value, String requestURI) { + public ResponseCookie getEncodedCookie(Object value, String requestURL) { String encrypt = encryptionUtils.encrypt(String.valueOf(value)); return ResponseCookie.from(rejoinKey, encrypt) .httpOnly(true) .secure(true) .path(DEFAULT_PATH) - .sameSite(getSameSiteOption(requestURI)) + .sameSite(getSameSiteOption(requestURL)) .build(); } From a6044ca90974404b98e17546f9e12e6c1d0a44f6 Mon Sep 17 00:00:00 2001 From: jhon3242 Date: Thu, 24 Oct 2024 10:33:46 +0900 Subject: [PATCH 11/15] =?UTF-8?q?feat:=20=EC=9A=94=EC=B2=AD=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=20=ED=99=95=EC=9D=B8=20#357?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/room/RoomMemberCookieEncryptor.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java b/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java index 498805c81..09f466820 100644 --- a/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java +++ b/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java @@ -1,9 +1,11 @@ package ddangkong.controller.room; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.ResponseCookie; import org.springframework.stereotype.Component; +@Slf4j @Component public class RoomMemberCookieEncryptor { @@ -31,8 +33,9 @@ public ResponseCookie getEncodedCookie(Object value, String requestURL) { .build(); } - private String getSameSiteOption(String uri) { - if (uri.startsWith(LOCALHOST)) { + private String getSameSiteOption(String url) { + log.info("request url = {}", url); + if (url.startsWith(LOCALHOST)) { return NONE; } return LAX; From 4d762295972579dee8e2005da66e1b84d5517ce3 Mon Sep 17 00:00:00 2001 From: jhon3242 Date: Thu, 24 Oct 2024 10:41:15 +0900 Subject: [PATCH 12/15] =?UTF-8?q?feat:=20=EC=9A=94=EC=B2=AD=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=20=ED=99=95=EC=9D=B8=EC=9D=84=20origin=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20#357?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/ddangkong/controller/room/RoomController.java | 4 ++-- .../controller/room/RoomMemberCookieEncryptor.java | 9 ++++----- .../controller/room/RoomMemberCookieEncryptorTest.java | 8 ++++---- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/backend/src/main/java/ddangkong/controller/room/RoomController.java b/backend/src/main/java/ddangkong/controller/room/RoomController.java index 6cd1f1a03..76e31a17f 100644 --- a/backend/src/main/java/ddangkong/controller/room/RoomController.java +++ b/backend/src/main/java/ddangkong/controller/room/RoomController.java @@ -126,8 +126,8 @@ public InitialRoomResponse isInitialRoom(@PathVariable @Positive Long roomId) { private void setEncryptCookie(HttpServletRequest request, HttpServletResponse response, Object cookieValue) { - String requestURL = request.getRequestURL().toString(); - ResponseCookie encodedCookie = roomMemberCookieEncryptor.getEncodedCookie(cookieValue, requestURL); + String origin = request.getHeader(HttpHeaders.ORIGIN); + ResponseCookie encodedCookie = roomMemberCookieEncryptor.getEncodedCookie(cookieValue, origin); response.addHeader(HttpHeaders.SET_COOKIE, encodedCookie.toString()); } } diff --git a/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java b/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java index 09f466820..bae1ebc8b 100644 --- a/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java +++ b/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java @@ -23,19 +23,18 @@ public RoomMemberCookieEncryptor(EncryptionUtils encryptionUtils, @Value("${cook this.rejoinKey = rejoinKey; } - public ResponseCookie getEncodedCookie(Object value, String requestURL) { + public ResponseCookie getEncodedCookie(Object value, String origin) { String encrypt = encryptionUtils.encrypt(String.valueOf(value)); return ResponseCookie.from(rejoinKey, encrypt) .httpOnly(true) .secure(true) .path(DEFAULT_PATH) - .sameSite(getSameSiteOption(requestURL)) + .sameSite(getSameSiteOption(origin)) .build(); } - private String getSameSiteOption(String url) { - log.info("request url = {}", url); - if (url.startsWith(LOCALHOST)) { + private String getSameSiteOption(String origin) { + if (origin.startsWith(LOCALHOST)) { return NONE; } return LAX; diff --git a/backend/src/test/java/ddangkong/controller/room/RoomMemberCookieEncryptorTest.java b/backend/src/test/java/ddangkong/controller/room/RoomMemberCookieEncryptorTest.java index 68d564fec..e5cfa457e 100644 --- a/backend/src/test/java/ddangkong/controller/room/RoomMemberCookieEncryptorTest.java +++ b/backend/src/test/java/ddangkong/controller/room/RoomMemberCookieEncryptorTest.java @@ -20,10 +20,10 @@ class 방_멤버_쿠키_암호화 { void 로컬_환경인_경우_SameSite는_None_이다() { // given String value = "ThisIsMySecretKe"; - String uri = "http://localhost:3306/api"; + String origin = "http://localhost:3306/api"; // when - ResponseCookie encodedCookie = roomMemberCookieEncryptor.getEncodedCookie(value, uri); + ResponseCookie encodedCookie = roomMemberCookieEncryptor.getEncodedCookie(value, origin); // then assertThat(encodedCookie.getSameSite()).isEqualTo("None"); @@ -33,10 +33,10 @@ class 방_멤버_쿠키_암호화 { void 로컬_환경이_아닌_경우_SameSite는_Lax_이다() { // given String value = "ThisIsMySecretKe"; - String uri = "ddangkong.kr"; + String origin = "ddangkong.kr"; // when - ResponseCookie encodedCookie = roomMemberCookieEncryptor.getEncodedCookie(value, uri); + ResponseCookie encodedCookie = roomMemberCookieEncryptor.getEncodedCookie(value, origin); // then assertThat(encodedCookie.getSameSite()).isEqualTo("Lax"); From d98c3e8251b14797ada69ecea6889a16d1c19ecb Mon Sep 17 00:00:00 2001 From: jhon3242 Date: Thu, 24 Oct 2024 10:42:23 +0900 Subject: [PATCH 13/15] =?UTF-8?q?chore:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=95=A0=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20#357?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ddangkong/controller/room/RoomMemberCookieEncryptor.java | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java b/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java index bae1ebc8b..b52cf605c 100644 --- a/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java +++ b/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java @@ -5,7 +5,6 @@ import org.springframework.http.ResponseCookie; import org.springframework.stereotype.Component; -@Slf4j @Component public class RoomMemberCookieEncryptor { From 9c1f71ebe61bc46472fb4fc828329eb61e65532d Mon Sep 17 00:00:00 2001 From: jhon3242 Date: Thu, 24 Oct 2024 10:46:01 +0900 Subject: [PATCH 14/15] =?UTF-8?q?feat:=20origin=20null=20=EC=B2=B4?= =?UTF-8?q?=ED=81=AC=20=EC=B6=94=EA=B0=80=20#357?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ddangkong/controller/room/RoomMemberCookieEncryptor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java b/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java index b52cf605c..164f94ebe 100644 --- a/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java +++ b/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java @@ -33,7 +33,7 @@ public ResponseCookie getEncodedCookie(Object value, String origin) { } private String getSameSiteOption(String origin) { - if (origin.startsWith(LOCALHOST)) { + if (origin != null && origin.startsWith(LOCALHOST)) { return NONE; } return LAX; From 4dd8346e6c62970320e0187bd7614ec26bf268c9 Mon Sep 17 00:00:00 2001 From: jhon3242 Date: Thu, 24 Oct 2024 13:17:11 +0900 Subject: [PATCH 15/15] =?UTF-8?q?refactor:=20SameSite=20Enum=20=ED=99=9C?= =?UTF-8?q?=EC=9A=A9=20#357?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/room/RoomMemberCookieEncryptor.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java b/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java index 164f94ebe..e313870ea 100644 --- a/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java +++ b/backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.java @@ -2,6 +2,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.web.server.Cookie.SameSite; import org.springframework.http.ResponseCookie; import org.springframework.stereotype.Component; @@ -9,8 +10,6 @@ public class RoomMemberCookieEncryptor { private static final String DEFAULT_PATH = "/api/balances/rooms"; - private static final String NONE = "None"; - private static final String LAX = "Lax"; private static final String LOCALHOST = "http://localhost"; private final EncryptionUtils encryptionUtils; @@ -34,9 +33,9 @@ public ResponseCookie getEncodedCookie(Object value, String origin) { private String getSameSiteOption(String origin) { if (origin != null && origin.startsWith(LOCALHOST)) { - return NONE; + return SameSite.NONE.attributeValue(); } - return LAX; + return SameSite.LAX.attributeValue(); } public Long getDecodedCookieValue(String cookieValue) {