Skip to content

Commit

Permalink
fix: SameSite 속성 사용을 위해 ResponseCookie 사용
Browse files Browse the repository at this point in the history
  • Loading branch information
bflykky committed Aug 2, 2024
1 parent a83fc20 commit c247dfe
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/main/java/com/umc/naoman/global/security/util/CookieUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.SerializationUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseCookie;
import org.springframework.web.util.WebUtils;

import java.io.Serializable;
import java.util.Base64;

public class CookieUtils {
public static void addCookie(HttpServletResponse response, String name, String value,
int maxAge) {
Cookie cookie = new Cookie(name, value);
cookie.setPath("/");
cookie.setMaxAge(maxAge);
// HTTPS 적용 시 함께 적용
cookie.setSecure(true);
cookie.setHttpOnly(true);
response.addCookie(cookie);
public static void addCookie(HttpServletResponse response, String name, String value, int maxAge) {
ResponseCookie cookie = ResponseCookie.from(name, value)
.path("/")
.maxAge(maxAge)
.httpOnly(true)
.secure(true)
.sameSite("None")
.build();

response.addHeader(HttpHeaders.SET_COOKIE, cookie.toString());
}

public static void deleteCookie(HttpServletRequest request, HttpServletResponse response,
Expand Down

0 comments on commit c247dfe

Please sign in to comment.