Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions src/main/java/inu/codin/codin/common/config/FeignConfig.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,35 @@ public class SecurityUtils {
* @throws JwtException 인증 정보가 없는 경우 예외 발생
*/
public static ObjectId getCurrentUserId() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

if (authentication == null || !(authentication.getPrincipal() instanceof CustomUserDetails userDetails)) {
throw new JwtException(SecurityErrorCode.ACCESS_DENIED);
}

return userDetails.getId();
return getCustomUserDetails().getId();
}

/**
* 현재 인증된 사용자의 ROLE를 반환.
*
* @return 인증된 사용자의 ROLE
* @throws JwtException 인증 정보가 없는 경우 예외 발생
*/
public static UserRole getCurrentUserRole(){
return getCustomUserDetails().getRole();
}

private static CustomUserDetails getCustomUserDetails() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

if (authentication == null || !(authentication.getPrincipal() instanceof CustomUserDetails userDetails)) {
throw new JwtException(SecurityErrorCode.ACCESS_DENIED);
}

return userDetails.getRole();
return userDetails;
}

/**
* 매개변수 id가 현재 로그인 한 유저의 _Id와 일치하는지 확인
* @param id
* @throws JwtException 일치하지 않을 경우 에러 발생
*/
public static void validateUser(ObjectId id){
ObjectId userId = SecurityUtils.getCurrentUserId();
ObjectId userId = getCurrentUserId();
if (!id.equals(userId)) {
throw new JwtException(SecurityErrorCode.ACCESS_DENIED, "현재 유저에게 권한이 없습니다.");
}
Expand Down
108 changes: 0 additions & 108 deletions src/main/java/inu/codin/codin/common/stomp/StompMessageService.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public void blockUser(String strBlockedUserId) {
log.error("");
throw new BlockException(BlockErrorCode.SELF_BLOCKED);
}
userValidator.validateUserExists(userId, () -> new BlockException(BlockErrorCode.BLOCKING_USER_NOT_FOUND));
userValidator.validateUserExists(blockedId, () -> new BlockException(BlockErrorCode.BLOCKED_USER_NOT_FOUND));
validateUser(userId, blockedId);

blockRepository.findByUserId(userId)
.ifPresentOrElse(blockEntity -> {
Expand All @@ -61,8 +60,7 @@ public void unblockUser(String strBlockedUserId) {
if (userId.equals(blockedId)) {
throw new BlockException(BlockErrorCode.SELF_UNBLOCKED);
}
userValidator.validateUserExists(userId, () -> new BlockException(BlockErrorCode.BLOCKING_USER_NOT_FOUND));
userValidator.validateUserExists(blockedId, () -> new BlockException(BlockErrorCode.BLOCKED_USER_NOT_FOUND));
validateUser(userId, blockedId);

blockRepository.findByUserId(userId)
.ifPresentOrElse(blockEntity -> {
Expand All @@ -85,4 +83,14 @@ public List<ObjectId> getBlockedUsers() {
.map(BlockEntity::getBlockedUsers)
.orElse(List.of());
}

/**
* 현재 유저와 차단할 유저의 존재 여부 검증
* @param userId 현재 로그인된 유저의 pk
* @param blockedId 차단할 유저의 pk
*/
private void validateUser(ObjectId userId, ObjectId blockedId) {
userValidator.validateUserExists(userId, () -> new BlockException(BlockErrorCode.BLOCKING_USER_NOT_FOUND));
userValidator.validateUserExists(blockedId, () -> new BlockException(BlockErrorCode.BLOCKED_USER_NOT_FOUND));
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading