我正在做一个项目,需要在 JSP 中获取用户详细信息。经过一番研究,我知道${pageContext.request.userPrincipal.name}
可以用来获取校长的名字。但是,如果我需要其他信息,例如 ID(通过 Google Auth 登录时从 Google 收到)或密码等,该怎么办。有没有一种简单的方法可以做到这一点?我正在使用 Spring Security taglib。
是的,在使用时有一种非常简单的方法可以做到这一点spring security taglib
。只需以这种方式使用身份验证标签:
<sec:authentication property="name" />
使用这种方式将返回Authorization
对象的名称属性,通常与主体名称相同。但是您可以访问任何其他属性,甚至是嵌套对象中的属性:
<sec:authentication property="authorities" />
将返回 Authentication 对象的授予权限列表
<sec:authentication property="details.sessionId" />
这是我有时在对象details
字段内的嵌套对象中使用的Authentication
属性。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句