|
1 | 1 | package com.sudo.railo.auth.util; |
2 | 2 |
|
| 3 | +import org.springframework.beans.factory.annotation.Value; |
3 | 4 | import org.springframework.stereotype.Component; |
4 | 5 |
|
5 | | -import jakarta.servlet.http.Cookie; |
6 | 6 | import jakarta.servlet.http.HttpServletResponse; |
7 | 7 |
|
8 | 8 | @Component |
9 | 9 | public class CookieManager { |
10 | 10 |
|
11 | 11 | private static final String COOKIE_PATH = "/"; |
12 | 12 |
|
| 13 | + @Value("${cookie.domain}") |
| 14 | + private String cookieDomain; |
| 15 | + |
13 | 16 | public void setCookie(HttpServletResponse response, String name, String value, int maxAge) { |
14 | | - Cookie cookie = createCookie(name, value, maxAge); |
15 | | - response.addCookie(cookie); |
| 17 | + String cookieHeader = String.format( |
| 18 | + "%s=%s; Max-Age=%d; Path=%s; Domain=%s; Secure; HttpOnly; SameSite=None", |
| 19 | + name, value, maxAge, COOKIE_PATH, cookieDomain |
| 20 | + ); |
| 21 | + response.setHeader("Set-Cookie", cookieHeader); // 중복 방지: addHeader → setHeader |
16 | 22 | } |
17 | 23 |
|
18 | 24 | public void removeCookie(HttpServletResponse response, String name) { |
19 | | - Cookie cookie = createCookie(name, null, 0); |
20 | | - response.addCookie(cookie); |
21 | | - } |
22 | | - |
23 | | - private Cookie createCookie(String name, String value, int maxAge) { |
24 | | - Cookie cookie = new Cookie(name, value); |
25 | | - cookie.setMaxAge(maxAge); |
26 | | - cookie.setSecure(true); |
27 | | - cookie.setHttpOnly(true); |
28 | | - cookie.setPath(COOKIE_PATH); |
29 | | - |
30 | | - return cookie; |
| 25 | + String cookieHeader = String.format( |
| 26 | + "%s=; Max-Age=0; Path=%s; Domain=%s; Secure; HttpOnly; SameSite=None", |
| 27 | + name, COOKIE_PATH, cookieDomain |
| 28 | + ); |
| 29 | + response.setHeader("Set-Cookie", cookieHeader); // 중복 방지 |
31 | 30 | } |
32 | 31 | } |
0 commit comments