Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
💗 Work Description
🔆 구현 과정
-
메인 홈
(794d204)request parameter
를 통해 전달받은Category
에 대한 유효성 검증은Controller
단에서 진행했습니다.String
값으로 전달 받은category
값을enum
타입의 객체로 변환함과 동시에 정의된 카테고리 값들 중에 해당하지 않는 경우에는 예외를 던집니다.jungyoon.shin/src/main/java/org/sopt/seminar2/diary/domain/enums/Category.java
Lines 20 to 26 in 7973e97
-
내 일기 모아보기
(7973e97)request header
에usename
과password
를 받아'인증'
및'인가'
처리를 하도록 구현했습니다!PASSWORD_HEADER
처럼 상수 처리 했습니다!jungyoon.shin/src/main/java/org/sopt/seminar2/diary/api/controller/DiaryController.java
Lines 77 to 86 in 7973e97
-
interceptor를 통한 유저 인가 기능 구현
(3e2c210)우선 일기 수정, 삭제 기능의 경우 해당 일기를 작성한 유저만 삭제 및 수정 권한을 가져야 한다고 판단했습니다!
해당 인가 처리를 어디서 할지 고민을 했는데요.. 고민한 방안은 다음과 같이 2가지였습니다!
제가 선택한 방법은 후자이며, 이유는 모든 컨트롤러 마다 1번과 같은 로직을 추가하기 보다는
interceptor
를 통해 전역적인 인가처리를 하는 것이 좋을 것 같다고 판단하였습니다.👉 1. 커스텀 어노테이션 생성
@Target
: 어노테이션이 사용될 위치를 지정합니다. (저는 메서드에 붙여서 사용할 거여서 다음과 같이 지정했습니다.)@Rentation
: 어노테이션이 유지되는 기간을 지정합니다.jungyoon.shin/src/main/java/org/sopt/seminar2/diary/api/annotation/CheckUserAuth.java
Lines 9 to 12 in 7973e97
👉 2.
HandlerIntercepto
r 인터페이스 구현handler
가 메서드인 경우 그리고 위에서 만든 어노테이션이 적용된 메서드일 경우에만 인가 로직을 거치게 됩니다.jungyoon.shin/src/main/java/org/sopt/seminar2/diary/api/interceptor/CheckUserAuthInterceptor.java
Lines 28 to 78 in 7973e97
👉 3.
Webconfig
에interceptor
등록jungyoon.shin/src/main/java/org/sopt/seminar2/diary/global/config/WebConfig.java
Lines 10 to 20 in 7973e97
💬 To Reviewers
request dto
객체 자체를service
단으로 전달하지 않고 풀어서 파라미터로 전달해보았습니다!🔗 Reference
interceptor를 통한 인가 처리