From e282b326ddfe0785e2cdb7078581894671617b5c Mon Sep 17 00:00:00 2001 From: Ganghee-Lee-0522 Date: Sat, 13 Jan 2024 04:02:18 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20CORS=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 서비스 코드를 수정하였습니다. --- .../domain/member/service/MemberService.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/committers/snowflowerthon/committersserver/domain/member/service/MemberService.java b/src/main/java/com/committers/snowflowerthon/committersserver/domain/member/service/MemberService.java index 18ba111..1816d04 100644 --- a/src/main/java/com/committers/snowflowerthon/committersserver/domain/member/service/MemberService.java +++ b/src/main/java/com/committers/snowflowerthon/committersserver/domain/member/service/MemberService.java @@ -26,7 +26,6 @@ @RequiredArgsConstructor @Service public class MemberService { -// private final AuthenticationUtils authenticationUtils; private final ValidationService validationService; private final MemberRepository memberRepository; private final CommitRepository commitRepository; @@ -34,17 +33,31 @@ public class MemberService { private final FollowService followService; private final GitHubService gitHubService; + + private static CustomAuthenticationToken getCustomAuthenticationToken(Authentication authentication) { +// return (CustomAuthenticationToken) authentication.getPrincipal(); + Object principal = authentication.getPrincipal(); + + if (principal instanceof CustomAuthenticationToken) { + return (CustomAuthenticationToken) principal; + } else { + // 처리할 로직이나 예외를 처리하는 코드를 추가할 수 있습니다. + throw new IllegalStateException("Unexpected principal type: " + principal.getClass()); + } + } + // 사용자 Member 받아오기 public Member getAuthMember() { // 현재 사용자의 Authentication 객체 가져오기 Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - log.info("authentication 객체 맞아? -> {}", String.valueOf(authentication.getPrincipal().getClass().equals(String.class))); + CustomAuthenticationToken c = getCustomAuthenticationToken(authentication); + log.info("authentication 객체 맞아? -> {}", String.valueOf(authentication.getPrincipal().getClass().equals(Long.class))); - Long memberId = Long.valueOf(authentication.getPrincipal().toString()); + Long memberId = c.getMemberId(); Member member = validationService.valMember(memberId); return member; }