会话中的Spring UserDetails和my User实现

会话中的Spring UserDetails和my User实现,spring,spring-security,Spring,Spring Security,我正在安全模型的支持下开发我的Spring应用程序。 我配置了所有东西,它似乎工作得很好,但我有一个概念上的问题。 在我的控制器中,我可以检索Spring生成的用户详细信息,如下所示: UserDetails userDetails = (UserDetails)SecurityContextHolder.getContext().getAuthentication().getPrincipal(); Authentication authentication = new Userna

我正在安全模型的支持下开发我的Spring应用程序。 我配置了所有东西,它似乎工作得很好,但我有一个概念上的问题。 在我的控制器中,我可以检索Spring生成的用户详细信息,如下所示:

UserDetails userDetails = (UserDetails)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    Authentication authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
    SecurityContextHolder.getContext().setAuthentication(authentication);
现在,我应该把这个用户放在Http会话中,还是没用

此外,我是否应该基于UserDetails对象检索用户实现并将其放入会话中

安全的正确思维方式是什么?我需要我的用户实现来检索一些信息,但我不知道如何保持这两个信息。

在docks 5.3.1中,您可以看到示例

大概是这样的:

UserDetails userDetails = (UserDetails)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    Authentication authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
    SecurityContextHolder.getContext().setAuthentication(authentication);
在此docks 5.3.1中,您可以看到示例

大概是这样的:

UserDetails userDetails = (UserDetails)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    Authentication authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
    SecurityContextHolder.getContext().setAuthentication(authentication);

我相信默认情况下Spring使用,顾名思义,它使用HttpSession。我相信默认情况下Spring使用,顾名思义,它使用HttpSession。