【问题标题】:How to get principal info in JSP? [closed]如何在 JSP 中获取主体信息? [关闭]
【发布时间】:2018-03-30 02:52:28
【问题描述】:

我正在做一个项目,需要在 JSP 中获取用户详细信息。经过一番研究,我知道${pageContext.request.userPrincipal.name} 可以用来获取校长的姓名。但是,如果我需要其他信息,例如 ID(通过 Google Auth 登录时从 Google 收到)或密码等,该怎么办。有没有简单的方法可以做到这一点?我正在使用 Spring Security 标签库。

【问题讨论】:

    标签: spring jsp spring-security taglib


    【解决方案1】:

    是的,当您使用spring security taglib 时,有一种非常简单的方法可以做到这一点。只需以这种方式使用身份验证标签:

    <sec:authentication property="name" />

    使用这种方式将返回Authorization 对象的名称属性,通常与主体名称相同。但是您可以访问任何其他属性,甚至是嵌套对象中的属性:

    <sec:authentication property="authorities" /> 将返回 Authentication 对象的授权列表

    <sec:authentication property="details.sessionId" /> 这是我有时在Authentication 对象的details 字段内的嵌套对象中使用的属性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-05
      • 1970-01-01
      • 2013-06-29
      相关资源
      最近更新 更多