diff --git a/src/main/java/com/eactive/apim/portal/file/service/FileService.java b/src/main/java/com/eactive/apim/portal/file/service/FileService.java index 66497d2..d3438fb 100644 --- a/src/main/java/com/eactive/apim/portal/file/service/FileService.java +++ b/src/main/java/com/eactive/apim/portal/file/service/FileService.java @@ -29,6 +29,30 @@ public class FileService { private final BinaryStorageService binaryStorageService; private final FileTypeDetector fileTypeDetector; + private static final ThreadLocal internalUserContext = new ThreadLocal<>(); + + /** + * 현재 스레드에 내부 사용자 컨텍스트 설정 + */ + public static void setInternalUserContext(boolean isInternal) { + internalUserContext.set(isInternal); + } + + /** + * 내부 사용자 컨텍스트 조회 + */ + public static boolean isInternalUserContext() { + Boolean isInternal = internalUserContext.get(); + return isInternal != null && isInternal; + } + + /** + * 내부 사용자 컨텍스트 정리 + */ + public static void clearInternalUserContext() { + internalUserContext.remove(); + } + /** * 특정 파일 ID를 기반으로 파일 정보를 검색합니다. * @@ -71,8 +95,15 @@ public class FileService { String type = fileTypeDetector.detectFileType(file.getBytes()); log.debug("upload file type:{}", type); - if(type.equalsIgnoreCase("unknown")) { - throw new InvalidFileException("허용된 파일 형식이 아닙니다.
문서파일과 이미지 파일만 등록 가능합니다.
(pdf, doc, docx, xls, xlsx, ppt, pptx, hwp, gif, jpg, png)"); + boolean isValidType = !type.equalsIgnoreCase("unknown"); + + if (!isValidType) { + if (isInternalUserContext()) { + log.warn("Internal user bypassed file validation - File: {}, Type: {}", + file.getOriginalFilename(), type); + } else { + throw new InvalidFileException("허용된 파일 형식이 아닙니다.
문서파일과 이미지 파일만 등록 가능합니다.
(pdf, doc, docx, xls, xlsx, ppt, pptx, hwp, gif, jpg, png)"); + } } if (StringUtils.isNotBlank(file.getOriginalFilename()) && file.getSize() > 0) { @@ -82,7 +113,13 @@ public class FileService { fileDetail.setFileSn(fileSn); fileDetail.setFileSize((int) file.getSize()); fileDetail.setOriginalFileName(FilenameUtils.getBaseName(file.getOriginalFilename())); - fileDetail.setFileExtension(type); + + if (isValidType) { + fileDetail.setFileExtension(type); + } else { + fileDetail.setFileExtension(FilenameUtils.getExtension(file.getOriginalFilename())); + } + String contentReference = binaryStorageService.store(file.getBytes()); fileDetail.setFileContents(contentReference); fileInfo.getFileDetails().add(fileDetail); @@ -232,12 +269,17 @@ public class FileService { String type = fileTypeDetector.detectFileType(file.getBytes()); log.debug("upload file type:{}", type); - if (isCheckMime) { - if(type.equalsIgnoreCase("unknown")) { - throw new InvalidFileException("허용된 파일 형식이 아닙니다.
문서파일과 이미지 파일만 등록 가능합니다.
(pdf, doc, docx, xls, xlsx, ppt, pptx, hwp, gif, jpg, png)"); - } - } else { - log.debug("파일 체크 옵션 해제 - FileType : {}", type); + boolean isValidType = !type.equalsIgnoreCase("unknown"); + + if (isCheckMime && !isValidType) { + if (isInternalUserContext()) { + log.warn("Internal user bypassed file validation - File: {}, Type: {}", + fileName, type); + } else { + throw new InvalidFileException("허용된 파일 형식이 아닙니다.
문서파일과 이미지 파일만 등록 가능합니다.
(pdf, doc, docx, xls, xlsx, ppt, pptx, hwp, gif, jpg, png)"); + } + } else if (!isCheckMime) { + log.debug("파일 체크 옵션 해제 - FileType : {}", type); } FileDetail fileDetail = new FileDetail();