【问题标题】:JSF, Hibernate, Spring Security?JSF、休眠、弹簧安全?
【发布时间】:2012-07-04 01:24:03
【问题描述】:

我正在开发一个 jsf 应用程序,我想使用 Spring-Secrity 来验证我的用户,我正在使用休眠,需要的是: - 使用 Spring-Security 对用户进行身份验证。 - 已认证的用户保存在会话 bean 中。 - 我需要一个注销方法。 - 我需要确切地知道要添加到我的项目中的罐子。 - 在我的数据库中,每个用户都有一个角色(用户或管理员)。

我发现的教程的问题是,在身份验证后没有保存有关当前用户的信息,而我的情况是,我的会话 bean 中确实需要一个 currentuser。

我该怎么做?

【问题讨论】:

    标签: hibernate jsf authentication spring-security


    【解决方案1】:

    我会查看Spring Web Flow primefaces example。它演示了与 JSF 的集成,提供 JSF 标记库以与 Spring Security 集成等。就能够从会话 bean 访问当前用户而言,您可以使用 SecurityContextHolder 从应用程序中的任何位置获取当前用户(包括会话 bean)。例如:

    Authentication authentication = SecurityContextHolder.getContext()
        .getAuthentication();
    UserDetails userDetails = (UserDetails) authentication.getPrincipal();
    

    【讨论】:

      猜你喜欢
      • 2012-01-22
      • 2011-02-17
      • 2016-11-04
      • 2017-07-19
      • 2020-03-13
      • 1970-01-01
      • 2011-08-09
      • 2015-12-14
      • 1970-01-01
      相关资源
      最近更新 更多