Skip to content

Commit 93e462f

Browse files
committed
2 parents e0b492c + 9fa39ba commit 93e462f

File tree

18 files changed

+134
-69
lines changed

18 files changed

+134
-69
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
## 개발 환경 설정
22

33
[AWS API SERVER](http://ec2-13-209-127-186.ap-northeast-2.compute.amazonaws.com:8080)
4+
5+
[카카오 로그인](http://ec2-13-209-127-186.ap-northeast-2.compute.amazonaws.com:8080/oauth2/authorization/kakao)
6+
7+
[네이버 로그인](http://ec2-13-209-127-186.ap-northeast-2.compute.amazonaws.com:8080/oauth2/authorization/naver)
8+
9+
[구글 로그인](http://ec2-13-209-127-186.ap-northeast-2.compute.amazonaws.com:8080/oauth2/authorization/google)
10+
411
---
512

613
* 루트 디렉토리(WEB3_4_Log4U_BE)에서 다음 명령 실행
7-
* 개발용 MYSQL 빌드
14+
* 개발용 DB 컨테이너 실행
815

916
```
10-
# 이미지 빌드
11-
cd docker
12-
docker build -t log4u-mysql .
13-
14-
# 최초 실행 1(볼륨 존재)
15-
docker run -d --name log4u-mysql -p 3307:3306 -v {file}:/var/lib/mysql log4u-mysql
16-
17-
# 최초 실행 2(볼륨 없이)
18-
docker run -d --name log4u-mysql -p 3307:3306 log4u-mysql
17+
# postgresql mysql 모두 실행
18+
docker-compose up -d
1919
20-
# 이미 존재할 경우
21-
docker start log4u-mysql
20+
# postgresql 만 실행
21+
docker-compose up -d postgres
2222
2323
```

scripts/deploy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ cp $PROJECT_ROOT/build/libs/Log4U-0.0.1-SNAPSHOT.jar $JAR_FILE
2828

2929
# jar 파일 실행
3030
echo "$TIME_NOW > $JAR_FILE 파일 실행" >> $DEPLOY_LOG
31-
nohup java -Dspring.profiles.active="prod, prod-secret" -jar $JAR_FILE > $APP_LOG 2> $ERROR_LOG &
31+
nohup java -Dspring.profiles.active="prod, prod-secret" -jar $JAR_FILE > $APP_LOG 2> $ERROR_LOG
3232

3333
CURRENT_PID=$(pgrep -f $JAR_FILE)
3434
echo "$TIME_NOW > 실행된 프로세스 아이디 $CURRENT_PID 입니다." >> $DEPLOY_LOG

src/main/java/com/example/log4u/common/config/CorsConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public static CorsConfigurationSource corsConfigurationSource() {
1515

1616
configuration.setAllowedOrigins(List.of(
1717
UrlConstants.FRONT_ORIGIN_URL,
18-
UrlConstants.FRONT_SUB_DOMAIN_URL
18+
UrlConstants.FRONT_SUB_DOMAIN_URL,
19+
UrlConstants.FRONT_VERCEL_ORIGIN
1920
));
2021

2122
configuration.setAllowedMethods(Collections.singletonList("*"));

src/main/java/com/example/log4u/common/config/SecurityConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
7272
.authorizeHttpRequests(auth -> auth
7373
// 소셜 로그인 경로
7474
.requestMatchers("/oauth2/**").permitAll()
75+
// 테스트용 인증/인가 경로
76+
.requestMatchers("/users/dev").permitAll()
7577
// Swagger UI 관련 경로 (swagger-ui.html 추가)
7678
.requestMatchers("/swagger-ui.html", "/swagger-ui/**", "/v3/api-docs/**").permitAll()
7779
.anyRequest().authenticated());

src/main/java/com/example/log4u/common/constants/UrlConstants.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22

33
public class UrlConstants {
44

5-
public static final String FRONT_ORIGIN_URL = "http://localhost:3000/me";
6-
public static final String FRONT_SUB_DOMAIN_URL = "http://web.ec2-13-209-127-186.ap-northeast-2.compute.amazonaws.com:3000";
7-
public static final String PROFILE_CREATE_URL = FRONT_SUB_DOMAIN_URL + "/profile/make";
5+
public static final String FRONT_ORIGIN_URL = " https://web.log4u.site:3000";
6+
public static final String FRONT_SUB_DOMAIN_URL = "https://web.log4u.site:3000";
7+
public static final String FRONT_VERCEL_ORIGIN = "https://web-3-4-log4-u-fe.vercel.app";
8+
9+
// 임시로 메인
10+
public static final String PROFILE_CREATE_URL = FRONT_SUB_DOMAIN_URL + "";
811
public static final String LOGIN_URL = FRONT_SUB_DOMAIN_URL + "/login";
912

1013
// 내 프로필 페이지가 메인
11-
public static final String MAIN_URL = FRONT_SUB_DOMAIN_URL;
14+
public static final String MAIN_URL = FRONT_SUB_DOMAIN_URL + "/me";
1215

1316
// checkstyle 경고 제거
1417
private UrlConstants() {
1518
}
1619
}
20+

src/main/java/com/example/log4u/common/oauth2/controller/OAuth2Controller.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.example.log4u.common.constants.TokenConstants;
1010
import com.example.log4u.common.oauth2.jwt.JwtUtil;
1111
import com.example.log4u.common.oauth2.service.RefreshTokenService;
12+
import com.example.log4u.common.util.CookieUtil;
1213

1314
import io.jsonwebtoken.ExpiredJwtException;
1415
import jakarta.servlet.http.Cookie;
@@ -75,8 +76,9 @@ private void createNewTokens(HttpServletResponse response, String access, String
7576
String newAccessToken = jwtUtil.createJwt(TokenConstants.ACCESS_TOKEN, userId, name, role, 600000L);
7677
String newRefreshToken = jwtUtil.createJwt(TokenConstants.REFRESH_TOKEN, userId, name, role, 600000L);
7778

78-
response.addCookie(createCookie(TokenConstants.REFRESH_TOKEN, newRefreshToken));
79-
response.addCookie(createCookie(TokenConstants.ACCESS_TOKEN, newAccessToken));
79+
// SameSite=None 속성이 있는 쿠키 생성 및 추가
80+
CookieUtil.createCookieWithSameSite(response, TokenConstants.ACCESS_TOKEN, newAccessToken);
81+
CookieUtil.createCookieWithSameSite(response, TokenConstants.REFRESH_TOKEN, newRefreshToken);
8082

8183
// 새 리프레시 토큰 저장
8284
refreshTokenService.saveRefreshToken(
@@ -86,12 +88,4 @@ private void createNewTokens(HttpServletResponse response, String access, String
8688

8789
}
8890

89-
private Cookie createCookie(String key, String value) {
90-
Cookie cookie = new Cookie(key, value);
91-
cookie.setMaxAge(60 * 60 * 60);
92-
//cookie.setSecure(true);
93-
cookie.setPath("/");
94-
cookie.setHttpOnly(true);
95-
return cookie;
96-
}
9791
}

src/main/java/com/example/log4u/common/oauth2/handler/OAuth2AuthenticationSuccessHandler.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,17 @@ private void setCookieAndSaveRefreshToken(
7474
// 리프레시 토큰 DB 저장
7575
refreshTokenService.saveRefreshToken(name, refresh);
7676

77-
response.addCookie(CookieUtil.createCookie(ACCESS_TOKEN, access));
78-
response.addCookie(CookieUtil.createCookie(REFRESH_TOKEN, refresh));
77+
// SameSite=None 속성이 있는 쿠키 생성 및 추가
78+
CookieUtil.createCookieWithSameSite(response, ACCESS_TOKEN, access);
79+
CookieUtil.createCookieWithSameSite(response, REFRESH_TOKEN, refresh);
80+
7981
response.setStatus(HttpStatus.OK.value());
8082
}
8183

8284
private void redirectTo(HttpServletResponse response, CustomOAuth2User customOAuth2User) throws IOException {
8385
String redirectUrl = switch (customOAuth2User.getRole()) {
8486
case "ROLE_GUEST" -> PROFILE_CREATE_URL;
85-
case "ROLE_USER" -> FRONT_SUB_DOMAIN_URL;
87+
case "ROLE_USER" -> FRONT_VERCEL_ORIGIN;
8688
default -> LOGIN_URL;
8789
};
8890
response.sendRedirect(redirectUrl);

src/main/java/com/example/log4u/common/oauth2/jwt/JwtAuthenticationFilter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ protected void doFilterInternal(
7777
private boolean shouldSkipFilter(String requestUri) {
7878
return requestUri.matches("^/login(/.*)?$")
7979
|| requestUri.matches("^/oauth2(/.*)?$")
80+
|| requestUri.matches("^/users/dev")
8081
|| requestUri.matches("^/swagger-ui(/.*)?$")
8182
|| requestUri.matches("^/v3/api-docs(/.*)?$"); // OpenAPI 문서 예외 처리
83+
8284
}
8385

8486
private String extractAccessTokenFromCookie(HttpServletRequest request) {

src/main/java/com/example/log4u/common/util/CookieUtil.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,30 @@ private CookieUtil() {
1111
public static Cookie createCookie(String key, String value) {
1212
Cookie cookie = new Cookie(key, value);
1313
cookie.setMaxAge(60 * 60 * 60);
14-
//cookie.setSecure(true);
14+
cookie.setSecure(true);
1515
cookie.setPath("/");
1616
cookie.setHttpOnly(true);
1717
return cookie;
1818
}
1919

20+
public static void createCookieWithSameSite(HttpServletResponse response, String key, String value) {
21+
Cookie cookie = createCookie(key, value);
22+
// SameSite=None 설정을 위한 추가 헤더
23+
String headerValue = String.format("%s=%s; Max-Age=%d; Path=%s; HttpOnly; Secure; SameSite=None",
24+
key, value, cookie.getMaxAge(), cookie.getPath());
25+
response.addHeader("Set-Cookie", headerValue);
26+
}
27+
2028
public static void deleteCookie(HttpServletResponse response) {
21-
Cookie access = CookieUtil.createCookie("access", null);
22-
Cookie refresh = CookieUtil.createCookie("refresh", null);
29+
// access 쿠키 삭제 - 헤더만 사용
30+
String accessCookieString = "access=; Max-Age=0; Path=/; HttpOnly; Secure; SameSite=None";
31+
response.addHeader("Set-Cookie", accessCookieString);
2332

24-
access.setMaxAge(0);
25-
access.setPath("/");
26-
refresh.setMaxAge(0);
27-
refresh.setPath("/");
33+
// refresh 쿠키 삭제 - 헤더만 사용
34+
String refreshCookieString = "refresh=; Max-Age=0; Path=/; HttpOnly; Secure; SameSite=None";
35+
response.addHeader("Set-Cookie", refreshCookieString);
2836

29-
response.addCookie(access);
30-
response.addCookie(refresh);
3137
response.setStatus(HttpServletResponse.SC_OK);
3238
}
39+
3340
}
Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
package com.example.log4u.domain.comment.dto.response;
22

3+
import java.time.LocalDateTime;
4+
35
import com.example.log4u.domain.comment.entity.Comment;
6+
import com.example.log4u.domain.user.entity.User;
47

58
public record CommentResponseDto(
69
Long commentId,
7-
String content
10+
Long userId,
11+
String userName,
12+
String userProfileImage,
13+
String content,
14+
LocalDateTime createdAt
815
) {
9-
public static CommentResponseDto of(Comment comment) {
16+
public static CommentResponseDto of(Comment comment, User user) {
1017
return new CommentResponseDto(
1118
comment.getCommentId(),
12-
comment.getContent()
19+
user.getUserId(),
20+
user.getName(),
21+
user.getProfileImage(),
22+
comment.getContent(),
23+
comment.getCreatedAt()
1324
);
1425
}
1526
}
27+

0 commit comments

Comments
 (0)