Reputation: 839
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 protected], 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]
Upvotes: 1
Views: 2954
Reputation: 34776
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
Upvotes: 3