Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import java.util.stream.Collectors;

import org.bbagisix.category.service.CategoryService;
import org.bbagisix.exception.BusinessException;
import org.bbagisix.exception.ErrorCode;
import org.bbagisix.common.exception.BusinessException;
import org.bbagisix.common.exception.ErrorCode;
import org.bbagisix.expense.domain.ExpenseVO;
import org.bbagisix.expense.service.ExpenseService;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -24,7 +24,7 @@ public class AnalyticsServiceImpl implements AnalyticsService {
private final ExpenseService expenseService;
private final CategoryService categoryService;
private final RestTemplate restTemplate = new RestTemplate();

@Value("${LLM_SERVER_URL}")
private String llmServerUrl;

Expand Down
11 changes: 5 additions & 6 deletions src/main/java/org/bbagisix/asset/controller/AssetController.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package org.bbagisix.asset.controller;

import java.util.HashMap;
import java.util.Map;

import org.bbagisix.asset.dto.AssetDTO;
import org.bbagisix.asset.service.AssetService;
import org.bbagisix.exception.BusinessException;
import org.bbagisix.exception.ErrorCode;
import org.bbagisix.common.exception.BusinessException;
import org.bbagisix.common.exception.ErrorCode;
import org.bbagisix.user.dto.CustomOAuth2User;
import org.bbagisix.user.mapper.UserMapper;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -36,7 +35,7 @@ public ResponseEntity<Map<String, Object>> connectMainAsset(
@RequestBody AssetDTO assetDTO,
Authentication authentication
) {
try{
try {
Long userId = getUserId(authentication);

String userName = userMapper.getNameByUserId(userId);
Expand Down Expand Up @@ -89,7 +88,7 @@ public ResponseEntity<Map<String, Object>> deleteAsset(
@RequestParam String status, // main or sub
Authentication authentication
) {
try{
try {
Long userId = getUserId(authentication);
// 입력값 검증
if (userId == null) {
Expand Down Expand Up @@ -118,7 +117,7 @@ private Long getUserId(Authentication authentication) {
throw new BusinessException(ErrorCode.AUTHENTICATION_REQUIRED);
}

CustomOAuth2User curUser = (CustomOAuth2User) authentication.getPrincipal();
CustomOAuth2User curUser = (CustomOAuth2User)authentication.getPrincipal();

if (curUser == null) {
throw new BusinessException(ErrorCode.USER_ID_REQUIRED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.bbagisix.exception.BusinessException;
import org.bbagisix.exception.ErrorCode;
import org.bbagisix.common.exception.BusinessException;
import org.bbagisix.common.exception.ErrorCode;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

// MyBatis TypeHandler : DB 저장 시 자동 암호화, 조회 시 자동 복호화
@Component
public class AESEncryptedTypeHandler extends BaseTypeHandler<String> implements ApplicationContextAware{
public class AESEncryptedTypeHandler extends BaseTypeHandler<String> implements ApplicationContextAware {

private static EncryptionUtil encryptionUtil;
private static ApplicationContext applicationContext;
Expand All @@ -29,15 +29,16 @@ public void setApplicationContext(ApplicationContext applicationContext) {

// DB에 저장할 때 자동 암호화
@Override
public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType){
public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) {
try {
validateEncryptionUtil();
String encryptedValue = encryptionUtil.encryptAES(parameter);
ps.setString(i, encryptedValue);
} catch (SQLException err) {
throw new BusinessException(ErrorCode.ENCRYPTION_FAIL, "DB 저장 시 SQL 오류가 발생했습니다: " + err.getMessage());
} catch (Exception err) {
throw new BusinessException(ErrorCode.ENCRYPTION_FAIL, "DB 저장 시 암호화 처리 중 예상치 못한 오류가 발생했습니다: " + err.getMessage());
} catch (Exception err) {
throw new BusinessException(ErrorCode.ENCRYPTION_FAIL,
"DB 저장 시 암호화 처리 중 예상치 못한 오류가 발생했습니다: " + err.getMessage());
}
}

Expand All @@ -52,51 +53,57 @@ public String getNullableResult(ResultSet rs, String columnName) {
}
return encryptionUtil.decryptAES(encryptedValue);
} catch (SQLException e) {
throw new BusinessException(ErrorCode.ENCRYPTION_FAIL, "DB 조회 시 SQL 오류가 발생했습니다 (컬럼: " + columnName + "): " + e.getMessage());
throw new BusinessException(ErrorCode.ENCRYPTION_FAIL,
"DB 조회 시 SQL 오류가 발생했습니다 (컬럼: " + columnName + "): " + e.getMessage());
} catch (Exception e) {
throw new BusinessException(ErrorCode.ENCRYPTION_FAIL, "DB 조회 시 복호화 처리 중 예상치 못한 오류가 발생했습니다 (컬럼: " + columnName + "): " + e.getMessage());
throw new BusinessException(ErrorCode.ENCRYPTION_FAIL,
"DB 조회 시 복호화 처리 중 예상치 못한 오류가 발생했습니다 (컬럼: " + columnName + "): " + e.getMessage());
}
}


// DB에서 조회할 때 자동 복호화
@Override
public String getNullableResult(ResultSet rs, int columnIndex) {
try{
try {
validateEncryptionUtil();
String encryptedValue = rs.getString(columnIndex);
if (encryptedValue == null) {
return null;
}
return encryptionUtil.decryptAES(encryptedValue);
} catch (SQLException e) {
throw new BusinessException(ErrorCode.ENCRYPTION_FAIL, "DB 조회 시 SQL 오류가 발생했습니다 (컬럼 인덱스: " + columnIndex + "): " + e.getMessage());
throw new BusinessException(ErrorCode.ENCRYPTION_FAIL,
"DB 조회 시 SQL 오류가 발생했습니다 (컬럼 인덱스: " + columnIndex + "): " + e.getMessage());
} catch (Exception e) {
throw new BusinessException(ErrorCode.ENCRYPTION_FAIL, "DB 조회 시 복호화 처리 중 예상치 못한 오류가 발생했습니다 (컬럼 인덱스: " + columnIndex + "): " + e.getMessage());
throw new BusinessException(ErrorCode.ENCRYPTION_FAIL,
"DB 조회 시 복호화 처리 중 예상치 못한 오류가 발생했습니다 (컬럼 인덱스: " + columnIndex + "): " + e.getMessage());
}
}

// CallableStatement에서 조회할 때 자동 복호화
@Override
public String getNullableResult(CallableStatement cs, int columnIndex){
try{
public String getNullableResult(CallableStatement cs, int columnIndex) {
try {
validateEncryptionUtil();
String encryptedValue = cs.getString(columnIndex);
if (encryptedValue == null) {
return null;
}
return encryptionUtil.decryptAES(encryptedValue);
} catch (SQLException e) {
throw new BusinessException(ErrorCode.ENCRYPTION_FAIL, "CallableStatement 조회 시 SQL 오류가 발생했습니다 (컬럼 인덱스: " + columnIndex + "): " + e.getMessage());
throw new BusinessException(ErrorCode.ENCRYPTION_FAIL,
"CallableStatement 조회 시 SQL 오류가 발생했습니다 (컬럼 인덱스: " + columnIndex + "): " + e.getMessage());
} catch (Exception e) {
throw new BusinessException(ErrorCode.ENCRYPTION_FAIL, "CallableStatement 조회 시 복호화 처리 중 예상치 못한 오류가 발생했습니다 (컬럼 인덱스: " + columnIndex + "): " + e.getMessage());
throw new BusinessException(ErrorCode.ENCRYPTION_FAIL,
"CallableStatement 조회 시 복호화 처리 중 예상치 못한 오류가 발생했습니다 (컬럼 인덱스: " + columnIndex + "): " + e.getMessage());
}
}

// EncryptionUtil 주입 상태 검증
private void validateEncryptionUtil(){
private void validateEncryptionUtil() {
if (encryptionUtil == null) {
throw new BusinessException(ErrorCode.ENCRYPTION_FAIL, "EncryptionUtil이 AESEncryptedTypeHandler에 주입되지 않았습니다. Spring 설정을 확인해주세요.");
throw new BusinessException(ErrorCode.ENCRYPTION_FAIL,
"EncryptionUtil이 AESEncryptedTypeHandler에 주입되지 않았습니다. Spring 설정을 확인해주세요.");
}
}
}
24 changes: 12 additions & 12 deletions src/main/java/org/bbagisix/asset/encryption/EncryptionUtil.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.bbagisix.asset.encryption;

import org.bbagisix.exception.BusinessException;
import org.bbagisix.exception.ErrorCode;
import org.bbagisix.common.exception.BusinessException;
import org.bbagisix.common.exception.ErrorCode;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
Expand Down Expand Up @@ -43,7 +43,6 @@ public class EncryptionUtil {
@Value("${AES_SECRET_KEY}")
private String aesBase64SecretKey;


// RSA 암호화
public String encryptRSA(String plainText, String rsaBase64PublicKey) {
try {
Expand Down Expand Up @@ -78,7 +77,7 @@ public static String generateAESKey() {
SecretKey secretKey = keyGenerator.generateKey();

// 원시 바이트 -> base64 인코딩 -> String
return Base64.getEncoder().encodeToString(secretKey.getEncoded());
return Base64.getEncoder().encodeToString(secretKey.getEncoded());

} catch (NoSuchAlgorithmException err) {
throw new BusinessException(ErrorCode.ENCRYPTION_FAIL, "AES 알고리즘을 찾을 수 없습니다: " + err.getMessage());
Expand All @@ -87,10 +86,10 @@ public static String generateAESKey() {

// Base64 문자열을 SecretKey로 변환
private SecretKey base64ToKey(String base64KeyString) {
if(!StringUtils.hasText(base64KeyString)){
if (!StringUtils.hasText(base64KeyString)) {
throw new BusinessException(ErrorCode.ENCRYPTION_FAIL, "암호화 키가 설정되지 않았습니다.");
}
try{
try {
byte[] keyBytes = Base64.getDecoder().decode(base64KeyString);
return new SecretKeySpec(keyBytes, AES_ALGORITHM);
} catch (IllegalArgumentException err) {
Expand All @@ -100,10 +99,9 @@ private SecretKey base64ToKey(String base64KeyString) {
}
}


// AES 암호화
public String encryptAES (String plainText) {
if(!StringUtils.hasText(plainText) || plainText.startsWith(ENCRYPTION_PREFIX)){
public String encryptAES(String plainText) {
if (!StringUtils.hasText(plainText) || plainText.startsWith(ENCRYPTION_PREFIX)) {
return plainText;
}
try {
Expand All @@ -127,7 +125,7 @@ public String encryptAES (String plainText) {

// 접두사 붙여서 반환
return ENCRYPTION_PREFIX + Base64.getEncoder().encodeToString(encryptedWithIv);
} catch (NoSuchAlgorithmException err) {
} catch (NoSuchAlgorithmException err) {
throw new BusinessException(ErrorCode.ENCRYPTION_FAIL, "AES 알고리즘을 찾을 수 없습니다: " + err.getMessage());
} catch (NoSuchPaddingException err) {
throw new BusinessException(ErrorCode.ENCRYPTION_FAIL, "AES 패딩 방식을 찾을 수 없습니다: " + err.getMessage());
Expand Down Expand Up @@ -177,7 +175,8 @@ public String decryptAES(String encryptedText) {
byte[] decryptedBytes = cipher.doFinal(encryptedBytes);
return new String(decryptedBytes, "UTF-8");
} catch (IllegalArgumentException err) {
throw new BusinessException(ErrorCode.ENCRYPTION_FAIL, "Base64 디코딩에 실패했습니다. 잘못된 암호화 데이터 형식입니다: " + err.getMessage());
throw new BusinessException(ErrorCode.ENCRYPTION_FAIL,
"Base64 디코딩에 실패했습니다. 잘못된 암호화 데이터 형식입니다: " + err.getMessage());
} catch (NoSuchAlgorithmException err) {
throw new BusinessException(ErrorCode.ENCRYPTION_FAIL, "AES 알고리즘을 찾을 수 없습니다: " + err.getMessage());
} catch (NoSuchPaddingException err) {
Expand All @@ -189,7 +188,8 @@ public String decryptAES(String encryptedText) {
} catch (IllegalBlockSizeException err) {
throw new BusinessException(ErrorCode.ENCRYPTION_FAIL, "AES 복호화 블록 크기가 유효하지 않습니다: " + err.getMessage());
} catch (BadPaddingException err) {
throw new BusinessException(ErrorCode.ENCRYPTION_FAIL, "AES 복호화 중 패딩 오류가 발생했습니다. 잘못된 키이거나 손상된 데이터일 수 있습니다: " + err.getMessage());
throw new BusinessException(ErrorCode.ENCRYPTION_FAIL,
"AES 복호화 중 패딩 오류가 발생했습니다. 잘못된 키이거나 손상된 데이터일 수 있습니다: " + err.getMessage());
} catch (UnsupportedEncodingException err) {
throw new BusinessException(ErrorCode.ENCRYPTION_FAIL, "UTF-8 인코딩을 지원하지 않습니다: " + err.getMessage());
} catch (Exception err) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/bbagisix/asset/service/AssetService.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
import org.bbagisix.asset.dto.AssetDTO;
import org.bbagisix.asset.mapper.AssetMapper;
import org.bbagisix.classify.service.ClassifyService;
import org.bbagisix.codef.dto.CodefTransactionResDTO;
import org.bbagisix.codef.service.CodefApiService;
import org.bbagisix.exception.BusinessException;
import org.bbagisix.exception.ErrorCode;
import org.bbagisix.common.codef.dto.CodefTransactionResDTO;
import org.bbagisix.common.codef.service.CodefApiService;
import org.bbagisix.common.exception.BusinessException;
import org.bbagisix.common.exception.ErrorCode;
import org.bbagisix.expense.domain.ExpenseVO;
import org.bbagisix.expense.mapper.ExpenseMapper;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -185,7 +185,7 @@ private void saveTransactionHistory(Long assetId, Long userId, CodefTransactionR

if (!expenseVOList.isEmpty()) {
// log.info("llm start.." + expenseVOList.stream().toList());
try{
try {
expenseVOList = classifyService.classify(expenseVOList);
} catch (Exception e) {
log.info("llm err.." + e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import org.bbagisix.challenge.dto.ChallengeFailDTO;
import org.bbagisix.challenge.dto.ChallengeProgressDTO;
import org.bbagisix.challenge.service.ChallengeService;
import org.bbagisix.exception.BusinessException;
import org.bbagisix.exception.ErrorCode;
import org.bbagisix.common.exception.BusinessException;
import org.bbagisix.common.exception.ErrorCode;
import org.bbagisix.user.dto.CustomOAuth2User;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import org.bbagisix.challenge.dto.ChallengeFailDTO;
import org.bbagisix.challenge.dto.ChallengeProgressDTO;
import org.bbagisix.challenge.mapper.ChallengeMapper;
import org.bbagisix.exception.BusinessException;
import org.bbagisix.exception.ErrorCode;
import org.bbagisix.common.exception.BusinessException;
import org.bbagisix.common.exception.ErrorCode;
import org.bbagisix.expense.mapper.ExpenseMapper;
import org.bbagisix.tier.service.TierService;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -151,7 +151,7 @@ public void dailyCheck() {
.progress(c.getProgress() + 1)
.status(isLastDay ? "completed" : c.getStatus()) // 마지막 날인 경우 -> 최종 성공
.build();

// 챌린지 완료 시 tier 승급 처리
if (isLastDay) {
tierService.promoteUserTier(userId);
Expand All @@ -163,7 +163,7 @@ public void dailyCheck() {
}

// 실패시 해당 카테고리 지출 내역 가져오기
public List<ChallengeFailDTO> failChallenge(Long userId, Long challengeId){
public List<ChallengeFailDTO> failChallenge(Long userId, Long challengeId) {
return challengeMapper.getFailExpenditures(userId, challengeId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import org.bbagisix.chat.dto.response.ParticipantResponse;
import org.bbagisix.chat.dto.response.UserChallengeStatusResponse;
import org.bbagisix.chat.dto.response.UserChatRoomResponse;
import org.bbagisix.exception.BusinessException;
import org.bbagisix.exception.ErrorCode;
import org.bbagisix.common.exception.BusinessException;
import org.bbagisix.common.exception.ErrorCode;
import org.bbagisix.chat.service.ChatService;
import org.bbagisix.chat.service.ChatSessionService;
import org.bbagisix.user.dto.CustomOAuth2User;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.bbagisix.chat.service;

import org.bbagisix.chat.dto.ChatMessageDTO;
import org.bbagisix.exception.BusinessException;
import org.bbagisix.exception.ErrorCode;
import org.bbagisix.common.exception.BusinessException;
import org.bbagisix.common.exception.ErrorCode;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/bbagisix/chat/service/ChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import org.bbagisix.chat.dto.UserChallengeInfoDTO;
import org.bbagisix.chat.dto.response.UserChallengeStatusResponse;
import org.bbagisix.chat.entity.ChatMessage;
import org.bbagisix.exception.BusinessException;
import org.bbagisix.exception.ErrorCode;
import org.bbagisix.common.exception.BusinessException;
import org.bbagisix.common.exception.ErrorCode;
import org.bbagisix.chat.mapper.ChatMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;

import org.bbagisix.exception.BusinessException;
import org.bbagisix.exception.ErrorCode;
import org.bbagisix.common.exception.BusinessException;
import org.bbagisix.common.exception.ErrorCode;
import org.bbagisix.expense.domain.ExpenseVO;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
Expand All @@ -21,7 +21,7 @@
public class ClassifyServiceImpl implements ClassifyService {

private final RestTemplate restTemplate = new RestTemplate();

@Value("${LLM_SERVER_URL}")
private String llmServerUrl;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.bbagisix.codef.domain;
package org.bbagisix.common.codef.domain;

import java.util.Date;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.bbagisix.codef.dto;
package org.bbagisix.common.codef.dto;

import lombok.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.bbagisix.codef.dto;
package org.bbagisix.common.codef.dto;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.bbagisix.codef.mapper;
package org.bbagisix.common.codef.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.bbagisix.codef.domain.CodefAccessTokenVO;
import org.bbagisix.common.codef.domain.CodefAccessTokenVO;

@Mapper
public interface CodefAccessTokenMapper {
Expand Down
Loading