0

I'm using Spring Boot, and I want to show inside my navbar the name and surname of the logged user.

To do that I have to call the principal inside every method of each controller and then I have to add the information to the model. I think there is a better way to do that. I think about the session attribute. Is it correct?

So my question is: Is the session attribute the best choice? If yes How can I do it?

Teo
  • 3,143
  • 2
  • 29
  • 59
  • here is proposed solution: https://stackoverflow.com/questions/35090329/how-to-display-current-logged-in-users-information-in-all-templates-including-v – Peter Zelenay Dec 06 '17 at 12:56
  • what is your template engine and security framework – neo Dec 06 '17 at 14:12

2 Answers2

0

You can use something along these lines directly in your jsp: <%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %> <security:authorize access="isAuthenticated()"> authenticated as <security:authentication property="principal.username" /> </security:authorize> Taken from baeldung

craigwor
  • 641
  • 8
  • 16