利用SecurityContextHolder
@GetMapping("/hello")
public Object hello() {
return SecurityContextHolder.getContext().getAuthentication();
}
利用Authentication
@GetMapping("/hello")
public Object hello(Authentication authentication) {
return authentication;
}
直接获取UserDetails信息
@GetMapping("/hello")
public Object hello(@AuthenticationPrincipal User user) {
return user;
}