diff --git a/src/main/java/meltingpot/server/config/TokenProvider.java b/src/main/java/meltingpot/server/config/TokenProvider.java index 62c597e..a418717 100644 --- a/src/main/java/meltingpot/server/config/TokenProvider.java +++ b/src/main/java/meltingpot/server/config/TokenProvider.java @@ -172,10 +172,7 @@ public Authentication getAuthentication(String accessToken) { // UserDetails 객체를 만들어서 Authentication 리턴 UserDetails principal = new User(claims.getSubject(), "", authorities); - // 유저 객체를 등록 - Optional account = accountRepository.findByUsername(principal.getUsername()); - - return new UsernamePasswordAuthenticationToken(account, accessToken, authorities); + return new UsernamePasswordAuthenticationToken(principal, accessToken, authorities); } diff --git a/src/main/java/meltingpot/server/util/CurrentUser.java b/src/main/java/meltingpot/server/util/CurrentUser.java new file mode 100644 index 0000000..f066554 --- /dev/null +++ b/src/main/java/meltingpot/server/util/CurrentUser.java @@ -0,0 +1,17 @@ +package meltingpot.server.util; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import org.springframework.security.core.annotation.AuthenticationPrincipal; + +@Target({ElementType.PARAMETER, ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@AuthenticationPrincipal(expression = "@authService.getUserInfo()") +//인증된 사용자의 Principal 정보를 참조할 수 있다. +public @interface CurrentUser { + +}