-
Notifications
You must be signed in to change notification settings - Fork 0
본인 소유 검증 누락으로 인한 멤버/디바이스 권한 문제 수정 #69
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -53,8 +53,11 @@ public MemberSaveOutput saveDevice(final MemberSaveInput input) { | |
|
|
||
| @Transactional(readOnly = true) | ||
| public MemberFindOutput findAllMemberDevices(final MemberFindInput input) { | ||
| final List<Device> devices = deviceRepository.findAllByMemberEmail(input.email()); | ||
| return MemberFindOutput.of(input.email(), devices); | ||
| final Member member = memberRepository.findByIdentifier(input.deviceIdentifier()) | ||
| .orElseThrow(() -> new UnauthorizedException("인증되지 않은 디바이스입니다")); | ||
|
|
||
| final List<Device> devices = deviceRepository.findAllByMemberEmail(member.getEmail()); | ||
| return MemberFindOutput.of(member.getEmail(), devices); | ||
| } | ||
|
|
||
| @Transactional(readOnly = true) | ||
|
|
@@ -69,11 +72,11 @@ public void authenticateDevice(final Email email, final DeviceIdentifier deviceI | |
| checkExistedMember(email); | ||
|
|
||
| final Device device = deviceRepository.findByIdentifier(deviceIdentifier) | ||
| .orElseThrow(() -> new NotFoundException("존재하지 않는 디바이스 아이디입니다: %s" | ||
| .orElseThrow(() -> new NotFoundException("존재하지 않는 디바이스 식별자입니다: %s" | ||
| .formatted(deviceIdentifier.getValue()))); | ||
|
|
||
| if (device.isActive()) { | ||
| throw new BadRequestException("이미 인증되었습니다"); | ||
| throw new BadRequestException("이미 인증된 디바이스입니다"); | ||
| } | ||
|
|
||
| device.verifyOwner(email); | ||
|
|
@@ -83,7 +86,18 @@ public void authenticateDevice(final Email email, final DeviceIdentifier deviceI | |
|
|
||
| @Transactional | ||
| public void deleteDevice(final DeviceDeleteInput input) { | ||
| deviceRepository.deleteByIdentifier(input.targetDeviceIdentifier()); | ||
| final Member requestMember = memberRepository.findByIdentifier(input.deviceIdentifier()) | ||
| .orElseThrow(() -> new UnauthorizedException("유효하지 않은 디바이스입니다")); | ||
|
|
||
| final Device targetDevice = deviceRepository.findByIdentifier(input.targetDeviceIdentifier()) | ||
| .orElseThrow(() -> new NotFoundException("존재하지 않는 디바이스입니다: %s" | ||
| .formatted(input.targetDeviceIdentifier().getValue()))); | ||
|
|
||
| if (!targetDevice.getMember().hasEmail(requestMember.getEmail())) { | ||
| throw new NotFoundException("존재하지 않는 디바이스입니다: %s".formatted(input.targetDeviceIdentifier().getValue())); | ||
| } | ||
|
|
||
| deviceRepository.delete(targetDevice); | ||
|
Comment on lines
88
to
+100
|
||
| log.info("[DEVICE_DELETED] 디바이스 삭제 성공: {}", input.targetDeviceIdentifier()); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,14 @@ | ||
| package com.recyclestudy.member.service.input; | ||
|
|
||
| import com.recyclestudy.member.domain.DeviceIdentifier; | ||
| import com.recyclestudy.member.domain.Email; | ||
|
|
||
| public record DeviceDeleteInput(Email email, DeviceIdentifier deviceIdentifier, | ||
| DeviceIdentifier targetDeviceIdentifier) { | ||
| public record DeviceDeleteInput(DeviceIdentifier deviceIdentifier, DeviceIdentifier targetDeviceIdentifier) { | ||
|
|
||
| public static DeviceDeleteInput from( | ||
| final String emailValue, | ||
| final DeviceIdentifier identifier, | ||
| final String targetIdentifier | ||
| ) { | ||
| final Email email = Email.from(emailValue); | ||
| final DeviceIdentifier targetDeviceIdentifier = DeviceIdentifier.from(targetIdentifier); | ||
| return new DeviceDeleteInput(email, identifier, targetDeviceIdentifier); | ||
| return new DeviceDeleteInput(identifier, targetDeviceIdentifier); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,10 @@ | ||
| package com.recyclestudy.member.service.input; | ||
|
|
||
| import com.recyclestudy.member.domain.DeviceIdentifier; | ||
| import com.recyclestudy.member.domain.Email; | ||
|
|
||
| public record MemberFindInput(Email email, DeviceIdentifier deviceIdentifier) { | ||
| public record MemberFindInput(DeviceIdentifier deviceIdentifier) { | ||
|
|
||
| public static MemberFindInput from(final String emailValue, final DeviceIdentifier identifier) { | ||
| final Email email = Email.from(emailValue); | ||
| return new MemberFindInput(email, identifier); | ||
| public static MemberFindInput from(final DeviceIdentifier identifier) { | ||
| return new MemberFindInput(identifier); | ||
| } | ||
| } |
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.
memberRepository.findByIdentifier() 실패 시 findAllMemberDevices()만 "인증되지 않은 디바이스입니다"를 사용하고, 같은 패턴을 쓰는 다른 메서드들(findNotificationTime/updateNotificationTime/deleteDevice)은 "유효하지 않은 디바이스입니다"를 사용하고 있습니다. @AuthDevice 리졸버의 메시지/다른 서비스들과도 달라서 클라이언트 입장에서 에러 메시지가 일관되지 않습니다. 이 메서드도 동일한 메시지로 통일하거나(권장), 여기서 구분하려면 실제로 활성 여부를 판단하는 로직을 함께 두는 쪽이 맞습니다.