在JSP中获取用户详细信息?

时间:2014-10-05 20:55:30

标签: jsp spring-mvc spring-security

如何获取并显示低于结果in${pageContext.request.userPrincipal}的用户的用户名,电子邮件,IP等?

  

org.springframework.security.authentication.UsernamePasswordAuthenticationToken@e40cde0e:校长:用户[username = admin,email = olga @ servalii.ru,密码= 1234,firstName = Olga,lastName = OZCAN,authority = [Role [name = USER_ROLE,privileges = null]],accountNonExpired = true,accountNonLocked = true,credentialsNonExpired = true,enabled = true];证书:[保护];认证:真实;详细信息:org.springframework.security.web.authentication.WebAuthenticationDetails@2cd90:RemoteIpAddress:0:0:0:0:0:0:0:1; SessionId:B91578060B48D46CC606AF8281757727;授权机构:角色[name = USER_ROLE,privileges = null]

1 个答案:

答案 0 :(得分:3)

您应该使用Spring Security JSP标记。

首先声明正确的taglib:

<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

然后使用以下代码显示当前用户的电子邮件。

<sec:authentication property="principal.email" />

您可以将电子邮件替换为主体对象的任何属性(用户名,firstName等)。

有关Spring Security JSP标记的更多信息,请参阅文档:

http://docs.spring.io/spring-security/site/docs/3.0.x/reference/taglibs.html