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     }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM