-
Notifications
You must be signed in to change notification settings - Fork 1
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: memberService에서 인증관련 로직 분리 #878
Open
coli-geonwoo
wants to merge
17
commits into
develop
Choose a base branch
from
feature/877
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d4b594f
refactor: token tagging interface로 로직 통일
955b5bc
refactor: AuthorizationType 구현체에 따른 분기 구현
639d456
refactor: 다형성을 통해 인증로직 구성
a4a76cc
refactor: 불필요한 delimiter 삭제
52faa43
refactor: 분기된 메서드 다시 생성
f847a27
refactor: token으로 추상화
214fe46
test: apiCall 테스트 조회 기간 수정
71fe61a
chore: token을 jwtToken으로 rename
3c1e4e5
chore: authPolicy로 rename
9f953b6
chore: 파라미터명 rename
607517a
refactor: authorize에 트랜잭션 추가
4071ef3
style: 개행 추가
8bdf327
style: 컨벤션 준수
a4e1e28
test: 불필요한 필드 제외 삭제
a862039
chore: 매개변수 명 변경
5d2ca70
style: 개행 통일
8ac4fcb
chore: 메서드 명 리네이밍
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 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 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 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,30 @@ | ||
package com.ody.auth.domain; | ||
|
||
import com.ody.auth.domain.logincontext.LoginContext; | ||
import com.ody.common.exception.OdyUnauthorizedException; | ||
import com.ody.member.domain.Member; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class Authorizer { | ||
|
||
private final List<LoginContext> authPolicies; | ||
|
||
@Transactional | ||
public Member authorize( | ||
Optional<Member> sameDeviceMember, | ||
Optional<Member> sameProviderIdMember, | ||
Member requestMember | ||
) { | ||
return authPolicies.stream() | ||
.filter(type -> type.match(sameDeviceMember, sameProviderIdMember, requestMember)) | ||
.findAny() | ||
.orElseThrow(() -> new OdyUnauthorizedException("잘못된 인증 요청입니다.")) | ||
.syncDevice(sameDeviceMember, sameProviderIdMember, requestMember); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
backend/src/main/java/com/ody/auth/domain/logincontext/ExistingUserForExistingDevice.java
This file contains 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 com.ody.auth.domain.logincontext; | ||
|
||
import com.ody.member.domain.Member; | ||
import java.util.Optional; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ExistingUserForExistingDevice implements LoginContext { | ||
|
||
@Override | ||
public boolean match( | ||
Optional<Member> sameDeviceMember, | ||
Optional<Member> sameProviderIdMember, | ||
Member requestMember | ||
) { | ||
return sameDeviceMember.isPresent() | ||
&& sameProviderIdMember.isPresent() | ||
&& requestMember.isSame(sameDeviceMember.get()); | ||
} | ||
|
||
@Override | ||
public Member syncDevice( | ||
Optional<Member> sameDeviceMember, | ||
Optional<Member> sameProviderIdMember, | ||
Member requestMember | ||
) { | ||
return sameProviderIdMember.get(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
backend/src/main/java/com/ody/auth/domain/logincontext/ExistingUserForNewDevice.java
This file contains 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,30 @@ | ||
package com.ody.auth.domain.logincontext; | ||
|
||
import com.ody.member.domain.Member; | ||
import java.util.Optional; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ExistingUserForNewDevice implements LoginContext { | ||
|
||
@Override | ||
public boolean match( | ||
Optional<Member> sameDeviceMember, | ||
Optional<Member> sameProviderIdMember, | ||
Member requestMember | ||
) { | ||
return sameDeviceMember.isEmpty() | ||
&& sameProviderIdMember.isPresent(); | ||
} | ||
|
||
@Override | ||
public Member syncDevice( | ||
Optional<Member> sameDeviceMember, | ||
Optional<Member> sameProviderIdMember, | ||
Member requestMember | ||
) { | ||
Member sameAuthProviderMember = sameProviderIdMember.get(); | ||
sameAuthProviderMember.updateDeviceToken(requestMember.getDeviceToken()); | ||
return sameAuthProviderMember; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
backend/src/main/java/com/ody/auth/domain/logincontext/LoginContext.java
This file contains 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,19 @@ | ||
package com.ody.auth.domain.logincontext; | ||
|
||
import com.ody.member.domain.Member; | ||
import java.util.Optional; | ||
|
||
public interface LoginContext { | ||
|
||
boolean match( | ||
Optional<Member> sameDeviceMember, | ||
Optional<Member> sameProviderIdMember, | ||
Member requestMember | ||
); | ||
|
||
Member syncDevice( | ||
Optional<Member> sameDeviceMember, | ||
Optional<Member> sameProviderIdMember, | ||
Member requestMember | ||
); | ||
} |
29 changes: 29 additions & 0 deletions
29
backend/src/main/java/com/ody/auth/domain/logincontext/NewUserForExistingDevice.java
This file contains 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 com.ody.auth.domain.logincontext; | ||
|
||
import com.ody.member.domain.Member; | ||
import java.util.Optional; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class NewUserForExistingDevice implements LoginContext { | ||
|
||
@Override | ||
public boolean match( | ||
Optional<Member> sameDeviceMember, | ||
Optional<Member> sameProviderIdMember, | ||
Member requestMember | ||
) { | ||
return sameDeviceMember.isPresent() | ||
&& sameProviderIdMember.isEmpty(); | ||
} | ||
|
||
@Override | ||
public Member syncDevice( | ||
Optional<Member> sameDeviceMember, | ||
Optional<Member> sameProviderIdMember, | ||
Member requestMember | ||
) { | ||
sameDeviceMember.get().updateDeviceTokenNull(); | ||
return requestMember; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
backend/src/main/java/com/ody/auth/domain/logincontext/NewUserForNewDevice.java
This file contains 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,28 @@ | ||
package com.ody.auth.domain.logincontext; | ||
|
||
import com.ody.member.domain.Member; | ||
import java.util.Optional; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class NewUserForNewDevice implements LoginContext { | ||
|
||
@Override | ||
public boolean match( | ||
Optional<Member> sameDeviceMember, | ||
Optional<Member> sameProviderIdMember, | ||
Member requestMember | ||
) { | ||
return sameDeviceMember.isEmpty() | ||
&& sameProviderIdMember.isEmpty(); | ||
} | ||
|
||
@Override | ||
public Member syncDevice( | ||
Optional<Member> sameDeviceMember, | ||
Optional<Member> sameProviderIdMember, | ||
Member requestMember | ||
) { | ||
return requestMember; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
backend/src/main/java/com/ody/auth/domain/logincontext/OtherUserForExistingDevice.java
This file contains 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,31 @@ | ||
package com.ody.auth.domain.logincontext; | ||
|
||
import com.ody.member.domain.Member; | ||
import java.util.Optional; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class OtherUserForExistingDevice implements LoginContext { | ||
|
||
@Override | ||
public boolean match( | ||
Optional<Member> sameDeviceMember, | ||
Optional<Member> sameProviderIdMember, | ||
Member requestMember | ||
) { | ||
return sameDeviceMember.isPresent() | ||
&& sameProviderIdMember.isPresent() | ||
&& !requestMember.isSame(sameDeviceMember.get()); | ||
} | ||
|
||
@Override | ||
public Member syncDevice( | ||
Optional<Member> sameDeviceMember, | ||
Optional<Member> sameProviderIdMember, | ||
Member requestMember | ||
) { | ||
sameDeviceMember.get().updateDeviceTokenNull(); | ||
sameProviderIdMember.get().updateDeviceToken(requestMember.getDeviceToken()); | ||
return sameProviderIdMember.get(); | ||
} | ||
} |
This file contains 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 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 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,10 @@ | ||
package com.ody.auth.token; | ||
|
||
import com.ody.auth.AuthProperties; | ||
|
||
public interface JwtToken { | ||
|
||
String getSecretKey(AuthProperties authProperties); | ||
|
||
String getValue(); | ||
} |
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
이곳에 Transactional이 있는 게 바로 이해가 안 가긴 하네요 🤔🤔
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.
처음에는 뗀 상태로 구현하긴 했어요.
그러나 조조의 다음 의견에 동의하여서 붙여주었습니다.
#878 (comment)