-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 게스트 로그인 구현 #12
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
Merged
Merged
feat: 게스트 로그인 구현 #12
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
489f37d
feat: 게스트 권한 추가
Uralauah f772932
refact: redis 함수 수정
Uralauah c4f3d4e
refact: User builder 수정
Uralauah 4ac34e2
feat: 게스트 ttl 설정
Uralauah b5f1f16
feat: RandomNicknameGenerator 작성
Uralauah 1109106
feat: UserDetails 닉네임 반환 함수 작성
Uralauah f5ad1f7
feat: 게스트 인증 로직 수정
Uralauah aaffeee
feat: 게스트 로그인 기능 구현
Uralauah 578782d
refact: 일반 사용자, 게스트 토큰 발급 로직 구별
Uralauah 8ea710a
refact: 변수 및 함수명 수정
Uralauah 651d7b3
refact: GuestDetailsService 분리
Uralauah eb281ce
chore: 폴더 구조 변경
Uralauah 8f9db8b
Merge branch 'develop' into feat/guest
Uralauah 412d711
refact: guest prefix 상수 정의
Uralauah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/Gotcha/domain/auth/util/RandomNicknameGenerator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package Gotcha.domain.auth.util; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.Random; | ||
|
|
||
| public class RandomNicknameGenerator { | ||
| private static final List<String> adjectives = Arrays.asList( | ||
| "귀여운", "무서운", "배고픈", "졸린", "쓸쓸한", "취한", "웃긴", "멋진", "시끄러운", "느린" | ||
| ); | ||
|
|
||
| private static final List<String> nouns = Arrays.asList( | ||
| "고양이", "강아지", "곰", "너구리", "햄스터", "호랑이", "펭귄", "낙타", "토끼", "벌새" | ||
| ); | ||
|
|
||
| private static final Random random = new Random(); | ||
|
|
||
| public static String generateNickname() { | ||
| String nickname; | ||
|
|
||
| do { | ||
| String adj = adjectives.get(random.nextInt(adjectives.size())); | ||
| String noun = nouns.get(random.nextInt(nouns.size())); | ||
| nickname = adj + noun; | ||
| } while (nickname.length() > 6); | ||
|
|
||
| return nickname; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
UserDetailsService를 상속받는 GuestDetailsService Interface를 작성 후에
요런 식으로 하는게 책임분리도 되고 좋지 않을까용? 아직 서비스 크기가 크진 않으니까 UserDetailsServiceImpl에 몰아도 상관 없을 것 같지만, Guest와 User가 성격 자체가 조금은 다르니 별도의 DetailsService에서 처리해주어도 좋다고 생각합니다.
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.
Guest와 User가 완전히 다른 엔터티가 아니고 같은 엔터티니까 UserDetailsService에서 전부 처리하는 것도 맞는 것 같지만, 그렇다고 loadUserByUsername() 함수 안에 Guest, User에 대한 로직을 합쳐서 username 조건에 따라 분기하는 방법을 쓰기에는 Guest는 unique한 email이 저장되지 않으니 좋은 방법은 아닌 것 같습니다.
하나의 UserDetailsService.loadUserByUsername() 에서 전부 로직을 처리하려면
여기서 username 대신에 "guest" 를 넣어서 loadUserByUsername에서 username.equals("guest") 로 분기를 하는 방법도 가능할 것 같습니당!!
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.
모든 방법이 전부 근거가 있는 것 같아서 같이 논의해보면 좋을 것 같습니다!
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.
맞습니다! 저도 분리하는게 더 나은 방법인 것 같긴합니다
민주님도 동의하신다면 바로 수정하도록 하겠습니다!
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.
게스트 토큰을 만들 때, usetName에 게스트임을 구분할 수 있게 "guest"라는 고정된 값을 넣자는 게 좋은 의견인 것 같아! 로컬에서 한 번 구현을 해보았습니다. 가능할 것 이라고 생각하나, 직접 구현을 해보니 제가 생각하기에 해당 로직은 다음과 같은 단점을 지녔던 것 같습니다.
단순 저의 생각으로 구현을 해본 것임을 감안해주세요!
현재 방법 : userDetailsService 함수 하나로 전부 처리해보자!
1. token 생성 단계
2. JwtAuthenticationFilter는 코드 변경 X
3. UserDetailsServiceImpl
loadUserByUsername은 제공되는 함수라 인자를 userName밖에 못 받아서 String 파싱을 통해 구현함.
다음과 같이 코드를 변경 했을 때 다음과 같은 장점을 지니는 것 같습니다.
그러나 단점이 더 큽니다.
-> 그러나 String 파싱을 통한 코드 구현을 하면 우리만의 새로운 인가 흐름이 생기는 것.
-> 본인 외 다른 개발자들이 보기에는 자연스럽지 못한 코드 흐름으로 가독성 측면에서 좋지 않음.
-> 각 케이스 별 로직 처리도 달라, 사실상 하나의 함수가 너무 많은 일을 하는 중
-> 만약 여기서 권한이 더 늘어나야 한다면 하드코딩 + 가독성 최악 + srp 파괴 의 함수가 될 것으로 예상
결론 : JwtAuthentication에서 토큰 내 권한으로 분기처리를 하는 방법 추천.
형준 선배의 첫 번째 의견처럼
GuestDetailsService guestDetailsService;
UserDetailsService userDetailsService;
이 srp 원칙 준수 + 권한 기반 인가 시스템 로직 유지 + 가독성 최고
일 것 같습니다.