44import java .util .Map ;
55
66import jakarta .servlet .ServletException ;
7- import jakarta .servlet .http .Cookie ;
87import jakarta .servlet .http .HttpServletRequest ;
98import jakarta .servlet .http .HttpServletResponse ;
109
1110import org .springframework .beans .factory .annotation .Qualifier ;
1211import org .springframework .beans .factory .annotation .Value ;
12+ import org .springframework .http .ResponseCookie ;
1313import org .springframework .security .core .Authentication ;
1414import org .springframework .security .web .authentication .AuthenticationSuccessHandler ;
1515import org .springframework .stereotype .Component ;
@@ -30,6 +30,12 @@ public class SocialSuccessHandler implements AuthenticationSuccessHandler {
3030 @ Value ("${frontend.cookie.secure}" )
3131 private boolean cookieSecure ;
3232
33+ @ Value ("${frontend.cookie.same-site}" )
34+ private String cookieSameSite ;
35+
36+ @ Value ("${frontend.cookie.http-only}" )
37+ private boolean cookieHttpOnly ;
38+
3339 public SocialSuccessHandler (@ Qualifier ("preJwtService" ) JwtService preJwtService ) {
3440 // JWT Service 매핑 (Strategy 패턴)
3541 this .jwtServiceMap =
@@ -62,14 +68,17 @@ public void onAuthenticationSuccess(
6268 // 발급한 Refresh DB 테이블 저장 (Refresh whitelist)
6369 jwtService .addRefresh (username , refreshToken );
6470
65- // 응답
66- Cookie refreshCookie = new Cookie ("refreshToken" , refreshToken );
67- refreshCookie .setHttpOnly (true );
68- refreshCookie .setSecure (cookieSecure );
69- refreshCookie .setPath ("/" );
70- refreshCookie .setMaxAge (10 ); // 10초 (프론트에서 발급 후 바로 헤더 전환 로직 진행 예정)
71-
72- response .addCookie (refreshCookie );
71+ // 응답 (ResponseCookie 사용 - SameSite 속성 지원)
72+ ResponseCookie refreshCookie =
73+ ResponseCookie .from ("refreshToken" , refreshToken )
74+ .httpOnly (cookieHttpOnly )
75+ .secure (cookieSecure )
76+ .path ("/" )
77+ .maxAge (10 ) // 10초 (프론트에서 발급 후 바로 헤더 전환 로직 진행 예정)
78+ .sameSite (cookieSameSite ) // SameSite 속성 추가
79+ .build ();
80+
81+ response .addHeader ("Set-Cookie" , refreshCookie .toString ());
7382 response .sendRedirect (frontendUrl + "/cookie" ); // 프론트 주소로 redirect
7483 }
7584
0 commit comments