Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
[Feat] 프론트의 요청으로 isLogin 마킹
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr-KoKo committed Jan 27, 2024
1 parent 94859c0 commit 91b0e2a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class SecurityConfig {

private static final String LOGIN_PROC_URL = "/login";
private static final String FRONT_ROOT_URL = "https://tripvote.site";
private static final String[] TOKEN_COOKIE_KEY = {"access-token", "refresh-token"};
private static final String[] TOKEN_COOKIE_KEY = {"access-token", "refresh-token", "isLogin"};

@Autowired
public void authenticationManagerConfigure(AuthenticationManagerBuilder auth) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo
CookieUtil.addCookie(response, tokenProperties.getRefreshTokenName(), refreshToken, Integer.parseInt(tokenProperties.getRefreshTokenCookieExpireTime()));
CookieUtil.addCookieForLocal(response, tokenProperties.getRefreshTokenName(), refreshToken, Integer.parseInt(tokenProperties.getRefreshTokenCookieExpireTime()));

CookieUtil.addSessionCookie(response, "isLogin", "true");
CookieUtil.addSessionCookieForLocal(response, "isLogin", "true");

response.setStatus(HttpStatus.OK.value());
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
response.setCharacterEncoding("UTF-8");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo
CookieUtil.addCookie(response, tokenProperties.getRefreshTokenName(), refreshToken, Integer.parseInt(tokenProperties.getRefreshTokenCookieExpireTime()));
CookieUtil.addCookieForLocal(response, tokenProperties.getRefreshTokenName(), refreshToken, Integer.parseInt(tokenProperties.getRefreshTokenCookieExpireTime()));

CookieUtil.addSessionCookie(response, "isLogin", "true");
CookieUtil.addSessionCookieForLocal(response, "isLogin", "true");

response.sendRedirect("https://tripvote.site");
}
}
19 changes: 19 additions & 0 deletions app/src/main/java/fc/be/app/global/util/CookieUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ public static void addCookieNotHttpOnly(HttpServletResponse response, String nam
response.addCookie(cookie);
}

public static void addSessionCookie(HttpServletResponse response, String name, String value) {
Cookie cookie = new Cookie(name, value);
cookie.setPath("/");
cookie.setDomain("tripvote.site");
cookie.setHttpOnly(false);
cookie.setSecure(true);
cookie.setAttribute("SameSite", "Lax");
response.addCookie(cookie);
}

// TODO: Remove before product
public static void addCookieForLocal(HttpServletResponse response, String name, String value, int maxAge) {
Cookie cookie = new Cookie(name, value);
Expand All @@ -63,6 +73,15 @@ public static void addCookieNotHttpOnlyForLocal(HttpServletResponse response, St
response.addCookie(cookie);
}

public static void addSessionCookieForLocal(HttpServletResponse response, String name, String value) {
Cookie cookie = new Cookie(name, value);
cookie.setPath("/");
cookie.setHttpOnly(false);
cookie.setSecure(true);
cookie.setAttribute("SameSite", "Lax");
response.addCookie(cookie);
}

public static void deleteCookie(HttpServletRequest request, HttpServletResponse response, String name) {
Cookie[] cookies = request.getCookies();
if (cookies == null) {
Expand Down

0 comments on commit 91b0e2a

Please sign in to comment.