Get user info in JSP?

How to get and show username, email, ip, etc. user who got below result in${pageContext.request.userPrincipal}

?

org.springframew ork.security.authentication.UsernamePasswordAuthenticationToken @ e40cde0e: Principal: User [username = admin, email=olga@vantalii.ru , password = 1234, firstName = Olga, lastName = OZCAN, authority = [Role [name = USER_ROLE , privileges = null]], accountNonExpired = true, accountNonLocked = true, credentialsNonExpired = true, enabled = true]; Credentials: [PROTECT]; Authenticated: true; Details: org.sprin gframework.security.web.authentication.WebAuthenticationDetails @ 2cd90: RemoteIpAddress: 0: 0: 0: 0: 0: 0: 0: 1; SessionId: B91578060B48D46CC606AF8281757727; Permissions granted: Role [name = USER_ROLE, privileges = null]

+1


source to share


1 answer


You have to use Spring JSP security 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 current user's email.



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

      

You can replace email with any property of your main object (username, firstName, etc.).

More information on Spring JSP Security Tags can be found in the documentation:

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

+3


source







All Articles