-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor/#156 api 인가처리 #161
Conversation
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 워크스루이 풀 리퀘스트는 여러 관리자 컨트롤러에 변경 사항
연결된 이슈에 대한 평가
관련 가능성 있는 PR
추천 리뷰어
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생 많으셨습니다! 😊 현재 USER 권한으로 관리자(Admin 전용) 엔드포인트에 접근할 경우 500 Internal Server Error가 발생하고 있다고 하셨는데요, 이 상황에서는 403 Forbidden을 반환하도록 수정하는 것이 어떨까 제안드립니다.
제안 이유
- HTTP 표준 준수: 권한 부족 상황에는 403 Forbidden이 적합하며, 500 에러는 서버 내부 문제를 의미하기 때문에 상황에 맞지 않습니다.
- 보안 강화: 500 에러는 서버 내부 오류로 오해를 살 수 있어, 잠재적 공격자에게 불필요한 힌트를 줄 가능성이 있습니다.
- 사용자 경험 개선: 클라이언트가 요청 실패 이유를 명확히 알 수 있도록, 권한 부족임을 403 상태 코드로 전달하는 것이 바람직합니다.
- 디버깅 효율성: 500 에러는 서버 측 문제로 간주되어 불필요한 디버깅을 유발할 수 있습니다. 반면 403 Forbidden은 권한 문제를 명확히 표현합니다.
권한 부족 상황에서 403 Forbidden이 반환될 수 있도록 Spring Security 설정과 예외 처리 로직을 점검해주시면 좋을 것 같습니다!
민준님 말씀대로 403 에러를 반환하도록 수정하는 것이 더 명확하고 우수할것으로 생각됩니다. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수고 많으셨습니다 👍
깔끔한 코드 보기 좋았고, 고민한 흔적도 많이 보이네요.
추가적으로 @LeeShinHaeng 님이 PR에 작성해주신 것처럼 현재는 로그인 시 ROLE_USER 임의 설정하고 있지만, 관리자로 로그인 시 ADMIN 권한을 주도록 변경해야합니다.
이 작업도 진행해주실 수 있을까요? 이번 PR에서 처리하는게 좋아보이네요~
@RestControllerAdvice | ||
public class AdminAuthorizeExceptionHandler { | ||
@ExceptionHandler(AccessDeniedException.class) | ||
public ResponseEntity<ExceptionResponse> handleAccessDeniedException() { | ||
ExceptionResponse response = ExceptionResponse.from(NOT_ADMIN); | ||
return ResponseEntity.status(FORBIDDEN).body(response); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AdminAuthorizeExceptionHandler
를 GlobalExceptionHandler
에 포함시키지 않고 분리한 이유가 있나요?
가능하다면 예외 핸들링 처리는 하나의 클래스에서 수행하는 것이, 예외 처리 로직 전반을 중앙에서 관리하고, 가독성을 향상시키는데 도움이 될 것 같습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Admin 접근시에만 사용하는 ExceptionHandler여서 분리했습니다.
하지만 말씀대로 하나의 클래스에서 관리하는게 가독성 측면에서 나을 것 같습니다!
93aea42 에서 반영했습니다
b623440 에서 반영 완료했습니다! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM😁
Summary
관리자 API 인가 처리 및 퍼블릭 API permitAll
Tasks
To Reviewer
현재는 로그인 시 ROLE_USER 임의 설정하고 있지만, 관리자로 로그인 시 ADMIN 권한을 주도록 변경해야합니다. (TokenAuthenticationFilter#doFilterInternal -> TokenProvider#getAuthentication 참고)
Screen Shot
일반 사용자로 로그인 후 Post Create
![스크린샷 2025-01-06 10 02 26](https://private-user-images.githubusercontent.com/72925577/400264974-2ac675d7-e222-4b6e-ac18-94f6b4359399.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2MzIzMDAsIm5iZiI6MTczOTYzMjAwMCwicGF0aCI6Ii83MjkyNTU3Ny80MDAyNjQ5NzQtMmFjNjc1ZDctZTIyMi00YjZlLWFjMTgtOTRmNmI0MzU5Mzk5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE1VDE1MDY0MFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTQ3NTlkN2M5ZTQ2ZDhlY2U0MTk1ODQ1YzY4NTljNjQ5MjVjYmNhZDZiMmY3YjlmZWM0YjBlNDc1NWFkZWJhODMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.z3WK5JbU9SDHAvz7PMXOAN8aZhovitRyE2nP2NiTz-0)
Admin 사용자 DB에 생성
![스크린샷 2025-01-06 10 05 40](https://private-user-images.githubusercontent.com/72925577/400265014-b733e4ee-b857-4522-af32-e725c13cf98d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2MzIzMDAsIm5iZiI6MTczOTYzMjAwMCwicGF0aCI6Ii83MjkyNTU3Ny80MDAyNjUwMTQtYjczM2U0ZWUtYjg1Ny00NTIyLWFmMzItZTcyNWMxM2NmOThkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE1VDE1MDY0MFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTZhM2ViMDRkMGQ5Y2U3NDdkMzI0YjQyMjMzMTkxNmUzMDJkZjg1OTVhZTEzNDJhYzdlNmQxOWExYjFhNmMwNzImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.CKMO3BKC3AwWR50_kP6Em06VZQjMzEQK71Y6lRszJD4)
Admin 사용자로 로그인 후 Post Create
![스크린샷 2025-01-06 10 02 34](https://private-user-images.githubusercontent.com/72925577/400265075-b248b6a6-b316-416d-addc-c6908fd598a0.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2MzIzMDAsIm5iZiI6MTczOTYzMjAwMCwicGF0aCI6Ii83MjkyNTU3Ny80MDAyNjUwNzUtYjI0OGI2YTYtYjMxNi00MTZkLWFkZGMtYzY5MDhmZDU5OGEwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE1VDE1MDY0MFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWE3YzdkYzNlZTA2ZTJhMDE5YjVlZmMzOTc4MmRmNDc1MzBiYWJlOTgyMWM1N2UzOTAxNDQxMDUzNDhiZmE4OWEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.9mAd1_ENRDFuNv7l_y_FcsWZwyjyM7sjPeWb2dd6QUQ)