我假设您有 一些
UserDetailsService类的实现。您可以返回从
User实现的任何对象。然后,该对象会自动放置在您的HTTP会话中。然后可以使用以下方法检索它:
UserDetails
loadUserByUsername()
User user = (User)SecurityContextHolder. getContext().getAuthentication().getPrincipal();
Spring Security自动处理您需要的一切。

我假设您有 一些
UserDetailsService类的实现。您可以返回从
User实现的任何对象。然后,该对象会自动放置在您的HTTP会话中。然后可以使用以下方法检索它:
UserDetails
loadUserByUsername()
User user = (User)SecurityContextHolder. getContext().getAuthentication().getPrincipal();
Spring Security自动处理您需要的一切。