【问题标题】:What are the implications of a JPA entity implementing Spring Security UserDetails?实现 Spring Security UserDetails 的 JPA 实体的含义是什么?
【发布时间】:2013-09-09 09:50:58
【问题描述】:

我有一个名为 Member 的 JPA 实体。我希望这个实体实现 Spring Security UserDetails实现一个自定义的基于 JPA 的 UserService

在此之前,我有几点需要整理:

  • Member 实体有很多属性。 Member 现在实现 UserDetails 并因此存储到 HttpSession 中(参见 HttpSessionSecurityContextRepository)这一事实会显着影响会话使用吗?
  • 我可以通过调用SecurityContextHolder.getContext().getAuthentication().getPrincipal(); 来检索当前登录的Member希望其所有属性在其他地方更新时保持正确同步

【问题讨论】:

    标签: spring jpa spring-security spring-data-jpa


    【解决方案1】:
    impact session usage significantly?
    

    没有。

    expect all its properties to remain synchronized properly when they are updated elsewhere?
    

    不,你必须自己管理......,即当你在某个地方更新它时,确保你也更新内存中的实例:

    Member member = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    member.setYourField(yourValue); //
    

    【讨论】:

      猜你喜欢
      • 2019-08-22
      • 1970-01-01
      • 2010-11-07
      • 2014-11-21
      • 2019-08-06
      • 2012-04-04
      • 2018-02-04
      • 2011-05-27
      • 2020-10-14
      相关资源
      最近更新 更多