-
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
base: develop
Are you sure you want to change the base?
Changes from all commits
d4b594f
955b5bc
639d456
a4a76cc
52faa43
f847a27
214fe46
71fe61a
3c1e4e5
9f953b6
607517a
4071ef3
8bdf327
a4e1e28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.ody.auth.domain; | ||
|
||
import com.ody.auth.domain.authpolicy.AuthPolicy; | ||
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<AuthPolicy> authPolicies; | ||
|
||
@Transactional | ||
public Member authorize( | ||
Optional<Member> sameDeviceMember, | ||
Optional<Member> samePidMember, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Authorizer의 authorize() 인자에는 반영이 안 되어 있어요! |
||
Member requestMember | ||
) { | ||
return authPolicies.stream() | ||
.filter(type -> type.match(sameDeviceMember, samePidMember, requestMember)) | ||
.findAny() | ||
.orElseThrow(() -> new OdyUnauthorizedException("잘못된 인증 요청입니다.")) | ||
.authorize(sameDeviceMember, samePidMember, requestMember); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.ody.auth.domain.authpolicy; | ||
|
||
import com.ody.member.domain.Member; | ||
import java.util.Optional; | ||
|
||
public interface AuthPolicy { | ||
|
||
boolean match( | ||
Optional<Member> sameDeviceMember, | ||
Optional<Member> sameProviderIdMember, | ||
Member requestMember | ||
); | ||
Comment on lines
+8
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [제안] 인터페이스랑 구현체에서 개행이 되었다 안 되었다 하네요?? 하나로 통일하면 좋을 것 같아요 |
||
|
||
Member authorize( | ||
Optional<Member> sameDeviceMember, | ||
Comment on lines
+14
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [제안] 현재 authorize 메서드가 수행하고 있는 동작이 개인적으론 권한 부여로 보이지 않는데, 아래와 같은 네이밍은 어떤가요?
|
||
Optional<Member> sameProviderIdMember, | ||
Member requestMember | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.ody.auth.domain.authpolicy; | ||
|
||
import com.ody.member.domain.Member; | ||
import java.util.Optional; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ExistingUserForExistingDevice implements AuthPolicy { | ||
|
||
@Override | ||
public boolean match(Optional<Member> sameDeviceMember, Optional<Member> sameProviderIdMember, Member requestMember) { | ||
return sameDeviceMember.isPresent() | ||
&& sameProviderIdMember.isPresent() | ||
&& requestMember.isSame(sameDeviceMember.get()); | ||
} | ||
|
||
@Override | ||
public Member authorize(Optional<Member> sameDeviceMember, Optional<Member> sameProviderIdMember, Member requestMember) { | ||
return sameProviderIdMember.get(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.ody.auth.domain.authpolicy; | ||
|
||
import com.ody.member.domain.Member; | ||
import java.util.Optional; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ExistingUserForNewDevice implements AuthPolicy { | ||
|
||
@Override | ||
public boolean match( | ||
Optional<Member> sameDeviceMember, | ||
Optional<Member> sameProviderIdMember, | ||
Member requestMember | ||
) { | ||
return sameDeviceMember.isEmpty() | ||
&& sameProviderIdMember.isPresent(); | ||
} | ||
|
||
@Override | ||
public Member authorize(Optional<Member> sameDeviceMember, Optional<Member> sameProviderIdMember, Member requestMember) { | ||
Member sameAuthProviderMember = sameProviderIdMember.get(); | ||
sameAuthProviderMember.updateDeviceToken(requestMember.getDeviceToken()); | ||
return sameAuthProviderMember; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.ody.auth.domain.authpolicy; | ||
|
||
import com.ody.member.domain.Member; | ||
import java.util.Optional; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class NewUserForExistingDevice implements AuthPolicy { | ||
|
||
@Override | ||
public boolean match( | ||
Optional<Member> sameDeviceMember, | ||
Optional<Member> sameProviderIdMember, | ||
Member requestMember | ||
) { | ||
return sameDeviceMember.isPresent() | ||
&& sameProviderIdMember.isEmpty(); | ||
} | ||
|
||
@Override | ||
public Member authorize( | ||
Optional<Member> sameDeviceMember, | ||
Optional<Member> sameProviderIdMember, | ||
Member requestMember | ||
) { | ||
sameDeviceMember.get().updateDeviceTokenNull(); | ||
return requestMember; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.ody.auth.domain.authpolicy; | ||
|
||
import com.ody.member.domain.Member; | ||
import java.util.Optional; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class NewUserForNewDevice implements AuthPolicy { | ||
|
||
@Override | ||
public boolean match( | ||
Optional<Member> sameDeviceMember, | ||
Optional<Member> sameProviderIdMember, | ||
Member requestMember | ||
) { | ||
return sameDeviceMember.isEmpty() | ||
&& sameProviderIdMember.isEmpty(); | ||
} | ||
|
||
@Override | ||
public Member authorize( | ||
Optional<Member> sameDeviceMember, | ||
Optional<Member> sameProviderIdMember, | ||
Member requestMember | ||
) { | ||
return requestMember; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.ody.auth.domain.authpolicy; | ||
|
||
import com.ody.member.domain.Member; | ||
import java.util.Optional; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class OtherUserForExistingDevice implements AuthPolicy { | ||
|
||
@Override | ||
public boolean match( | ||
Optional<Member> sameDeviceMember, | ||
Optional<Member> sameProviderIdMember, | ||
Member requestMember | ||
) { | ||
return sameDeviceMember.isPresent() | ||
&& sameProviderIdMember.isPresent() | ||
&& !requestMember.isSame(sameDeviceMember.get()); | ||
} | ||
|
||
@Override | ||
public Member authorize( | ||
Optional<Member> sameDeviceMember, | ||
Optional<Member> sameProviderIdMember, | ||
Member requestMember | ||
) { | ||
sameDeviceMember.get().updateDeviceTokenNull(); | ||
sameProviderIdMember.get().updateDeviceToken(requestMember.getDeviceToken()); | ||
return sameProviderIdMember.get(); | ||
} | ||
} |
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(); | ||
} |
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이 있는 게 바로 이해가 안 가긴 하네요 🤔🤔