Showing Current User Info

Learn how to show current user info using Thymeleaf.

We'll cover the following

Application user details

We have seen in the earlier modules that we can show the username on a Thymeleaf page using sec:authentication="name" and the roles of the user with sec:authentication="principal.authorities".

The principal refers to the UserDetails implementation that the UserDetailsService returns. We can call any method of our ApplicationUserDetails implementation in the sec:authentication attribute to display information about the current user.

Updating menu

As an example, we can update top-menu.html to show the displayName and the username information from ApplicationUserDetails:

Get hands-on with 1400+ tech skills courses.