SpringSecurity如何在代码中获取认证用户信息

1     public Object getCurrentUser(){
2         return SecurityContextHolder.getContext().getAuthentication();
3     }

1     public Object getCurrentUser(Authentication authentication){
2         return authentication;
3     }

如果不想拿到全部得认证用户信息,可以使用如下方式

1     public Object getCurrentUser(@AuthenticationPrincipal UserDetails user){
2         return user;
3     }

猜你喜欢

转载自www.cnblogs.com/fanqisoft/p/10628621.html