user2733757
user2733757

Reputation: 171

Get name of username with SpringSecurity and JSP

I wonder how to get the username by springsecurity, for example, my user table looks like this:

username - password - name

Authentication is done by the username + password, if I use these two options:

<%= request.getUserPrincipal().getName() %>
<%= SecurityContextHolder.getContext().getAuthentication().getName() %>

He will show me the username value, but in case my username is a value personal document, so I would only show the value of the field name.

Is how to do this? I'm using JSP + JSTL. Thank you.

Upvotes: 1

Views: 3266

Answers (1)

Nabil
Nabil

Reputation: 1811

You can use the spring security JSTL tags :

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

and put in your JSP code the following code :

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

you will have acess to all Principal properties .

Upvotes: 5

Related Questions