SpringSecurity获取主体的三种方式
2021-05-31 16:02
标签:ima ext context aliyun 结果 body getc code https 结果: SpringSecurity获取主体的三种方式 标签:ima ext context aliyun 结果 body getc code https 原文地址:https://www.cnblogs.com/dalianpai/p/14744866.html三种获取登陆信息方式
@RequestMapping("/user/info")
@ResponseBody
public Object userInfo(Authentication authentication) {
return authentication.getPrincipal();
}
@RequestMapping("/user/info2")
@ResponseBody
public Object userInfo2(@AuthenticationPrincipal UserDetails userDetails) {
return userDetails;
}
@RequestMapping("/user/info3")
@ResponseBody
public Object userInfo3() {
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (principal != null && principal instanceof UserDetails) {
UserDetails userDetails = (UserDetails) principal;
return userDetails;
}
return principal;
}
文章标题:SpringSecurity获取主体的三种方式
文章链接:http://soscw.com/index.php/essay/89784.html