Get User Details in JSP?

2020-04-21 08:24发布

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: 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]

1条回答
Evening l夕情丶
2楼-- · 2020-04-21 09:03

You should use Spring Security JSP tags.

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.).

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

查看更多
登录 后发表回答