Projects
-
Sneakers Mania - Summernote 이미지 파일 업로드 시 고유 URL 생성Projects/Problem & Solution 2022. 1. 29. 12:09
개요 문제점 Summernote는 이미지 파일 업로드 시 base64로 인코딩을 한 후 저장하는 방식이기 때문에, 보안성은 뛰어나지만 이미지 파일 관리가 매우 어렵다는 단점이 있다. 예를 들어서, 고화질의 이미지 파일을 업로드했을 때 DB의 용량을 많이 차지한다는 점과 해당 이미지 파일을 조회할 경우 업로드 시간이 많이 소요된다는 점이다. 해결 방안 Summernote가 제공하는 callback 함수를 이용하여, 이미지를 특정 경로에 업로드한 후 고유한 URL을 리턴하는 방식으로 해결해 보았다. 추가로, URL을 통한 외부 리소스 접근을 위해 톰캣 설정도 별도로 필요하다. 구현 방법 1. Summernote callback 함수 ㆍ Summernote에서는 몇 개의 callback 함수를 지원한다. ㆍ ..
-
Sneakers Mania - 더티 체킹(Dirty Checking)Projects/Problem & Solution 2022. 1. 4. 14:12
더티 체킹(Dirty Checking) 더티 체킹(Dirty Checking)이란? JPA는 EntityManager가 Entity를 저장/조회/수정/삭제를 한다. 그런데, EntityManager의 메서드를 찾아보면, 저장(persist)/조회(find)/삭제(delete)로 수정에 해당하는 메서드는 존재하지 않는다. 대신에 더티 체킹(Dirty Checking)이라는 개념이 존재한다. 더티 체킹은 트랜잭션 안에서 Entity의 변경이 일어나면, 변경 내용은 자동으로 DB에 반영하는 JPA의 특징이다. 또한, 영속성 컨텍스트 안에 있는 Entity를 대상으로 더티 체킹이 발생한다. 여기서 Dirty란 Entity 데이터의 변경된 부분으로 해석하면 된다. 즉, Entity의 변경된 부분을 확인해서 DB에..
-
Sneakers Mania - @ControllerAdvice, @ExceptionHandler를 이용한 전역 예외 처리Projects/Problem & Solution 2022. 1. 3. 13:42
개요 문제점 존재하지 않는 게시물을 조회하거나 존재하지 않는 게시물을 수정하는 등 예기치 못한 상황에서 발생하는 예외들을 전역적으로 처리할 필요가 있었다. 기존에는 각 비즈니스 로직을 담당하는 메서드 내 try-catch 문을 사용해서 예외처리를 하였으나, 이런 방식으로 예외처리를 하면 프로그램이 커지고 기능이 추가됨에 따라 유지보수가 어렵고, 코드가 복잡해지겠다고 생각하였다. 이러한 문제를 개선시키고자 전역적으로 예외를 관리할 수 있는 방법을 모색하였다. 해결 방안 애너테이션 설명 @ControllerAdvice 모든 Controller에서 발생할 수 있는 Exception을 전역으로 처리하기 위해 사용 @ExceptionHandler 컨트롤러 내 특정 Exception을 처리하기 위한 애너테이션 "@..
-
Sneakers Mania - ENUM 타입을 이용한 사용자 권한 처리Projects/Problem & Solution 2021. 12. 31. 23:35
개요 문제점 사용자가 회원가입을 할 때, 사용자의 권한에 대한 속성을 지정할 필요가 있었다. 사용자의 권한은 일반 사용자를 뜻하는 USER, 관리자를 뜻하는 ADMIN이 있다. 단순히 문자열 형태로 설정할 수 있었지만, 개발자가 권한을 설정하는 과정에서 USER, ADMIN 권한 외에 다른 값을 넣을 수도 있다는 위험이 존재했다. 따라서, 사용자 권한에 대해 강제성을 부여할 수 있는 방법이 필요했다. 해결 방안 RoleType이라는 ENUM 타입의 클래스를 생성하고, 해당 클래스의 속성으로 일반 사용자를 뜻하는 USER, 관리자를 뜻하는 ADMIN을 선언하였다. 사용자 권한에 대한 속성을 RoleType으로 지정하고, 해당 권한 값을 강제로 2개만 설정할 수 있게 한다. 이렇게 함으로써, 개발자가 사용자..
-
Sneakers Mania - 카카오 로그인(4)Projects/Problem & Solution 2021. 12. 28. 15:01
액세스 토큰 자바 객체로 매핑 1. OAuthToken 클래스 생성 @Data public class OAuthToken { private String access_token; private String token_type; private String refresh_token; private int expires_in; private String scope; private int refresh_token_expires_in; } ㆍ 카카오 서버로부터 전달받은 액세스 토큰을 자바 객체로 매핑하기 위한 클래스를 생성한다. 2. 자바 객체로 매핑 ObjectMapper objectMapper = new ObjectMapper(); OAuthToken oAuthToken = objectMapper.readVal..
-
Sneakers Mania - 카카오 로그인(3)Projects/Problem & Solution 2021. 12. 27. 21:02
인증 코드 받기 인증 코드란? 인증 코드 받기는 카카오 로그인을 시작하는 단계로써, 카카오 로그인 동의 화면을 호출하고, 사용자 동의를 거쳐 인증 코드 발급을 요청하는 API이다. 사용자는 동의 화면에서 서비스 이용 시 필요한 사용자 정보 및 권한 제공에 동의하고 로그인을 요청하거나 로그인을 취소할 수 있다. 사용자가 필수 동의 항목에 모두 동의한 뒤 "동의하고 계속하기" 버튼을 누르면, 카카오 인증 서버는 해당 사용자에 대한 인증 코드를 발급해 서비스의 redirect_uri에 전달한다. 인증 코드를 요청하기 위한 URI는 카카오 개발자 홈페이지에서 확인할 수 있으며, 위 사진과 같다. 1. 인증 코드 요청 ㆍ loginForm.jsp 파일에 카카오 로그인 버튼을 생성한 후, href 속성에 위에서 확..