Skip to content

Commit

Permalink
feat : @currentuser ์ƒ์„ฑ
Browse files Browse the repository at this point in the history
  • Loading branch information
JangYouJung committed May 26, 2024
1 parent e5bc462 commit 52b90fa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/main/java/meltingpot/server/config/TokenProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,7 @@ public Authentication getAuthentication(String accessToken) {
// UserDetails ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค์–ด์„œ Authentication ๋ฆฌํ„ด
UserDetails principal = new User(claims.getSubject(), "", authorities);

// ์œ ์ € ๊ฐ์ฒด๋ฅผ ๋“ฑ๋ก
Optional<Account> account = accountRepository.findByUsername(principal.getUsername());

return new UsernamePasswordAuthenticationToken(account, accessToken, authorities);
return new UsernamePasswordAuthenticationToken(principal, accessToken, authorities);
}


Expand Down
17 changes: 17 additions & 0 deletions src/main/java/meltingpot/server/util/CurrentUser.java
Original file line number Diff line number Diff line change
@@ -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 {

}

0 comments on commit 52b90fa

Please sign in to comment.