Spring Boot Security 获取 Authentication 身份信息
Spring Security Spring Boot About 559 words需求
已经认证的用户需要能从Controller
中获取。
代码
ThreadLocal
SecurityContextHolder.getContext().getAuthentication().getPrincipal();
Controller
@PutMapping("/api/user")
public void updateUser(@RequestBody UserInfoRequest request, Authentication authentication) {
userService.updateUserInfo(authentication.getPrincipal(), request);
}
自定义Authentication
,如:TokenAuthentication
。
@PutMapping("/api/user")
public void updateUser(@RequestBody UserInfoRequest request, TokenAuthentication authentication) {
userService.updateUserInfo(authentication.getPrincipal(), request);
}
Views: 445 · Posted: 2024-05-17
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...