获取JSP中的用户详细信息? [英] Get User Details in JSP?
问题描述
如何获取并显示低于结果in${pageContext.request.userPrincipal}
的用户的用户名,电子邮件,ip等?
How can get and show username, email, ip etc. of User which got below result in${pageContext.request.userPrincipal}
?
org.springframework.security.authentication.UsernamePasswordAuthenticationToken@e40cde0e:主体:用户[username = admin,email = olga @ vantalii.ru,password = 1234,firstName = Olga,lastName = OZCAN,当局= [角色[name = USER_ROLE,特权= null]],accountNonExpired = true,accountNonLocked = true,凭据NonExpired = true,启用= true];凭证:[受保护];已验证:true;详细信息:org.springframework.security.web.authentication.WebAuthenticationDetails@2cd90:RemoteIpAddress:0:0:0:0:0:0:0:1;会话编号:B91578060B48D46CC606AF8281757727;授予的权限:角色[name = USER_ROLE,privacys = null]
org.springframework.security.authentication.UsernamePasswordAuthenticationToken@e40cde0e: Principal: User [username=admin, email=olga@vantalii.ru, password=1234, firstName=Olga, lastName=OZCAN, authorities=[Role [name=USER_ROLE, privileges=null]], accountNonExpired=true, accountNonLocked=true, credentialsNonExpired=true, enabled=true]; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@2cd90: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: B91578060B48D46CC606AF8281757727; Granted Authorities: Role [name=USER_ROLE, privileges=null]
推荐答案
您应该使用Spring Security JSP标签.
You should use Spring Security JSP tags.
首先声明正确的taglib:
First declare the correct taglib:
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
,然后使用以下代码显示例如当前用户的电子邮件.
and then use the following code to display for example the email of the current user.
<sec:authentication property="principal.email" />
您可以用电子邮件代替主体对象的任何属性(用户名,名字等).
You can substitute email for any property of your principal object (username, firstName, etc.).
有关Spring Security JSP标记的更多信息可以在文档中找到:
More information about Spring Security JSP tags can be found in the documentation:
http://docs.spring. io/spring-security/site/docs/3.0.x/reference/taglibs.html
这篇关于获取JSP中的用户详细信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!