Skip to content

Commit

Permalink
πŸ› CORS 였λ₯˜ μˆ˜μ •
Browse files Browse the repository at this point in the history
- μ„œλΉ„μŠ€ μ½”λ“œλ₯Ό μˆ˜μ •ν•˜μ˜€μŠ΅λ‹ˆλ‹€.
  • Loading branch information
Ganghee-Lee-0522 committed Jan 12, 2024
1 parent af50da8 commit e282b32
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,38 @@
@RequiredArgsConstructor
@Service
public class MemberService {
// private final AuthenticationUtils authenticationUtils;
private final ValidationService validationService;
private final MemberRepository memberRepository;
private final CommitRepository commitRepository;
private final UnivRepository univRepository;
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;
}
Expand Down

0 comments on commit e282b32

Please sign in to comment.