Skip to content

Commit 76b74b3

Browse files
authored
Merge pull request #299 from mosu-dev/develop
prod: fix 전반적인 오류 수정
2 parents 187cab3 + 5d270db commit 76b74b3

10 files changed

Lines changed: 68 additions & 12 deletions

File tree

src/main/java/life/mosu/mosuserver/application/event/EventService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import life.mosu.mosuserver.global.exception.CustomRuntimeException;
88
import life.mosu.mosuserver.global.exception.ErrorCode;
99
import life.mosu.mosuserver.global.support.CursorResponse;
10+
import life.mosu.mosuserver.infra.persistence.s3.FileUploadHelper;
1011
import life.mosu.mosuserver.infra.persistence.s3.S3Service;
1112
import life.mosu.mosuserver.presentation.event.dto.EventRequest;
1213
import life.mosu.mosuserver.presentation.event.dto.EventResponse;
@@ -22,12 +23,13 @@ public class EventService {
2223

2324
private final EventJpaRepository eventJpaRepository;
2425
private final EventQueryRepository eventQueryRepository;
25-
// private final EventAttachmentService attachmentService;
26+
private final FileUploadHelper uploadHelper;
2627
private final S3Service s3Service;
2728

2829
@Transactional
2930
public void createEvent(EventRequest request) {
3031
EventJpaEntity eventEntity = eventJpaRepository.save(request.toEntity());
32+
uploadHelper.updateTag(eventEntity.getS3Key());
3133
// attachmentService.createAttachment(request.optionalAttachment(), eventEntity);
3234
}
3335

src/main/java/life/mosu/mosuserver/application/examapplication/ExamApplicationService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public ExamApplicationInfoResponse getApplication(Long userId, Long examApplicat
153153
examApplicationInfo.schoolName(),
154154
AddressResponse.from(examApplicationInfo.address()),
155155
subjects,
156-
examApplicationInfo.isLunchChecked() ? examApplicationInfo.lunchName() : "신청 안 함",
156+
examApplicationInfo.isLunchChecked() ? examApplicationInfo.lunchName() : "도시락 X",
157157
paymentAmount,
158158
discountAmount,
159159
examApplicationInfo.paymentMethod().getName()

src/main/java/life/mosu/mosuserver/domain/application/entity/Lunch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
@Getter
1010
@RequiredArgsConstructor
1111
public enum Lunch {
12-
NONE("선택 안 함"),
12+
NONE("도시락 X"),
1313
OPTION1("도시락 A"),
1414
OPTION2("도시락 B"),
1515
OPTION3("비건 도시락"),

src/main/java/life/mosu/mosuserver/global/exception/ErrorCode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public enum ErrorCode {
3232
INVALID_SIGN_UP_TOKEN(HttpStatus.UNAUTHORIZED, "유효하지 않은 회원가입 인증 토큰입니다."),
3333
MISSING_SIGNUP_TOKEN(HttpStatus.BAD_REQUEST, "회원가입 인증 토큰이 누락되었습니다."),
3434
MISSING_PASSWORD_TOKEN(HttpStatus.BAD_REQUEST, "비밀번호 변경 토큰이 누락되었습니다."),
35+
COOKIE_NOT_FOUND(HttpStatus.NOT_FOUND, "쿠키가 존재하지 않습니다."),
3536

3637
NOT_FOUND_TOKEN(HttpStatus.NOT_FOUND, "인증 토큰을 찾을 수 없습니다."),
3738
NOT_FOUND_ACCESS_TOKEN(HttpStatus.UNAUTHORIZED, "액세스 토큰을 찾을 수 없습니다."),

src/main/java/life/mosu/mosuserver/global/filter/AuthConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class AuthConstants {
1818
public static final String AUTH_PREFIX = API_PREFIX + "/auth";
1919
public static final String PATH_REISSUE = AUTH_PREFIX + "/reissue";
2020
public static final String PATH_SIGNUP = AUTH_PREFIX + "/signup";
21+
public static final String COOKIE_ACCESS = AUTH_PREFIX + "/check-cookie";
2122

2223
public static final String USER_PREFIX = API_PREFIX + "/user";
2324
public static final String PATH_PASSWORD_CHANGE = USER_PREFIX + "/me/password";

src/main/java/life/mosu/mosuserver/global/filter/TokenFilter.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,26 @@ protected void doFilterInternal(
7878
return;
7979
}
8080

81+
if (requestUri.startsWith(AuthConstants.COOKIE_ACCESS)) {
82+
83+
final TokenCookies tokenCookies = tokenResolver.resolveTokens(request);
84+
String accessToken = tokenCookies.getAccessToken().orElseThrow(
85+
() -> new CustomRuntimeException(ErrorCode.COOKIE_NOT_FOUND)
86+
);
87+
try {
88+
setAuthentication(accessToken);
89+
90+
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
91+
return;
92+
} catch (CustomRuntimeException e) {
93+
log.warn("쿠키 토큰 검증 실패: {}", e.getMessage());
94+
throw e;
95+
} catch (Exception e) {
96+
log.error("쿠키 토큰 검증 중 예외 발생", e);
97+
throw new CustomRuntimeException(ErrorCode.INVALID_TOKEN);
98+
}
99+
}
100+
81101
final TokenCookies tokenCookies = tokenResolver.resolveTokens(request);
82102
String accessToken = tokenCookies.getAccessToken().orElseThrow(
83103
() -> new CustomRuntimeException(ErrorCode.NOT_FOUND_ACCESS_TOKEN)

src/main/java/life/mosu/mosuserver/global/util/CookieBuilderUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public static ResponseCookie createDevelopResponseCookie(String name, String val
8181
*/
8282
public static Cookie createDevelopCookie(String name, String value, Long maxAge) {
8383
Cookie cookie = createBaseServletCookie(name, value, maxAge);
84-
cookie.setSecure(true);
84+
cookie.setSecure(false);
8585
cookie.setDomain(".mosuedu.com");
8686
return cookie;
8787
}

src/main/java/life/mosu/mosuserver/infra/persistence/s3/S3Service.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,23 @@
3131
@RequiredArgsConstructor
3232
public class S3Service {
3333

34+
private static final int MAX_FILENAME_LENGTH = 150;
35+
private static final int MAX_S3_KEY_LENGTH = 255;
36+
3437
private final S3Client s3Client;
3538
private final S3Presigner s3Presigner;
3639
private final S3Properties s3Properties;
3740

3841
public FileUploadResponse uploadFile(MultipartFile file, Folder folder) {
3942
String sanitizedName = sanitizeFileName(file.getOriginalFilename());
40-
String s3Key = folder.getPath() + "/" + UUID.randomUUID() + "_" + sanitizedName;
43+
String randomPrefix = UUID.randomUUID().toString();
44+
String s3Key = folder.getPath() + "/" + randomPrefix + "_" + sanitizedName;
45+
46+
if (s3Key.length() > MAX_S3_KEY_LENGTH) {
47+
int excess = s3Key.length() - MAX_S3_KEY_LENGTH;
48+
sanitizedName = sanitizedName.substring(0, sanitizedName.length() - excess);
49+
s3Key = folder.getPath() + "/" + randomPrefix + "_" + sanitizedName;
50+
}
4151

4252
try {
4353
s3Client.putObject(
@@ -108,12 +118,23 @@ public String getPreSignedUrl(String s3Key) {
108118
}
109119

110120
private String sanitizeFileName(String originalFilename) {
111-
try {
112-
return URLEncoder.encode(originalFilename, StandardCharsets.UTF_8)
113-
.replaceAll("\\+", "%20");
114-
} catch (Exception e) {
115-
throw new RuntimeException("파일 이름 인코딩 실패", e);
121+
122+
String encoded = URLEncoder.encode(originalFilename, StandardCharsets.UTF_8)
123+
.replaceAll("\\+", "%20");
124+
125+
// 파일명만 잘라내기 (확장자 유지)
126+
String extension = "";
127+
int dotIndex = encoded.lastIndexOf('.');
128+
if (dotIndex != -1) {
129+
extension = encoded.substring(dotIndex);
130+
encoded = encoded.substring(0, dotIndex);
131+
}
132+
133+
if (encoded.length() > MAX_FILENAME_LENGTH) {
134+
encoded = encoded.substring(0, MAX_FILENAME_LENGTH);
116135
}
136+
137+
return encoded;
117138
}
118139

119140
private String shortenKey(String key) {

src/main/java/life/mosu/mosuserver/presentation/auth/AuthController.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.springframework.http.HttpHeaders;
1313
import org.springframework.http.HttpStatus;
1414
import org.springframework.http.ResponseEntity;
15+
import org.springframework.web.bind.annotation.GetMapping;
1516
import org.springframework.web.bind.annotation.PostMapping;
1617
import org.springframework.web.bind.annotation.RequestBody;
1718
import org.springframework.web.bind.annotation.RequestMapping;
@@ -42,15 +43,22 @@ public ResponseEntity<ApiResponseWrapper<LoginResponse>> login(
4243
));
4344
}
4445

46+
@GetMapping("/check-cookie")
47+
public ResponseEntity<Void> checkToken() {
48+
return ResponseEntity.ok().build();
49+
}
50+
51+
;
52+
4553
private HttpHeaders applyTokenHeader(Token token) {
4654
HttpHeaders headers = new HttpHeaders();
4755

48-
headers.add(HttpHeaders.SET_COOKIE, CookieBuilderUtil.createDevelopCookieString(
56+
headers.add(HttpHeaders.SET_COOKIE, CookieBuilderUtil.createLocalCookieString(
4957
CookieBuilderUtil.ACCESS_TOKEN_COOKIE_NAME,
5058
token.accessToken(),
5159
token.accessTokenExpireTime()
5260
));
53-
headers.add(HttpHeaders.SET_COOKIE, CookieBuilderUtil.createDevelopCookieString(
61+
headers.add(HttpHeaders.SET_COOKIE, CookieBuilderUtil.createLocalCookieString(
5462
CookieBuilderUtil.REFRESH_TOKEN_COOKIE_NAME,
5563
token.refreshToken(),
5664
token.refreshTokenExpireTime()

src/main/java/life/mosu/mosuserver/presentation/auth/AuthControllerDocs.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ public interface AuthControllerDocs {
1515
@Operation(description = "로그인 API 지금은 쿠키와 response 둘다 반환하는데 곧 쿠키로만 작동하게 할 것 입니다. <프론트하고 변경하려고 Response 이렇게 만들었는데 나중에 같이 맞춥시다!>", summary = "사용자가 로그인합니다.")
1616
public ResponseEntity<ApiResponseWrapper<LoginResponse>> login(
1717
@RequestBody @Valid final LoginRequest request);
18+
19+
@Operation(description = "쿠키 검증용 API", summary = "쿠키가 유효한지 확인합니다.")
20+
public ResponseEntity<Void> checkToken();
1821
}

0 commit comments

Comments
 (0)